Skip to content

Commit

Permalink
Fix: Rename variables in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Mar 15, 2020
1 parent d432211 commit 8777bdd
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 94 deletions.
22 changes: 11 additions & 11 deletions test/Integration/FixtureFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public function testAutomaticPersistCanBeTurnedOn(): void

$fixtureFactory->persistOnGet();

/** @var Fixture\FixtureFactory\Entity\Spaceship $ss */
$ss = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);
/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceship */
$spaceship = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);

$entityManager->flush();

self::assertNotNull($ss->getId());
self::assertSame($ss, $entityManager->find(Fixture\FixtureFactory\Entity\Spaceship::class, $ss->getId()));
self::assertNotNull($spaceship->getId());
self::assertSame($spaceship, $entityManager->find(Fixture\FixtureFactory\Entity\Spaceship::class, $spaceship->getId()));
}

public function testDoesNotPersistByDefault(): void
Expand All @@ -56,19 +56,19 @@ public function testDoesNotPersistByDefault(): void
'name' => 'Zeta',
]);

/** @var Fixture\FixtureFactory\Entity\Spaceship $ss */
$ss = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);
/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceship */
$spaceship = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);

$entityManager->flush();

self::assertNull($ss->getId());
self::assertNull($spaceship->getId());

$q = $entityManager->createQueryBuilder()
->select('ss')
->from(Fixture\FixtureFactory\Entity\Spaceship::class, 'ss')
$query = $entityManager->createQueryBuilder()
->select('spaceship')
->from(Fixture\FixtureFactory\Entity\Spaceship::class, 'spaceship')
->getQuery();

self::assertEmpty($q->getResult());
self::assertEmpty($query->getResult());
}

public function testDoesNotPersistEmbeddableWhenAutomaticPersistingIsTurnedOn(): void
Expand Down
166 changes: 83 additions & 83 deletions test/Unit/FixtureFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ public function testAcceptsConstantValuesInEntityDefinitions(): void
'name' => 'My BattleCruiser',
]);

/** @var Fixture\FixtureFactory\Entity\Spaceship $ss */
$ss = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);
/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceship */
$spaceship = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);

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

public function testAcceptsGeneratorFunctionsInEntityDefinitions(): void
Expand Down Expand Up @@ -165,12 +165,12 @@ public function testValuesCanBeOverriddenAtCreationTime(): void
'name' => 'My BattleCruiser',
]);

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

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

public function testPreservesDefaultValuesOfEntity(): void
Expand All @@ -179,10 +179,10 @@ public function testPreservesDefaultValuesOfEntity(): void

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

/** @var Fixture\FixtureFactory\Entity\Spaceship $ss */
$ss = $fixtureFactory->get(Fixture\FixtureFactory\Entity\SpaceStation::class);
/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceship */
$spaceship = $fixtureFactory->get(Fixture\FixtureFactory\Entity\SpaceStation::class);

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

public function testDoesNotCallTheConstructorOfTheEntity(): void
Expand All @@ -191,10 +191,10 @@ public function testDoesNotCallTheConstructorOfTheEntity(): void

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

/** @var Fixture\FixtureFactory\Entity\Spaceship $ss */
$ss = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);
/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceship */
$spaceship = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);

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

public function testInstantiatesCollectionAssociationsToBeEmptyCollectionsWhenUnspecified(): void
Expand All @@ -205,11 +205,11 @@ public function testInstantiatesCollectionAssociationsToBeEmptyCollectionsWhenUn
'name' => 'Battlestar Galaxy',
]);

/** @var Fixture\FixtureFactory\Entity\Spaceship $ss */
$ss = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);
/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceship */
$spaceship = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);

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

public function testArrayElementsAreMappedToCollectionAsscociationFields(): void
Expand All @@ -222,25 +222,25 @@ public function testArrayElementsAreMappedToCollectionAsscociationFields(): void
'spaceship' => FieldDef::reference(Fixture\FixtureFactory\Entity\Spaceship::class),
]);

/** @var Fixture\FixtureFactory\Entity\Person $p1 */
$p1 = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Person::class);
/** @var Fixture\FixtureFactory\Entity\Person $personOne */
$personOne = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Person::class);

/** @var Fixture\FixtureFactory\Entity\Person $p2 */
$p2 = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Person::class);
/** @var Fixture\FixtureFactory\Entity\Person $personTwo */
$personTwo = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Person::class);

/** @var Fixture\FixtureFactory\Entity\Spaceship $ship */
$ship = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class, [
/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceship */
$spaceship = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class, [
'name' => 'Battlestar Galaxy',
'crew' => [
$p1,
$p2,
$personOne,
$personTwo,
],
]);

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

self::assertTrue($ship->getCrew()->contains($p1));
self::assertTrue($ship->getCrew()->contains($p2));
self::assertTrue($spaceship->getCrew()->contains($personOne));
self::assertTrue($spaceship->getCrew()->contains($personTwo));
}

public function testUnspecifiedFieldsAreLeftNull(): void
Expand Down Expand Up @@ -311,11 +311,11 @@ public function testBidirectionalOntToManyReferencesAreAssignedBothWays(): void
/** @var Fixture\FixtureFactory\Entity\Person $person */
$person = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Person::class);

$ship = $person->getSpaceship();
$spaceship = $person->getSpaceship();

self::assertInstanceOf(Fixture\FixtureFactory\Entity\Spaceship::class, $ship);
self::assertInstanceOf(Fixture\FixtureFactory\Entity\Spaceship::class, $spaceship);

self::assertContains($person, $ship->getCrew());
self::assertContains($person, $spaceship->getCrew());
}

public function testUnidirectionalReferencesWorkAsUsual(): void
Expand Down Expand Up @@ -431,11 +431,11 @@ public function testAfterGettingAnEntityAsASingletonGettingTheEntityAgainReturns

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Spaceship::class);

/** @var Fixture\FixtureFactory\Entity\Spaceship $ss */
$ss = $fixtureFactory->getAsSingleton(Fixture\FixtureFactory\Entity\Spaceship::class);
/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceship */
$spaceship = $fixtureFactory->getAsSingleton(Fixture\FixtureFactory\Entity\Spaceship::class);

self::assertSame($ss, $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class));
self::assertSame($ss, $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class));
self::assertSame($spaceship, $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class));
self::assertSame($spaceship, $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class));
}

public function testGetAsSingletonMethodAcceptsFieldOverridesLikeGet(): void
Expand All @@ -444,17 +444,17 @@ public function testGetAsSingletonMethodAcceptsFieldOverridesLikeGet(): void

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Spaceship::class);

/** @var Fixture\FixtureFactory\Entity\Spaceship $ss */
$ss = $fixtureFactory->getAsSingleton(Fixture\FixtureFactory\Entity\Spaceship::class, [
/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceshipTwo */
$spaceshipOne = $fixtureFactory->getAsSingleton(Fixture\FixtureFactory\Entity\Spaceship::class, [
'name' => 'Beta',
]);

self::assertSame('Beta', $ss->getName());
self::assertSame('Beta', $spaceshipOne->getName());

/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceship */
$spaceship = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);
$spaceshipTwo = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);

self::assertSame('Beta', $spaceship->getName());
self::assertSame('Beta', $spaceshipTwo->getName());
}

public function testThrowsAnErrorWhenCallingGetSingletonTwiceOnTheSameEntity(): void
Expand All @@ -480,11 +480,11 @@ public function testAllowsSettingSingletons(): void

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Spaceship::class);

$ss = new Fixture\FixtureFactory\Entity\Spaceship('The mothership');
$spaceship = new Fixture\FixtureFactory\Entity\Spaceship('The mothership');

$fixtureFactory->setSingleton(Fixture\FixtureFactory\Entity\Spaceship::class, $ss);
$fixtureFactory->setSingleton(Fixture\FixtureFactory\Entity\Spaceship::class, $spaceship);

self::assertSame($ss, $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class));
self::assertSame($spaceship, $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class));
}

public function testAllowsUnsettingSingletons(): void
Expand All @@ -493,12 +493,12 @@ public function testAllowsUnsettingSingletons(): void

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Spaceship::class);

$ss = new Fixture\FixtureFactory\Entity\Spaceship('The mothership');
$spaceship = new Fixture\FixtureFactory\Entity\Spaceship('The mothership');

$fixtureFactory->setSingleton(Fixture\FixtureFactory\Entity\Spaceship::class, $ss);
$fixtureFactory->setSingleton(Fixture\FixtureFactory\Entity\Spaceship::class, $spaceship);
$fixtureFactory->unsetSingleton(Fixture\FixtureFactory\Entity\Spaceship::class);

self::assertNotSame($ss, $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class));
self::assertNotSame($spaceship, $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class));
}

public function testAllowsOverwritingExistingSingletons(): void
Expand All @@ -507,13 +507,13 @@ public function testAllowsOverwritingExistingSingletons(): void

$fixtureFactory->defineEntity(Fixture\FixtureFactory\Entity\Spaceship::class);

$ss1 = new Fixture\FixtureFactory\Entity\Spaceship('The mothership');
$ss2 = new Fixture\FixtureFactory\Entity\Spaceship('The battlecruiser');
$spaceshipOne = new Fixture\FixtureFactory\Entity\Spaceship('The mothership');
$spaceshipTwo = new Fixture\FixtureFactory\Entity\Spaceship('The battlecruiser');

$fixtureFactory->setSingleton(Fixture\FixtureFactory\Entity\Spaceship::class, $ss1);
$fixtureFactory->setSingleton(Fixture\FixtureFactory\Entity\Spaceship::class, $ss2);
$fixtureFactory->setSingleton(Fixture\FixtureFactory\Entity\Spaceship::class, $spaceshipOne);
$fixtureFactory->setSingleton(Fixture\FixtureFactory\Entity\Spaceship::class, $spaceshipTwo);

self::assertSame($ss2, $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class));
self::assertSame($spaceshipTwo, $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class));
}

public function testReferencedObjectsCanBeSingletons(): void
Expand All @@ -531,10 +531,10 @@ public function testReferencedObjectsCanBeSingletons(): void
/** @var Fixture\FixtureFactory\Entity\Person $person */
$person = $fixtureFactory->getAsSingleton(Fixture\FixtureFactory\Entity\Person::class);

/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceShip */
$spaceShip = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);
/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceship */
$spaceship = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);

$crew = $spaceShip->getCrew();
$crew = $spaceship->getCrew();

self::assertContains($person, $crew);
self::assertCount(1, $crew);
Expand All @@ -550,17 +550,17 @@ public function testWhenTheOneSideIsASingletonItMayGetSeveralChildObjects(): voi
'spaceship' => FieldDef::reference(Fixture\FixtureFactory\Entity\Spaceship::class),
]);

/** @var Fixture\FixtureFactory\Entity\Spaceship $ship */
$ship = $fixtureFactory->getAsSingleton(Fixture\FixtureFactory\Entity\Spaceship::class);
/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceship */
$spaceship = $fixtureFactory->getAsSingleton(Fixture\FixtureFactory\Entity\Spaceship::class);

/** @var Fixture\FixtureFactory\Entity\Person $p1 */
$p1 = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Person::class);
/** @var Fixture\FixtureFactory\Entity\Person $personOne */
$personOne = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Person::class);

/** @var Fixture\FixtureFactory\Entity\Person $p2 */
$p2 = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Person::class);
/** @var Fixture\FixtureFactory\Entity\Person $personTwo */
$personTwo = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Person::class);

self::assertContains($p1, $ship->getCrew());
self::assertContains($p2, $ship->getCrew());
self::assertContains($personOne, $spaceship->getCrew());
self::assertContains($personTwo, $spaceship->getCrew());
}

public function testCanInvokeACallbackAfterObjectConstruction(): void
Expand All @@ -573,16 +573,16 @@ public function testCanInvokeACallbackAfterObjectConstruction(): void
'name' => 'Foo',
],
[
'afterCreate' => static function (Fixture\FixtureFactory\Entity\Spaceship $ss, array $fieldValues): void {
$ss->setName($ss->getName() . '-' . $fieldValues['name']);
'afterCreate' => static function (Fixture\FixtureFactory\Entity\Spaceship $spaceship, array $fieldValues): void {
$spaceship->setName($spaceship->getName() . '-' . $fieldValues['name']);
},
]
);

/** @var Fixture\FixtureFactory\Entity\Spaceship $ss */
$ss = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);
/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceship */
$spaceship = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class);

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

public function testTheAfterCreateCallbackCanBeUsedToCallTheConstructor(): void
Expand All @@ -595,19 +595,19 @@ public function testTheAfterCreateCallbackCanBeUsedToCallTheConstructor(): void
'name' => 'Foo',
],
[
'afterCreate' => static function (Fixture\FixtureFactory\Entity\Spaceship $ss, array $fieldValues): void {
$ss->__construct($fieldValues['name'] . 'Master');
'afterCreate' => static function (Fixture\FixtureFactory\Entity\Spaceship $spaceship, array $fieldValues): void {
$spaceship->__construct($fieldValues['name'] . 'Master');
},
]
);

/** @var Fixture\FixtureFactory\Entity\Spaceship $ss */
$ss = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class, [
/** @var Fixture\FixtureFactory\Entity\Spaceship $spaceship */
$spaceship = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Spaceship::class, [
'name' => 'Xoo',
]);

self::assertTrue($ss->constructorWasCalled());
self::assertSame('XooMaster', $ss->getName());
self::assertTrue($spaceship->constructorWasCalled());
self::assertSame('XooMaster', $spaceship->getName());
}

public function testReferencedObjectShouldBeCreatedAutomatically(): void
Expand All @@ -627,12 +627,12 @@ public function testReferencedObjectShouldBeCreatedAutomatically(): void
/** @var Fixture\FixtureFactory\Entity\Person $personTwo */
$personTwo = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Person::class);

$ss1 = $personOne->getSpaceship();
$ss2 = $personTwo->getSpaceship();
$spaceshipOne = $personOne->getSpaceship();
$spaceshipTwo = $personTwo->getSpaceship();

self::assertNotNull($ss1);
self::assertNotNull($ss2);
self::assertNotSame($ss1, $ss2);
self::assertNotNull($spaceshipOne);
self::assertNotNull($spaceshipTwo);
self::assertNotSame($spaceshipOne, $spaceshipTwo);
}

public function testReferencesGetInstantiatedTransitively(): void
Expand Down Expand Up @@ -675,17 +675,17 @@ public function testTransitiveReferencesWorkWithSingletons(): void

$fixtureFactory->getAsSingleton(Fixture\FixtureFactory\Entity\Spaceship::class);

/** @var Fixture\FixtureFactory\Entity\Badge $badge1 */
$badge1 = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Badge::class);
/** @var Fixture\FixtureFactory\Entity\Badge $badgeOne */
$badgeOne = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Badge::class);

/** @var Fixture\FixtureFactory\Entity\Badge $badge2 */
$badge2 = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Badge::class);
/** @var Fixture\FixtureFactory\Entity\Badge $badgeTwo */
$badgeTwo = $fixtureFactory->get(Fixture\FixtureFactory\Entity\Badge::class);

$ownerOne = $badge1->getOwner();
$ownerOne = $badgeOne->getOwner();

self::assertInstanceOf(Fixture\FixtureFactory\Entity\Person::class, $ownerOne);

$ownerTwo = $badge2->getOwner();
$ownerTwo = $badgeTwo->getOwner();

self::assertInstanceOf(Fixture\FixtureFactory\Entity\Person::class, $ownerTwo);

Expand Down

0 comments on commit 8777bdd

Please sign in to comment.