Repository navigation
Expand file tree
/
Copy pathDbTest.php
More file actions
58 lines (50 loc) · 1.98 KB
/
Copy pathDbTest.php
File metadata and controls
58 lines (50 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
class DbTest extends \PHPUnit_Framework_TestCase
{
protected $config = array(
'dsn' => 'sqlite:tests/data/sqlite.db',
'user' => 'root',
'password' => '',
'cleanup' => false
);
/**
* @var \Codeception\Module\Db
*/
protected $module = null;
public function setUp()
{
$this->module = new \Codeception\Module\Db();
$this->module->_setConfig($this->config);
$this->module->_initialize();
// $this->loadDump(); enable this when you want to change fixtures
}
protected function loadDump()
{
$sql = file_get_contents(\Codeception\Configuration::dataDir() . '/dumps/sqlite.sql');
$sql = preg_replace('%/\*(?:(?!\*/).)*\*/%s', "", $sql);
$sql = explode("\n", $sql);
$sqlite = \Codeception\Util\Driver\Db::create($this->config['dsn'], $this->config['user'], $this->config['password']);
$sqlite->load($sql);
}
public function testSeeInDatabase() {
$this->module->seeInDatabase('users', array('name' => 'davert'));
}
public function testDontSeeInDatabase() {
$this->module->dontSeeInDatabase('users', array('name' => 'user1'));
}
public function testDontSeeInDatabaseWithEmptyTable() {
$this->module->dontSeeInDatabase('empty_table');
}
public function testGrabFromDatabase() {
$email = $this->module->grabFromDatabase('users', 'email', array('name' => 'davert'));
$this->assertEquals('davert@mail.ua', $email);
}
public function testHaveAndSeeInDatabase()
{
$user_id = $this->module->haveInDatabase('users', array('name' => 'john', 'email' => 'john@jon.com'));
$this->assertInternalType('integer', $user_id);
$this->module->seeInDatabase('users', array('name' => 'john', 'email' => 'john@jon.com'));
$this->module->_before(\Codeception\Util\Stub::make('\Codeception\TestCase'));
$this->module->dontSeeInDatabase('users', array('name' => 'john'));
}
}