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

feat: support doctrine/orm 3 #296

Merged
merged 1 commit into from
Mar 31, 2024
Merged
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
5 changes: 2 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ jobs:
run: echo '127.0.0.1 mariadb postgres mongodb' | sudo tee -a /etc/hosts

- name: Run tests
# In phpunit.xml.dist, tests annotated with "@group mysql" are excluded, revert this
# Run tests twice to ensure that tests are idempotent even if database caching is enabled
run: |
php ./vendor/bin/phpunit --testdox --exclude-group ""
php ./vendor/bin/phpunit --testdox --exclude-group ""
php ./vendor/bin/phpunit --testdox --process-isolation
php ./vendor/bin/phpunit --testdox --process-isolation
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"doctrine/doctrine-fixtures-bundle": "^3.4.4 || ^4.0",
"doctrine/mongodb-odm": "^2.2",
"doctrine/mongodb-odm-bundle": "^4.2.1 || ^5.0",
"doctrine/orm": "^2.14",
"doctrine/orm": "^2.14 || ^3.0",
"doctrine/phpcr-bundle": "^2.4.3 || ^3.0",
"doctrine/phpcr-odm": "^1.7.2 || ^2.0",
"jackalope/jackalope-doctrine-dbal": "^1.10.1 || ^2.0",
Expand All @@ -48,7 +48,7 @@
"doctrine/annotations": "<1.13.1 || >=3.0",
"doctrine/dbal": "<2.13.1 || ~3.0.0 || >=4.0",
"doctrine/mongodb-odm": "<2.2 || >=3.0",
"doctrine/orm": "<2.14 || >=3.0"
"doctrine/orm": "<2.14 || >=4.0"
},
"suggest": {
"doctrine/dbal": "Required when using the fixture loading functionality with an ORM and SQLite",
Expand Down
34 changes: 33 additions & 1 deletion doc/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,40 @@ Install the dependencies with composer:
docker-compose exec php-fpm composer install
```

Install the lowest dependencies with composer:

```bash
docker-compose exec php-fpm composer update --prefer-lowest
```

Now you can execute the tests with the following command:

```bash
docker-compose exec php-fpm ./vendor/bin/phpunit --exclude-group ""
docker-compose exec php-fpm ./vendor/bin/phpunit --process-isolation
```

If one test fails, run it without the `--process-isolation` option

```bash
docker-compose exec php-fpm ./vendor/bin/phpunit tests/Test/ConfigMongodbTest.php
```

You can also use the `--filter` option to run tests matching a class and name:

```bash
docker-compose exec php-fpm ./vendor/bin/phpunit --process-isolation --filter=ConfigSqliteTest::testAppendFixtures
```

You can also use the `--filter` option to run tests matching a name:

```bash
docker-compose exec php-fpm ./vendor/bin/phpunit --process-isolation --filter=testAppendFixtures
```

## Delete the cache

If you change the version of PHP or dependencies, the caches may cause issues, they can be deleted:

```bash
docker-compose exec php-fpm bash -c "rm -rf tests/App*/var/cache/*"
```
7 changes: 0 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,4 @@
<directory>tests/Test</directory>
</testsuite>
</testsuites>

<groups>
<exclude>
<group>mysql</group>
<group>pgsql</group>
</exclude>
</groups>
</phpunit>
11 changes: 6 additions & 5 deletions tests/App/DataFixtures/ORM/LoadDependentUserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ class LoadDependentUserData extends AbstractFixture implements DependentFixtureI
*/
public function load(ObjectManager $manager): void
{
/** @var User $user */
$user = clone $this->getReference('user');

$user = new User();
$user->setId(3);
$user->setName('alice bar');
$user->setEmail('[email protected]');

$manager->persist($user);
$manager->flush();

$user = clone $this->getReference('user');

$user = new User();
$user->setId(4);
$user->setName('eve bar');
$user->setEmail('[email protected]');

$manager->persist($user);
$manager->flush();
Expand Down
11 changes: 6 additions & 5 deletions tests/App/DataFixtures/ORM/LoadDependentUserWithServiceData.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@ public function __construct(DummyService $dummyService)
*/
public function load(ObjectManager $manager): void
{
/** @var User $user */
$user = clone $this->getReference('serviceUser');

$user = new User();
$user->setId(3);
$user->setName('alice bar');
$user->setEmail('[email protected]');
$user->setDummyText($this->dummyService->getText());

$manager->persist($user);
$manager->flush();

$user = clone $this->getReference('serviceUser');

$user = new User();
$user->setId(4);
$user->setName('eve bar');
$user->setEmail('[email protected]');

$manager->persist($user);
$manager->flush();
Expand Down
5 changes: 3 additions & 2 deletions tests/App/DataFixtures/ORM/LoadSecondUserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class LoadSecondUserData extends AbstractFixture
public function load(ObjectManager $manager): void
{
$user = new User();
$user->setName('bar foo');
$user->setEmail('[email protected]');
$user->setId(3);
$user->setName('alice bar');
$user->setEmail('[email protected]');

$manager->persist($user);
$manager->flush();
Expand Down
5 changes: 3 additions & 2 deletions tests/App/DataFixtures/ORM/LoadUserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public function load(ObjectManager $manager): void

$this->addReference('user', $user);

$user = clone $this->getReference('user');

$user = new User();
$user->setId(2);
$user->setName('bob bar');
$user->setEmail('[email protected]');

$manager->persist($user);
$manager->flush();
Expand Down
12 changes: 6 additions & 6 deletions tests/App/DataFixtures/ORM/LoadUserDataInGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ public function load(ObjectManager $manager): void
$manager->persist($user);
$manager->flush();

$this->addReference('groupUser', $user);

$user = clone $this->getReference('groupUser');

$user = new User();
$user->setId(2);
$user->setName('bob bar');
$user->setEmail('[email protected]');

$manager->persist($user);
$manager->flush();

$user = clone $this->getReference('groupUser');

$user = new User();
$user->setId(3);
$user->setName('alice bar');
$user->setEmail('[email protected]');

$manager->persist($user);
$manager->flush();
Expand Down
7 changes: 3 additions & 4 deletions tests/App/DataFixtures/ORM/LoadUserWithServiceData.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ public function load(ObjectManager $manager): void
$manager->persist($user);
$manager->flush();

$this->addReference('serviceUser', $user);

$user = clone $this->getReference('serviceUser');

$user = new User();
$user->setId(2);
$user->setName('bob bar');
$user->setEmail('[email protected]');

$manager->persist($user);
$manager->flush();
Expand Down
3 changes: 2 additions & 1 deletion 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}:
user_id_{1..10}:
id: <current()>
name: <name()>
email: <email()>
3 changes: 2 additions & 1 deletion tests/App/DataFixtures/ORM/user_with_custom_provider.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Liip\Acme\Tests\App\Entity\User:
id{1..10}:
custom_user_id_{11..20}:
id: <current()>
name: <foo('a string')>
email: <email()>
3 changes: 1 addition & 2 deletions tests/Test/ConfigMysqlCacheDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
* they are disabled by default (see phpunit.xml.dist).
*
* In order to run them, you have to set the MySQL connection
* parameters in the Tests/AppConfigMysql/config.yml file and
* add “--exclude-group ""” when running PHPUnit.
* parameters in the Tests/AppConfigMysql/config.yml file.
*
* Use Tests/AppConfigMysql/AppConfigMysqlKernelCacheDb.php instead of
* Tests/App/AppKernel.php.
Expand Down
3 changes: 1 addition & 2 deletions tests/Test/ConfigMysqlKeepDatabaseAndSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
* they are disabled by default (see phpunit.xml.dist).
*
* In order to run them, you have to set the MySQL connection
* parameters in the Tests/AppConfigMysql/config.yml file and
* add “--exclude-group ""” when running PHPUnit.
* parameters in the Tests/AppConfigMysql/config.yml file.
*
* Use Tests/AppConfigMysqlKeepDatabaseAndSchema/AppConfigMysqlKernelKeepDatabaseAndSchema.php instead of
* Tests/App/AppKernel.php.
Expand Down
52 changes: 45 additions & 7 deletions tests/Test/ConfigMysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence
* they are disabled by default (see phpunit.xml.dist).
*
* In order to run them, you have to set the MySQL connection
* parameters in the Tests/AppConfigMysql/config.yml file and
* add “--exclude-group ""” when running PHPUnit.
* parameters in the Tests/AppConfigMysql/config.yml file.
*
* Use Tests/AppConfigMysql/AppConfigMysqlKernel.php instead of
* Tests/App/AppKernel.php.
Expand Down Expand Up @@ -95,7 +94,7 @@ public function testLoadEmptyFixtures(): void
/**
* @group mysql
*/
public function testLoadFixtures(int $firstUserId = 1): void
public function testLoadFixtures(): void
{
$fixtures = $this->databaseTool->loadFixtures([
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadUserData',
Expand Down Expand Up @@ -135,7 +134,7 @@ public function testLoadFixtures(int $firstUserId = 1): void
/**
* @group mysql
*/
public function testAppendFixtures(int $firstUserId = 1, int $thirdUserId = 3): void
public function testAppendFixtures(): void
{
$this->databaseTool->loadFixtures([
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadUserData',
Expand Down Expand Up @@ -169,17 +168,31 @@ public function testAppendFixtures(int $firstUserId = 1, int $thirdUserId = 3):
$user1->getEmail()
);

/** @var User $user */
/** @var User $user2 */
$user2 = $this->userRepository
->findOneBy([
'email' => '[email protected]',
])
;

$this->assertNotNull($user2);

$this->assertSame(
'[email protected]',
$user2->getEmail()
);

/** @var User $user3 */
$user3 = $this->userRepository
->findOneBy([
'email' => 'bar@foo.com',
'email' => 'alice@bar.com',
])
;

$this->assertNotNull($user3);

$this->assertSame(
'bar@foo.com',
'alice@bar.com',
$user3->getEmail()
);
}
Expand Down Expand Up @@ -262,6 +275,8 @@ public function testLoadFixturesAndPurge(): void
$users
);

$this->getTestContainer()->get('doctrine')->getManager()->clear();

// Reload fixtures
$this->databaseTool->loadFixtures([
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadUserData',
Expand Down Expand Up @@ -331,6 +346,29 @@ public function testLoadFixturesFiles(): void
$this->assertInstanceOf(User::class, $user);
}

/**
* Load fixture which has a dependency.
*/
public function testLoadDependentFixtures(): void
{
$fixtures = $this->databaseTool->loadFixtures([
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadDependentUserData',
]);

$this->assertInstanceOf(
'Doctrine\Common\DataFixtures\Executor\ORMExecutor',
$fixtures
);

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

// The two files with fixtures have been loaded, there are 4 users.
$this->assertCount(
4,
$users
);
}

protected static function getKernelClass(): string
{
return AppConfigMysqlKernel::class;
Expand Down
3 changes: 1 addition & 2 deletions tests/Test/ConfigMysqlUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
* they are disabled by default (see phpunit.xml.dist).
*
* In order to run them, you have to set the MySQL connection
* parameters in the Tests/AppConfigMysql/config.yml file and
* add “--exclude-group ""” when running PHPUnit.
* parameters in the Tests/AppConfigMysql/config.yml file.
*
* Use Tests/AppConfigMysql/AppConfigMysqlUrlKernel.php instead of
* Tests/App/AppKernel.php.
Expand Down
26 changes: 24 additions & 2 deletions tests/Test/ConfigPgsqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
* they are disabled by default (see phpunit.xml.dist).
*
* In order to run them, you have to set the PostgreSQL connection
* parameters in the Tests/AppConfigPgsql/config.yml file and
* add “--exclude-group ""” when running PHPUnit.
* parameters in the Tests/AppConfigPgsql/config.yml file.
*
* Use Tests/AppConfigPgsql/AppConfigPgsqlKernel.php instead of
* Tests/App/AppKernel.php.
Expand All @@ -38,6 +37,29 @@
*/
class ConfigPgsqlTest extends ConfigMysqlTest
{
/**
* Load fixture which has a dependency.
*/
public function testLoadDependentFixtures(): void
{
$fixtures = $this->databaseTool->loadFixtures([
'Liip\Acme\Tests\App\DataFixtures\ORM\LoadDependentUserData',
]);

$this->assertInstanceOf(
'Doctrine\Common\DataFixtures\Executor\ORMExecutor',
$fixtures
);

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

// The two files with fixtures have been loaded, there are 4 users.
$this->assertCount(
4,
$users
);
}

public function testToolType(): void
{
$this->assertInstanceOf(ORMDatabaseTool::class, $this->databaseTool);
Expand Down
Loading
Loading