Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve phpunit configuration 2.x #109

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
beStrictAboutOutputDuringTests="true"
executionOrder="random"
resolveDependencies="true"
processIsolation="true"
>

<php>
Expand Down
5 changes: 1 addition & 4 deletions src/Services/DatabaseTools/MongoDBDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,9 @@ public function loadFixtures(array $classNames = [], bool $append = false): Abst

$executor = $this->getExecutor($this->getPurger());
$executor->setReferenceRepository($referenceRepository);
if (false === $append) {
$executor->purge();
}

$loader = $this->fixturesLoaderFactory->getFixtureLoader($classNames);
$executor->execute($loader->getFixtures(), true);
$executor->execute($loader->getFixtures(), $append);

if ($backupService) {
$event = new ReferenceSaveEvent($this->om, $executor, $backupService->getBackupFilePath());
Expand Down
13 changes: 5 additions & 8 deletions src/Services/DatabaseTools/ORMDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use Liip\TestFixturesBundle\Event\PreFixtureBackupRestoreEvent;
use Liip\TestFixturesBundle\Event\ReferenceSaveEvent;
use Liip\TestFixturesBundle\LiipTestFixturesEvents;
use function count;
use function in_array;

/**
* @author Aleksey Tupichenkov <[email protected]>
Expand Down Expand Up @@ -103,7 +105,7 @@ public function loadFixtures(array $classNames = [], bool $append = false): Abst
// TODO: handle case when using persistent connections. Fail loudly?
if (false === $this->getKeepDatabaseAndSchemaParameter()) {
$schemaTool = new SchemaTool($this->om);
if (\count($this->excludedDoctrineTables) > 0 || true === $append) {
if (count($this->excludedDoctrineTables) > 0 || true === $append) {
if (!empty($this->getMetadatas())) {
$schemaTool->updateSchema($this->getMetadatas());
}
Expand All @@ -120,14 +122,9 @@ public function loadFixtures(array $classNames = [], bool $append = false): Abst

$executor = $this->getExecutor($this->getPurger());
$executor->setReferenceRepository($referenceRepository);
if (false === $append) {
$this->disableForeignKeyChecksIfApplicable();
$executor->purge();
$this->enableForeignKeyChecksIfApplicable();
}

$loader = $this->fixturesLoaderFactory->getFixtureLoader($classNames);
$executor->execute($loader->getFixtures(), true);
$executor->execute($loader->getFixtures(), $append);

if ($backupService) {
$event = new ReferenceSaveEvent($this->om, $executor, $backupService->getBackupFilePath());
Expand Down Expand Up @@ -179,7 +176,7 @@ protected function createDatabaseIfNotExists(): void
$tmpConnection = DriverManager::getConnection($params);
$tmpConnection->connect();

if (!\in_array($dbName, $tmpConnection->getSchemaManager()->listDatabases(), true)) {
if (!in_array($dbName, $tmpConnection->getSchemaManager()->listDatabases(), true)) {
$tmpConnection->getSchemaManager()->createDatabase($dbName);
}

Expand Down
5 changes: 1 addition & 4 deletions src/Services/DatabaseTools/ORMSqliteDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,9 @@ public function loadFixtures(array $classNames = [], bool $append = false): Abst

$executor = $this->getExecutor($this->getPurger());
$executor->setReferenceRepository($referenceRepository);
if (false === $append) {
$executor->purge();
}

$loader = $this->fixturesLoaderFactory->getFixtureLoader($classNames);
$executor->execute($loader->getFixtures(), true);
$executor->execute($loader->getFixtures(), $append);

if ($backupService) {
$event = new ReferenceSaveEvent($this->om, $executor, $backupService->getBackupFilePath());
Expand Down
5 changes: 1 addition & 4 deletions src/Services/DatabaseTools/PHPCRDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,9 @@ public function loadFixtures(array $classNames = [], bool $append = false): Abst

$executor = $this->getExecutor($this->getPurger(), $this->getInitializerManager());
$executor->setReferenceRepository($referenceRepository);
if (false === $append) {
$executor->purge();
}

$loader = $this->fixturesLoaderFactory->getFixtureLoader($classNames);
$executor->execute($loader->getFixtures(), true);
$executor->execute($loader->getFixtures(), $append);

if ($backupService) {
$event = new ReferenceSaveEvent($this->om, $executor, $backupService->getBackupFilePath());
Expand Down
1 change: 1 addition & 0 deletions tests/App/DataFixtures/ORM/user.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Liip\Acme\Tests\App\Entity\User:
id{1..10}:
id: '<current()>'
name: <name()>
email: <email()>
24 changes: 23 additions & 1 deletion tests/Test/ConfigSqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Liip\TestFixturesBundle\Services\DatabaseTools\ORMSqliteDatabaseTool;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use function count;

/**
* @runTestsInSeparateProcesses
Expand Down Expand Up @@ -362,8 +363,20 @@ public function testLoadNonexistentFixturesFiles(): void
*/
public function testLoadFixturesFilesWithPurgeModeTruncate(): void
{
// Load initial fixtures
$this->testLoadFixturesFiles();

$users = $this->userRepository->findAll();

// There are 10 users in the database
$this->assertSame(
10,
count($users)
);

$this->databaseTool->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);

// Load fixtures with append = true
$fixtures = $this->databaseTool->loadAliceFixture([
'@AcmeBundle/DataFixtures/ORM/user.yml',
], true);
Expand All @@ -376,7 +389,16 @@ public function testLoadFixturesFilesWithPurgeModeTruncate(): void
$fixtures
);

$id = 1;
$users = $this->userRepository->findAll();

// There are only 10 users in the database
$this->assertSame(
10,
count($users)
);

// Auto-increment hasn't been altered, so ids start from 11
$id = 11;
/** @var User $user */
foreach ($fixtures as $user) {
$this->assertSame($id++, $user->getId());
Expand Down
Loading