Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Jul 18, 2024
1 parent f125ef2 commit 517da09
Show file tree
Hide file tree
Showing 8 changed files with 944 additions and 5 deletions.
4 changes: 2 additions & 2 deletions tests/PgSqlIntegration.suite.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
suite_namespace: Vjik\Codeception\DatabasePopulator\Tests\Integration
actor: IntegrationTester
suite_namespace: Vjik\Codeception\DatabasePopulator\Tests\PgSqlIntegration
actor: PgSqlIntegrationTester
modules:
enabled:
- Db:
Expand Down
51 changes: 51 additions & 0 deletions tests/PgSqlIntegration/DatabasePopulateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,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('SHOW TABLES')->fetchAll(PDO::FETCH_COLUMN);

$this->assertSame([], $tableNames);
}
}
6 changes: 3 additions & 3 deletions tests/PgSqlPreload.suite.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
suite_namespace: Vjik\Codeception\DatabasePopulator\Tests\Preload
actor: PreloadTester
suite_namespace: Vjik\Codeception\DatabasePopulator\Tests\PgSqlPreload
actor: PgSqlPreloadTester
modules:
enabled:
- Db:
dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%'
dsn: 'pgsql:host=%DB_HOST%;dbname=%DB_NAME%'
user: '%DB_USERNAME%'
password: '%DB_PASSWORD%'
- Vjik\Codeception\DatabasePopulator\Module:
Expand Down
22 changes: 22 additions & 0 deletions tests/PgSqlPreload/PreloadTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Vjik\Codeception\DatabasePopulator\Tests\PgSqlPreload;

use Codeception\Test\Unit;
use Vjik\Codeception\DatabasePopulator\Tests\PgSqlPreloadTester;

final class PreloadTest extends Unit
{
/**
* @var PgSqlPreloadTester
*/
protected $tester;

public function testBase(): void
{
$this->tester->seeInDatabase('author', ['id' => 1, 'name' => 'Ivan']);
$this->tester->seeInDatabase('author', ['id' => 2, 'name' => 'Petr']);
}
}
29 changes: 29 additions & 0 deletions tests/_support/PgSqlIntegrationTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Vjik\Codeception\DatabasePopulator\Tests;

/**
* Inherited Methods
* @method void wantTo($text)
* @method void wantToTest($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause($vars = [])
*
* @SuppressWarnings(PHPMD)
*/
class PgSqlIntegrationTester extends \Codeception\Actor
{
use _generated\PgSqlIntegrationTesterActions;

/**
* Define custom actions here
*/
}
29 changes: 29 additions & 0 deletions tests/_support/PgSqlPreloadTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Vjik\Codeception\DatabasePopulator\Tests;

/**
* Inherited Methods
* @method void wantTo($text)
* @method void wantToTest($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause($vars = [])
*
* @SuppressWarnings(PHPMD)
*/
class PgSqlPreloadTester extends \Codeception\Actor
{
use _generated\PgSqlPreloadTesterActions;

/**
* Define custom actions here
*/
}
Loading

0 comments on commit 517da09

Please sign in to comment.