Skip to content
Permalink
Browse files

Merge pull request #21 from ergebnis/fix/entity-manager

Fix: Do not create entity manager in setUp()
  • Loading branch information
localheinz committed Mar 9, 2020
2 parents cd1eb31 + 671f0cd commit 6621d3c27e00e66f7f89a4a87dab1c9094a2257a
@@ -785,11 +785,6 @@ parameters:
count: 1
path: test/Doctrine/Fixtures/TestCase.php

-
message: "#^Method FactoryGirl\\\\Tests\\\\Provider\\\\Doctrine\\\\Fixtures\\\\TestCase\\:\\:setUp\\(\\) is not final, but since the containing class is abstract, it should be\\.$#"
count: 1
path: test/Doctrine/Fixtures/TestCase.php

-
message: "#^Parameter \\#1 \\$paths of method Doctrine\\\\ORM\\\\Configuration\\:\\:newDefaultAnnotationDriver\\(\\) expects array, string given\\.$#"
count: 1
@@ -13,7 +13,7 @@ class BasicUsageTest extends TestCase
*/
public function acceptsConstantValuesInEntityDefinitions()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$ss = $fixtureFactory
->defineEntity(Entity\SpaceShip::class, [
@@ -31,7 +31,7 @@ public function acceptsGeneratorFunctionsInEntityDefinitions()
{
$name = "Star";

$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class, [
'name' => function () use (&$name) {
@@ -49,7 +49,7 @@ public function acceptsGeneratorFunctionsInEntityDefinitions()
*/
public function valuesCanBeOverriddenAtCreationTime()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$ss = $fixtureFactory
->defineEntity(Entity\SpaceShip::class, [
@@ -64,7 +64,7 @@ public function valuesCanBeOverriddenAtCreationTime()
*/
public function preservesDefaultValuesOfEntity()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$ss = $fixtureFactory
->defineEntity(Entity\SpaceStation::class)
@@ -77,7 +77,7 @@ public function preservesDefaultValuesOfEntity()
*/
public function doesNotCallTheConstructorOfTheEntity()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$ss = $fixtureFactory
->defineEntity(Entity\SpaceShip::class, [])
@@ -90,7 +90,7 @@ public function doesNotCallTheConstructorOfTheEntity()
*/
public function instantiatesCollectionAssociationsToBeEmptyCollectionsWhenUnspecified()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$ss = $fixtureFactory
->defineEntity(Entity\SpaceShip::class, [
@@ -107,7 +107,7 @@ public function instantiatesCollectionAssociationsToBeEmptyCollectionsWhenUnspec
*/
public function arrayElementsAreMappedToCollectionAsscociationFields()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class);
$fixtureFactory->defineEntity(Entity\Person::class, [
@@ -132,7 +132,7 @@ public function arrayElementsAreMappedToCollectionAsscociationFields()
*/
public function unspecifiedFieldsAreLeftNull()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class);
$this->assertNull($fixtureFactory->get(Entity\SpaceShip::class)->getName());
@@ -143,7 +143,7 @@ public function unspecifiedFieldsAreLeftNull()
*/
public function entityIsDefinedToDefaultNamespace()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class);
$fixtureFactory->defineEntity(Entity\Person\User::class);
@@ -164,7 +164,7 @@ public function entityIsDefinedToDefaultNamespace()
*/
public function entityCanBeDefinedToAnotherNamespace()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(
Entity\Artist::class
@@ -183,7 +183,7 @@ public function entityCanBeDefinedToAnotherNamespace()
*/
public function returnsListOfEntities()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class);

@@ -195,7 +195,7 @@ public function returnsListOfEntities()
*/
public function canSpecifyNumberOfReturnedInstances()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class);

@@ -12,7 +12,7 @@ class BidirectionalReferencesTest extends TestCase
*/
public function bidirectionalOntToManyReferencesAreAssignedBothWays()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class);
$fixtureFactory->defineEntity(Entity\Person::class, [
@@ -30,7 +30,7 @@ public function bidirectionalOntToManyReferencesAreAssignedBothWays()
*/
public function unidirectionalReferencesWorkAsUsual()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\Badge::class, [
'owner' => FieldDef::reference(Entity\Person::class)
@@ -45,7 +45,7 @@ public function unidirectionalReferencesWorkAsUsual()
*/
public function whenTheOneSideIsASingletonItMayGetSeveralChildObjects()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class);
$fixtureFactory->defineEntity(Entity\Person::class, [
@@ -11,7 +11,7 @@ class ExtraConfigurationTest extends TestCase
*/
public function canInvokeACallbackAfterObjectConstruction()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class, [
'name' => 'Foo'
@@ -30,7 +30,7 @@ public function canInvokeACallbackAfterObjectConstruction()
*/
public function theAfterCreateCallbackCanBeUsedToCallTheConstructor()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class, [
'name' => 'Foo'
@@ -11,7 +11,7 @@ class IncorrectUsageTest extends TestCase
*/
public function throwsWhenTryingToDefineTheSameEntityTwice()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class);

@@ -25,7 +25,7 @@ public function throwsWhenTryingToDefineTheSameEntityTwice()
*/
public function throwsWhenTryingToDefineEntitiesThatAreNotEvenClasses()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$this->expectException(\Exception::class);

@@ -37,7 +37,7 @@ public function throwsWhenTryingToDefineEntitiesThatAreNotEvenClasses()
*/
public function throwsWhenTryingToDefineEntitiesThatAreNotEntities()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$this->assertTrue(class_exists(Entity\NotAnEntity::class, true));

@@ -51,7 +51,7 @@ public function throwsWhenTryingToDefineEntitiesThatAreNotEntities()
*/
public function throwsWhenTryingToDefineNonexistentFields()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$this->expectException(\Exception::class);

@@ -65,7 +65,7 @@ public function throwsWhenTryingToDefineNonexistentFields()
*/
public function throwsWhenTryingToGiveNonexistentFieldsWhileConstructing()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class, ['name' => 'Alpha']);

@@ -81,7 +81,7 @@ public function throwsWhenTryingToGiveNonexistentFieldsWhileConstructing()
*/
public function throwsWhenTryingToGetLessThanOneInstance()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class);

@@ -13,34 +13,38 @@ class PersistingTest extends TestCase
*/
public function automaticPersistCanBeTurnedOn()
{
$fixtureFactory = new FixtureFactory($this->em);
$entityManager = self::createEntityManager();

$fixtureFactory = new FixtureFactory($entityManager);

$fixtureFactory->defineEntity(Entity\SpaceShip::class, ['name' => 'Zeta']);

$fixtureFactory->persistOnGet();

$ss = $fixtureFactory->get(Entity\SpaceShip::class);
$this->em->flush();
$entityManager->flush();

$this->assertNotNull($ss->getId());
$this->assertSame($ss, $this->em->find(Entity\SpaceShip::class, $ss->getId()));
$this->assertSame($ss, $entityManager->find(Entity\SpaceShip::class, $ss->getId()));
}

/**
* @test
*/
public function doesNotPersistByDefault()
{
$fixtureFactory = new FixtureFactory($this->em);
$entityManager = self::createEntityManager();

$fixtureFactory = new FixtureFactory($entityManager);

$fixtureFactory->defineEntity(Entity\SpaceShip::class, ['name' => 'Zeta']);

$ss = $fixtureFactory->get(Entity\SpaceShip::class);

$this->em->flush();
$entityManager->flush();

$this->assertNull($ss->getId());
$q = $this->em
$q = $entityManager
->createQueryBuilder()
->select('ss')
->from(Entity\SpaceShip::class, 'ss')
@@ -64,7 +68,9 @@ public function doesNotPersistEmbeddableWhenAutomaticPersistingIsTurnedOn()
}
}

$fixtureFactory = new FixtureFactory($this->em);
$entityManager = self::createEntityManager();

$fixtureFactory = new FixtureFactory($entityManager);

$fixtureFactory->defineEntity(Entity\Name::class, [
'first' => FieldDef::sequence(static function () {
@@ -99,6 +105,6 @@ public function doesNotPersistEmbeddableWhenAutomaticPersistingIsTurnedOn()
$this->assertInstanceOf(Entity\Commander::class, $commander);
$this->assertInstanceOf(Entity\Name::class, $commander->name());

$this->em->flush();
$entityManager->flush();
}
}
@@ -12,7 +12,7 @@ class ReferenceTest extends TestCase
*/
public function referencedObjectShouldBeCreatedAutomatically()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class);
$fixtureFactory->defineEntity(Entity\Person::class, [
@@ -33,7 +33,7 @@ public function referencedObjectShouldBeCreatedAutomatically()
*/
public function referencedObjectsShouldBeNullable()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class);
$fixtureFactory->defineEntity(Entity\Person::class, [
@@ -15,7 +15,7 @@ class ReferencesTest extends TestCase
*/
public function referencedObjectsShouldBeCreatedAutomatically()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class, [
'crew' => FieldDef::references(Entity\Person::class)
@@ -42,7 +42,7 @@ public function referencedObjectsShouldBeOverrideable()
{
$count = 5;

$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class, [
'crew' => FieldDef::references(Entity\Person::class)
@@ -69,7 +69,7 @@ public function referencedObjectsShouldBeOverrideable()
*/
public function referencedObjectsShouldBeNullable()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class, [
'crew' => FieldDef::references(Entity\Person::class)
@@ -95,7 +95,7 @@ public function referencedObjectsShouldBeNullable()
*/
public function referencedObjectsCanBeSingletons()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class, [
'crew' => FieldDef::references(Entity\Person::class)
@@ -13,7 +13,7 @@ class SequenceTest extends TestCase
*/
public function sequenceGeneratorCallsAFunctionWithAnIncrementingArgument()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class, [
'name' => FieldDef::sequence(function ($n) {
@@ -31,7 +31,7 @@ public function sequenceGeneratorCallsAFunctionWithAnIncrementingArgument()
*/
public function sequenceGeneratorCanTakeAPlaceholderString()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class, [
'name' => FieldDef::sequence("Beta %d")
@@ -47,7 +47,7 @@ public function sequenceGeneratorCanTakeAPlaceholderString()
*/
public function sequenceGeneratorCanTakeAStringToAppendTo()
{
$fixtureFactory = new FixtureFactory($this->em);
$fixtureFactory = new FixtureFactory(self::createEntityManager());

$fixtureFactory->defineEntity(Entity\SpaceShip::class, [
'name' => FieldDef::sequence("Gamma ")

0 comments on commit 6621d3c

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