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

chore: merge 2.x in 3.x #297

Merged
merged 3 commits 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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"doctrine/doctrine-bundle": "^2.11",
"doctrine/doctrine-fixtures-bundle": "^3.5.1 || ^4.0",
"doctrine/mongodb-odm-bundle": "^4.4 || ^5.0",
"doctrine/orm": "^2.7",
"doctrine/orm": "^2.14 || ^3.0",
"doctrine/mongodb-odm": "^2.5",
"monolog/monolog": "^1.25.1 || ^2.0 || ^3.0",
"phpunit/phpunit": "^10.5.11 || ^11.0.4",
Expand All @@ -42,7 +42,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
12 changes: 12 additions & 0 deletions doc/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ If one test fails, run it without the `--process-isolation` option
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:
Expand Down
11 changes: 6 additions & 5 deletions tests/App/DataFixtures/ORM/LoadDependentUserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,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 @@ -31,18 +31,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 @@ -22,8 +22,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 @@ -31,9 +31,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 @@ -33,18 +33,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 @@ -42,11 +42,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()>
49 changes: 44 additions & 5 deletions tests/Test/ConfigMysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testLoadEmptyFixtures(): void
);
}

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 @@ -111,7 +111,7 @@ public function testLoadFixtures(int $firstUserId = 1): void
);
}

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 @@ -145,17 +145,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 @@ -236,6 +250,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 @@ -303,6 +319,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
23 changes: 23 additions & 0 deletions tests/Test/ConfigPgsqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@
#[PreserveGlobalState(false)]
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
45 changes: 35 additions & 10 deletions tests/Test/ConfigSqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function loadAllFixtures(): void
$repository
);

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

// The fixture group myGroup contains 3 users
$this->assertCount(
Expand All @@ -188,7 +188,7 @@ public function loadAllFixtures(): void
$repository
);

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

// Loading all fixtures results in 12 users.
$this->assertCount(
Expand All @@ -209,28 +209,49 @@ public function testAppendFixtures(): void
);

// Load data from database
/** @var User $user */
$user = $this->userRepository
$users = $this->userRepository->findAll();

// Check that there are 3 users.
$this->assertCount(
3,
$users
);

// Load data from database
/** @var User $user1 */
$user1 = $this->userRepository
->findOneBy([
'id' => 1,
])
;

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

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

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

/** @var User $user3 */
$user3 = $this->userRepository
->findOneBy([
'id' => 3,
])
;

$this->assertSame(
'bar@foo.com',
$user->getEmail()
'alice@bar.com',
$user3->getEmail()
);
}

Expand Down Expand Up @@ -390,8 +411,12 @@ public function testLoadFixturesFilesPaths(): void
$fixtures
);

$fixtureId = 'user_id_1';

$this->assertArrayHasKey($fixtureId, $fixtures);

/** @var User $user1 */
$user1 = $fixtures['id1'];
$user1 = $fixtures[$fixtureId];

$this->assertIsString($user1->getEmail());

Expand Down
Loading