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

[WIP] PHPUnit: set executionOrder as random and enable resolveDependencies #8

Closed
wants to merge 5 commits into from
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
2 changes: 2 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
bootstrap="tests/App/bootstrap.php"
colors="true"
beStrictAboutOutputDuringTests="true"
executionOrder="random"
resolveDependencies="true"
>

<php>
Expand Down
3 changes: 2 additions & 1 deletion src/Services/DatabaseTools/ORMDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ public function loadFixtures(array $classNames = [], bool $append = false): Abst

protected function disableForeignKeyChecksIfApplicable(): void
{
if (!$this->isMysql()) {
// Don't disable FOREIGN_KEY_CHECKS is the database is not created yet
if (!$this->isMysql() || !$this->connection->isConnected()) {
return;
}

Expand Down
36 changes: 33 additions & 3 deletions tests/Test/ConfigSqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*
* @IgnoreAnnotation("depends")
* @IgnoreAnnotation("expectedException")
*/
class ConfigSqliteTest extends KernelTestCase
{
Expand Down Expand Up @@ -221,7 +223,7 @@ public function testLoadDependentFixturesWithDependencyInjected(): void
/**
* Use nelmio/alice.
*/
public function testLoadFixturesFiles(): void
public function testLoadFixturesFiles(): array
{
$fixtures = $this->loadFixtureFiles([
'@AcmeBundle/DataFixtures/ORM/user.yml',
Expand Down Expand Up @@ -264,6 +266,8 @@ public function testLoadFixturesFiles(): void
$this->assertTrue(
$user->getEnabled()
);

return $fixtures;
}

/**
Expand All @@ -285,6 +289,22 @@ public function testLoadNonexistentFixturesFiles(): void
*/
public function testLoadFixturesFilesWithPurgeModeTruncate(): void
{
// Load initial fixtures
$this->testLoadFixturesFiles();

$em = $this->getContainer()
->get('doctrine.orm.entity_manager');

$users = $em->getRepository('LiipAcme:User')
->findAll();

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

// Load fixtures with append = true
$fixtures = $this->loadFixtureFiles([
'@AcmeBundle/DataFixtures/ORM/user.yml',
], true, null, 'doctrine', ORMPurger::PURGE_MODE_TRUNCATE);
Expand All @@ -297,7 +317,17 @@ public function testLoadFixturesFilesWithPurgeModeTruncate(): void
$fixtures
);

$id = 1;
$users = $em->getRepository('LiipAcme:User')
->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 \Liip\Acme\Tests\App\Entity\User $user */
foreach ($fixtures as $user) {
$this->assertSame($id++, $user->getId());
Expand Down
4 changes: 0 additions & 4 deletions tests/Test/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*
* Avoid conflict with PHPUnit annotation when reading QueryCount
* annotation:
*
* @IgnoreAnnotation("expectedException")
*/
class ConfigTest extends KernelTestCase
{
Expand Down