Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Use Doctrine persistence package
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierstoval committed Feb 2, 2020
1 parent a08bda3 commit 5737139
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions AbstractFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
use Doctrine\Common\DataFixtures\AbstractFixture as BaseAbstractFixture;
use Doctrine\ORM\Id\AssignedGenerator;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Instantiator\Instantiator;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use ReflectionClass;
use function count;
use function method_exists;
use RuntimeException;
use function sprintf;
Expand Down Expand Up @@ -90,7 +91,7 @@ public function load(ObjectManager $manager)

$objects = $this->getObjects();

$this->totalNumberOfObjects = \count($objects);
$this->totalNumberOfObjects = count($objects);

$this->numberOfIteratedObjects = 0;
foreach ($objects as $data) {
Expand All @@ -114,7 +115,7 @@ public function load(ObjectManager $manager)
/**
* Creates the object and persist it in database.
*
* @param object $data
* @param array $data
*/
private function fixtureObject(array $data): void
{
Expand All @@ -127,7 +128,7 @@ private function fixtureObject(array $data): void
// This means that it _may_ break objects for which ids are not provided in the fixtures.
$metadata = $this->manager->getClassMetadata($this->getEntityClass());
$primaryKey = $metadata->getIdentifierFieldNames();
if (1 === \count($primaryKey) && isset($data[$primaryKey[0]])) {
if (1 === count($primaryKey) && isset($data[$primaryKey[0]])) {
$metadata->setIdGeneratorType($metadata::GENERATOR_TYPE_NONE);
$metadata->setIdGenerator(new AssignedGenerator());
}
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"require": {
"php": "^7.2",
"doctrine/orm": "^2.6",
"doctrine/persistence": "^1.3",
"doctrine/instantiator": "^1.1"
},
"require-dev": {
Expand Down

0 comments on commit 5737139

Please sign in to comment.