Last active
          September 1, 2017 14:00 
        
      - 
      
- 
        Save tinker1987/bdc62bbc4c4d57f4fba3eef5c31f805a to your computer and use it in GitHub Desktop. 
Revisions
- 
        tinker1987 revised this gist Sep 1, 2017 . 1 changed file with 6 additions and 7 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,10 +3,9 @@ namespace Tests; use Doctrine\Common\DataFixtures\{ Executor\ORMExecutor, FixtureInterface, Purger\ORMPurger, SharedFixtureInterface }; use Doctrine\Common\Persistence\ObjectManager; use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader; @@ -28,7 +27,6 @@ trait FixtureAwareTestCaseTrait private $fixtureLoader; /** * @param FixtureInterface $fixture * @return self */ @@ -40,10 +38,11 @@ protected function addFixture(FixtureInterface $fixture) /** * Executes all the fixtures that have been loaded so far. * @param bool $append */ protected function executeFixtures(bool $append = false) { $this->getFixtureExecutor()->execute($this->getFixtureLoader()->getFixtures(), $append); } /** 
- 
        tinker1987 revised this gist Sep 1, 2017 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,6 +46,14 @@ protected function executeFixtures() $this->getFixtureExecutor()->execute($this->getFixtureLoader()->getFixtures()); } /** * Purges loaded fixtures from DB */ protected function purgeFixtures() { $this->getFixtureExecutor()->getPurger()->purge(); } /** * @return ORMExecutor */ 
- 
        tinker1987 revised this gist Aug 30, 2017 . 1 changed file with 17 additions and 1 deletion.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,8 @@ use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Doctrine\Common\DataFixtures\SharedFixtureInterface; use Doctrine\Common\Persistence\ObjectManager; use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader; /** @@ -54,7 +56,21 @@ private function getFixtureExecutor() * @var \Doctrine\ORM\EntityManager $entityManager */ $entityManager = self::$kernel->getContainer()->get('doctrine')->getManager(); $this->fixtureExecutor = new class ($entityManager, new ORMPurger($entityManager)) extends ORMExecutor { /** * @inheritDoc */ public function load(ObjectManager $manager, FixtureInterface $fixture) { if ($fixture instanceof SharedFixtureInterface) { $fixture->setReferenceRepository($this->referenceRepository); } $fixture->load($manager); } }; } return $this->fixtureExecutor; } 
- 
        tinker1987 revised this gist Aug 25, 2017 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,12 +27,13 @@ trait FixtureAwareTestCaseTrait /** * Adds a new fixture to be loaded. * @param FixtureInterface $fixture * @return self */ protected function addFixture(FixtureInterface $fixture) { $this->getFixtureLoader()->addFixture($fixture); return $this; } /** 
- 
        tinker1987 created this gist Aug 24, 2017 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ <?php declare(strict_types=1); namespace Tests; use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\DataFixtures\Purger\ORMPurger; use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader; /** * Class FixtureAwareTestCaseTrait * @package Tests * @author Dmytro Paiareli <[email protected]> */ trait FixtureAwareTestCaseTrait { /** * @var ORMExecutor */ private $fixtureExecutor; /** * @var ContainerAwareLoader */ private $fixtureLoader; /** * Adds a new fixture to be loaded. * * @param FixtureInterface $fixture */ protected function addFixture(FixtureInterface $fixture) { $this->getFixtureLoader()->addFixture($fixture); } /** * Executes all the fixtures that have been loaded so far. */ protected function executeFixtures() { $this->getFixtureExecutor()->execute($this->getFixtureLoader()->getFixtures()); } /** * @return ORMExecutor */ private function getFixtureExecutor() { if (!$this->fixtureExecutor) { /** * @var \Doctrine\ORM\EntityManager $entityManager */ $entityManager = self::$kernel->getContainer()->get('doctrine')->getManager(); $this->fixtureExecutor = new ORMExecutor($entityManager, new ORMPurger($entityManager)); } return $this->fixtureExecutor; } /** * @return ContainerAwareLoader */ private function getFixtureLoader() { if (!$this->fixtureLoader) { $this->fixtureLoader = new ContainerAwareLoader(self::$kernel->getContainer()); } return $this->fixtureLoader; } }