generated from vjik/package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabasePopulateTest.php
51 lines (40 loc) · 1.45 KB
/
DatabasePopulateTest.php
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
<?php
declare(strict_types=1);
namespace Vjik\Codeception\DatabasePopulator\Tests\PgSqlIntegration;
use Codeception\Exception\ModuleException;
use Codeception\Test\Unit;
use PDO;
use Vjik\Codeception\DatabasePopulator\Tests\PgSqlIntegrationTester;
use function dirname;
final class DatabasePopulateTest extends Unit
{
/**
* @var PgSqlIntegrationTester
*/
protected $tester;
public function testBase(): void
{
$this->tester->loadDump('blog');
$this->tester->loadRows('authors');
$this->tester->seeInDatabase('author', ['id' => 1, 'name' => 'Ivan']);
$this->tester->seeInDatabase('author', ['id' => 2, 'name' => 'Petr']);
}
public function testLoadNotExistDump(): void
{
$this->expectException(ModuleException::class);
$this->expectExceptionMessage(
"\nFile with dump doesn't exist.\nPlease, check path for SQL-file: " .
dirname(__DIR__) . '/_data/dumps/pgsql/shop.sql'
);
$this->tester->loadDump('shop');
}
public function testLoadEmptyDump(): void
{
$this->tester->loadDump('blog');
$this->tester->loadDump('empty');
/** @var PDO $pdo */
$pdo = $this->getModule('Db')->_getDbh();
$tableNames = $pdo->query('SELECT table_name FROM information_schema.tables WHERE table_schema=\'public\' AND table_type=\'BASE TABLE\'')->fetchAll(PDO::FETCH_COLUMN);
$this->assertSame([], $tableNames);
}
}