Skip to content
Permalink
Browse files

Merge pull request #43 from ergebnis/fix/split

Fix: Split defining and getting entities
  • Loading branch information
localheinz committed Mar 14, 2020
2 parents 19c3864 + 0359971 commit 6c76035c2f88085e280affb601e7a893b743f123
Showing with 33 additions and 21 deletions.
  1. +33 −21 test/Unit/FixtureFactoryTest.php
@@ -31,6 +31,15 @@
*/
final class FixtureFactoryTest extends AbstractTestCase
{
public function testDefineReturnsFixtureFactory(): void
{
$entityManager = self::createEntityManager();

$fixtureFactory = new FixtureFactory($entityManager);

self::assertSame($fixtureFactory, $fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\User::class));
}

public function testGetThrowsEntityDefinitionUnavailableWhenDefinitionIsUnavailable(): void
{
$entityManager = $this->prophesize(ORM\EntityManagerInterface::class)->reveal();
@@ -112,11 +121,11 @@ public function testAcceptsConstantValuesInEntityDefinitions(): void
{
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$ss = $fixtureFactory
->defineEntity(Fixture\FixtureFactory\Entity\Spaceship::class, [
'name' => 'My BattleCruiser',
])
->get(Fixture\FixtureFactory\Entity\Spaceship::class);
$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Spaceship::class, [
'name' => 'My BattleCruiser',
]);

$ss = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);

self::assertSame('My BattleCruiser', $ss->getName());
}
@@ -142,43 +151,46 @@ public function testValuesCanBeOverriddenAtCreationTime(): void
{
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$ss = $fixtureFactory
->defineEntity(Fixture\FixtureFactory\Entity\Spaceship::class, [
'name' => 'My BattleCruiser',
])
->get(Fixture\FixtureFactory\Entity\Spaceship::class, ['name' => 'My CattleBruiser']);
$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Spaceship::class, [
'name' => 'My BattleCruiser',
]);

$ss = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class, ['name' => 'My CattleBruiser']);

self::assertSame('My CattleBruiser', $ss->getName());
}

public function testPreservesDefaultValuesOfEntity(): void
{
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$ss = $fixtureFactory
->defineEntity(Fixture\FixtureFactory\Entity\SpaceStation::class)
->get(Fixture\FixtureFactory\Entity\SpaceStation::class);
$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\SpaceStation::class);

$ss = $fixtureFactory->get(Fixture\FixtureFactory\Entity\SpaceStation::class);

self::assertSame('Babylon5', $ss->getName());
}

public function testDoesNotCallTheConstructorOfTheEntity(): void
{
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$ss = $fixtureFactory
->defineEntity(Fixture\FixtureFactory\Entity\Spaceship::class, [])
->get(Fixture\FixtureFactory\Entity\Spaceship::class);
$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Spaceship::class, []);

$ss = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);

self::assertFalse($ss->constructorWasCalled());
}

public function testInstantiatesCollectionAssociationsToBeEmptyCollectionsWhenUnspecified(): void
{
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$ss = $fixtureFactory
->defineEntity(Fixture\FixtureFactory\Entity\Spaceship::class, [
'name' => 'Battlestar Galaxy',
])
->get(Fixture\FixtureFactory\Entity\Spaceship::class);
$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Spaceship::class, [
'name' => 'Battlestar Galaxy',
]);

$ss = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);

self::assertInstanceOf(Common\Collections\ArrayCollection::class, $ss->getCrew());
self::assertEmpty($ss->getCrew());

0 comments on commit 6c76035

Please sign in to comment.
You can’t perform that action at this time.