getFixtures() public method

Returns the array of data fixtures to execute.
public getFixtures ( ) : array
return array $fixtures
 /** @test */
 public function should_find_post_by_id()
 {
     $this->executor->execute($this->loader->getFixtures());
     $post = $this->repository->threadOfId(PostId::fromString('d16f9fe7-e947-460e-99f6-2d64d65f46bc'));
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Discussion\\Post', $post);
     $this->assertEquals('d16f9fe7-e947-460e-99f6-2d64d65f46bc', $post->id());
 }
Esempio n. 2
0
 /**
  * Napolni podatke iz Fixtures
  */
 public function populateTestAction()
 {
     $logger = function ($message) {
         echo $message . PHP_EOL;
     };
     $em = $this->serviceLocator->get("\\Doctrine\\ORM\\EntityManager");
     $config = new Config($this->serviceLocator->get('config'));
     $loader = new Loader();
     $fixtures = isset($config->test_fixtures) ? $config->test_fixtures : [];
     $fixturename = $this->params('fixturename');
     if (!empty($fixturename)) {
         foreach ($fixtures as $dir) {
             $loader->loadFromFile($dir . '/' . $fixturename . 'Fixture.php');
             /**
              * če je dependent naj ne izvede nobenega
              */
             if (count($loader->getFixtures()) > 1) {
                 throw new \InvalidArgumentException('Loadanih več fixtur-jev -verjetno zaradi dependencies. Kot parameter možen le fixture brez odvisnosti.');
             }
         }
     } else {
         foreach ($fixtures as $dir) {
             $loader->loadFromDirectory($dir);
         }
     }
     $executor = new ORMExecutor($em);
     $executor->setLogger($logger);
     $executor->execute($loader->getFixtures(), true);
 }
 /** @test */
 public function should_find_group_by_slug()
 {
     $this->executor->execute($this->loader->getFixtures());
     $group = $this->repository->groupOfSlug('cribbb');
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Groups\\Group', $group);
     $this->assertEquals('cribbb', $group->slug());
 }
Esempio n. 4
0
 /**
  * @return \Doctrine\Common\DataFixtures\AbstractFixture
  */
 public function getFixture($className)
 {
     $this->loadEntities();
     foreach ($this->loader->getFixtures() as $fixture) {
         if ($fixture instanceof $className) {
             return $fixture;
         }
     }
 }
 /** @test */
 public function should_update_existing_user()
 {
     $this->executor->execute($this->loader->getFixtures());
     $user = $this->repository->userOfUsername(new Username('username'));
     $username = new Username('new_username');
     $user->updateUsername($username);
     $this->repository->update($user);
     $this->em->clear();
     $user = $this->repository->userOfUsername($username);
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Identity\\User', $user);
     $this->assertEquals($username, $user->username());
 }
Esempio n. 6
0
 public function testLoader()
 {
     $loader = new Loader();
     $loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\FixtureInterface'), array(), array(), 'Mock1');
     $loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\FixtureInterface', array(), array(), 'Mock2'));
     $loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\SharedFixtureInterface', array(), array(), 'Mock3'));
     $this->assertEquals(3, count($loader->getFixtures()));
     $loader->loadFromDirectory(__DIR__ . '/TestFixtures');
     $this->assertEquals(7, count($loader->getFixtures()));
     $this->assertTrue($loader->isTransient('TestFixtures\\NotAFixture'));
     $this->assertFalse($loader->isTransient('TestFixtures\\MyFixture1'));
 }
Esempio n. 7
0
    public function testLoader()
    {
        $loader = new Loader();
        $loader->addFixture($this->getMock('Doctrine\Common\DataFixtures\FixtureInterface'));
        $loader->addFixture($this->getMock('Doctrine\Common\DataFixtures\FixtureInterface'));

        $this->assertEquals(2, count($loader->getFixtures()));

        $loader->loadFromDirectory(__DIR__.'/TestFixtures');
        $this->assertEquals(4, count($loader->getFixtures()));
        $this->assertTrue($loader->isTransient('TestFixtures\NotAFixture'));
        $this->assertFalse($loader->isTransient('TestFixtures\MyFixture1'));
    }
 /**
  * Append a certain fixture
  *
  * @param  AbstractFixture $fixture
  * @param  array           $options (default: [])
  * @return void
  */
 protected static function appendFixture(AbstractFixture $fixture, array $options = [])
 {
     $em = static::getClient(isset($options['new_client']) ? $options['new_client'] : false)->getContainer()->get('doctrine')->getManager();
     $loader = new Loader();
     $loader->addFixture($fixture);
     if (isset($options['purge']) && $options['purge']) {
         $purger = new ORMPurger($em);
         $executor = new ORMExecutor($em, $purger);
         $executor->execute($loader->getFixtures(), false);
     } else {
         $executor = new ORMExecutor($em);
         $executor->execute($loader->getFixtures(), true);
     }
 }
Esempio n. 9
0
 public function testLoadFromFile()
 {
     $loader = new Loader();
     $loader->addFixture($this->getMockBuilder(FixtureInterface::class)->setMockClassName('Mock1')->getMock());
     $loader->addFixture($this->getMockBuilder(FixtureInterface::class)->setMockClassName('Mock2')->getMock());
     $loader->addFixture($this->getMockBuilder(SharedFixtureInterface::class)->setMockClassName('Mock3')->getMock());
     $this->assertCount(3, $loader->getFixtures());
     $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture1.php');
     $this->assertCount(4, $loader->getFixtures());
     $loader->loadFromFile(__DIR__ . '/TestFixtures/NotAFixture.php');
     $this->assertCount(4, $loader->getFixtures());
     $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture2.php');
     $this->assertCount(5, $loader->getFixtures());
     $this->assertTrue($loader->isTransient('TestFixtures\\NotAFixture'));
     $this->assertFalse($loader->isTransient('TestFixtures\\MyFixture1'));
 }
Esempio n. 10
0
 /**
  * Executes the current command.
  *
  * This method is not abstract because you can use this class
  * as a concrete class. In this case, instead of defining the
  * execute() method, you set the code to execute by passing
  * a Closure to the setCode() method.
  *
  * @param InputInterface $input An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return null|int null or 0 if everything went fine, or an error code
  *
  * @throws LogicException When this abstract method is not implemented
  *
  * @see setCode()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var QuestionHelper $helper */
     $helper = $this->getHelper('question');
     $question = new ConfirmationQuestion('All data in User table will be purged before inserting default data.
          Are you sure you want to continue?', false);
     if (!$helper->ask($input, $output, $question)) {
         return;
     }
     try {
         $loader = new Loader();
         $loader->loadFromDirectory(__DIR__ . '/../fixtures');
         $fixtures = $loader->getFixtures();
         $purger = new ORMPurger($this->em);
         $executor = new ORMExecutor($this->em, $purger);
         $executor->setLogger(function ($message) use($output) {
             $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
         });
         $executor->execute($fixtures);
         $output->writeln('Default users have been successfully loaded!');
         return 0;
     } catch (\Exception $e) {
         $output->writeLn("That's bad. An Error occurred: <error>{$e->getMessage()}</error>");
         return 1;
     }
 }
 public function adminRefreshDatabaseAction(Request $request, Application $app)
 {
     $conn = $app['db'];
     $em = $app['doctrine.orm.entity_manager'];
     $params = $conn->getParams();
     $name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false);
     try {
         $conn->getSchemaManager()->dropDatabase($name);
         $conn->getSchemaManager()->createDatabase($name);
         $conn->close();
     } catch (\Exception $e) {
         return 1;
     }
     $classes = [];
     foreach ($app['authbucket_oauth2.model'] as $class) {
         $classes[] = $em->getClassMetadata($class);
     }
     PersistentObject::setObjectManager($em);
     $tool = new SchemaTool($em);
     $tool->dropSchema($classes);
     $tool->createSchema($classes);
     $purger = new ORMPurger();
     $executor = new ORMExecutor($em, $purger);
     $loader = new Loader();
     $loader->loadFromDirectory(__DIR__ . '/../DataFixtures/ORM');
     $executor->execute($loader->getFixtures());
     return $app->redirect($app['url_generator']->generate('index'));
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getEntityManager();
     if ($input->isInteractive() && !$input->getOption('append')) {
         if (!$this->askConfirmation($input, $output, '<question>Careful, database will be purged. Do you want to continue y/N ?</question>', false)) {
             return;
         }
     }
     $app = $this->getApp();
     $path = $app->getApplicationBase($app->getAppNamespace()) . '/DataFixture';
     $loader = new DataFixturesLoader();
     $loader->loadFromDirectory($path);
     $fixtures = $loader->getFixtures();
     if (!$fixtures) {
         throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- {$path}"));
     }
     foreach ($fixtures as $fixture) {
         if ($fixture instanceof ContainerAwareInterface) {
             $fixture->setContainer($this->getContainer());
         }
     }
     $purger = new ORMPurger($em);
     if ($input->getOption('truncate-only')) {
         $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
         $purger->purge();
         exit(0);
     }
     $purger->setPurgeMode($input->getOption('truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
     $executor = new ORMExecutor($em, $purger);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     $executor->execute($fixtures, $input->getOption('append'));
 }
Esempio n. 13
0
 /**
  * Initializes the database (once).
  *
  * @throws \Doctrine\DBAL\DBALException
  * @throws \Doctrine\ORM\ORMException
  * @throws \Doctrine\ORM\Tools\ToolsException
  */
 protected function setUp()
 {
     if (null === static::$_conn) {
         $dbPath = __DIR__ . '/../../../db.sqlite';
         if (file_exists($dbPath)) {
             unlink($dbPath);
         }
         $params = ['driver' => 'pdo_sqlite', 'path' => $dbPath];
         static::$_conn = DriverManager::getConnection($params);
         static::$_conn->getConfiguration()->setSQLLogger(null);
     }
     if (null === static::$_em) {
         $paths = [__DIR__ . '/../../../../../src/Ekyna/Commerce/Bridge/Doctrine/ORM/Resources/mapping'];
         $isDevMode = true;
         $config = Setup::createXMLMetadataConfiguration($paths, $isDevMode);
         $em = EntityManager::create(static::$_conn, $config);
         $classes = [];
         foreach (static::$_classes as $class) {
             array_push($classes, $em->getClassMetadata($class));
         }
         $schemaTool = new SchemaTool($em);
         $schemaTool->dropSchema($classes);
         $schemaTool->createSchema($classes);
         // Load fixtures
         $loader = new Loader();
         $loader->loadFromDirectory(__DIR__ . '/../../../../../src/Ekyna/Commerce/Bridge/Doctrine/Fixtures');
         $purger = new ORMPurger();
         $executor = new ORMExecutor($em, $purger);
         $executor->execute($loader->getFixtures());
         static::$_em = $em;
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = $this->getApplication()->getApp();
     $em = $app['em'];
     $dirOrFile = $input->getOption('fixtures');
     if ($dirOrFile) {
         $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
     } else {
         $paths = isset($app['em.fixtures']) ? $app['em.fixtures'] : array();
     }
     $loader = new Loader();
     foreach ($paths as $path) {
         if (is_dir($path)) {
             $loader->loadFromDirectory($path);
         }
     }
     $fixtures = $loader->getFixtures();
     if (!$fixtures) {
         throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths)));
     }
     $purger = new ORMPurger($em);
     $purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
     $executor = new ORMExecutor($em, $purger);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     $executor->execute($fixtures, $input->getOption('append'));
 }
Esempio n. 15
0
 public function testLoadFromFile()
 {
     $loader = new Loader();
     $loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\FixtureInterface'), array(), array(), 'Mock1');
     $loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\FixtureInterface', array(), array(), 'Mock2'));
     $loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\SharedFixtureInterface', array(), array(), 'Mock3'));
     $this->assertCount(3, $loader->getFixtures());
     $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture1.php');
     $this->assertCount(4, $loader->getFixtures());
     $loader->loadFromFile(__DIR__ . '/TestFixtures/NotAFixture.php');
     $this->assertCount(4, $loader->getFixtures());
     $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture2.php');
     $this->assertCount(5, $loader->getFixtures());
     $this->assertTrue($loader->isTransient('TestFixtures\\NotAFixture'));
     $this->assertFalse($loader->isTransient('TestFixtures\\MyFixture1'));
 }
Esempio n. 16
0
 private function loadFixtures()
 {
     $loader = new Loader();
     $loader->addFixture(new LoadAchievementData());
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->manager, $purger);
     $executor->execute($loader->getFixtures());
 }
 /**
  * @param $directories
  * @return mixed
  * @throws \InvalidArgumentException
  */
 public function getFixtures($directories)
 {
     /** @var \SplFileInfo $directory */
     foreach ($directories as $directory) {
         $this->loader->loadFromDirectory($directory->getRealPath());
     }
     return $this->loader->getFixtures();
 }
 private function loadWholeFixtures()
 {
     $loader = new Loader();
     $loader->addFixture(new LoadItems());
     $purger = new ORMPurger($this->getEntityManager());
     $executor = new ORMExecutor($this->getEntityManager(), $purger);
     $executor->execute($loader->getFixtures());
 }
 /**
  * Load the given fixture
  *
  * @param \Doctrine\Common\DataFixtures\FixtureInterface $fixture
  */
 protected function loadFixture(FixtureInterface $fixture)
 {
     $loader = new Loader();
     $loader->addFixture($fixture);
     $purger = new ORMPurger();
     $executor = new ORMExecutor(static::$em, $purger);
     $executor->execute($loader->getFixtures());
 }
Esempio n. 20
0
 protected function loadFixtures()
 {
     $loader = new Loader();
     $loader->addFixture(new DataFixtures());
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->app['orm.em'], $purger);
     $executor->execute($loader->getFixtures());
 }
Esempio n. 21
0
 protected function loadFixtures()
 {
     $loader = new Loader();
     $loader->loadFromDirectory(__DIR__ . '/Fixtures');
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->entityManager, $purger);
     $executor->execute($loader->getFixtures());
 }
 protected function tearDown()
 {
     $loader = new Loader();
     $loader->loadFromFile('src/PadelTFG/GeneralBundle/DataFixtures/ORM/SponsorTest/SponsorTestRemove.php');
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->em, $purger);
     $executor->execute($loader->getFixtures(), true);
     $this->em->close();
 }
 /** @test */
 public function should_delete_expired_reminders()
 {
     $this->executor->execute($this->loader->getFixtures());
     $code = ReminderCode::fromNative('code+1');
     $email = new Email('*****@*****.**');
     $this->repository->deleteExpiredReminders();
     $reminder = $this->repository->findReminderByEmailAndCode($email, $code);
     $this->assertEquals(null, $reminder);
 }
Esempio n. 24
0
 /** @before */
 public function doLoadFixtures()
 {
     $loader = new Loader();
     foreach ($this->loadFixtures() as $fixture) {
         $loader->addFixture($fixture);
     }
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->em, $purger);
     $executor->execute($loader->getFixtures());
 }
Esempio n. 25
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $loader = new Loader();
     $executor = new ORMExecutor($this->em, new ORMPurger());
     $loader->loadFromDirectory($this->mainDir);
     foreach ($this->dirs as $dir) {
         $loader->loadFromDirectory($dir);
     }
     $executor->execute($loader->getFixtures(), true);
 }
Esempio n. 26
0
 public static function init()
 {
     $zf2ModulePaths = [dirname(dirname(__DIR__))];
     if ($path = static::findParentPath('vendor')) {
         $zf2ModulePaths[] = $path;
     }
     if ($path = static::findParentPath('module')) {
         $zf2ModulePaths[] = $path;
     }
     if (($path = static::findParentPath('src')) !== $zf2ModulePaths[0]) {
         $zf2ModulePaths[] = $path;
     }
     static::initAutoloader();
     $config = (include __DIR__ . '/../config/application.config.php');
     $serviceManager = new ServiceManager(new ServiceManagerConfig());
     $serviceManager->setService('ApplicationConfig', $config);
     $serviceManager->get('ModuleManager')->loadModules();
     static::$serviceManager = $serviceManager;
     if (defined("TEST_SUITE") && constant("TEST_SUITE") == 'full') {
         $entityManager = $serviceManager->get('doctrine.entitymanager.orm_default');
         //Validate the schema;
         $validator = new \Doctrine\ORM\Tools\SchemaValidator($entityManager);
         $errors = $validator->validateMapping();
         if (count($errors) > 0) {
             foreach ($errors as $entity => $errors) {
                 echo "Error in Entity: '" . $entity . "':\n";
                 echo implode("\n", $errors);
                 echo "\n";
             }
             die;
         }
         //Create the schema
         $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
         $mdFactory = $entityManager->getMetadataFactory();
         $mdFactory->getAllMetadata();
         $tool->dropDatabase();
         $tool->createSchema($mdFactory->getAllMetadata());
         $loader = new Loader();
         $loader->addFixture(new \ProjectTest\Fixture\LoadVersionData());
         $loader->addFixture(new \ContactTest\Fixture\LoadContactData());
         $loader->addFixture(new \ProjectTest\Fixture\LoadProjectLogoData());
         $loader->addFixture(new \ProjectTest\Fixture\LoadDocumentData());
         $loader->addFixture(new \ProjectTest\Fixture\LoadFundingStatusData());
         $loader->addFixture(new \ProjectTest\Fixture\LoadIdeaDocumentData());
         $loader->addFixture(new \ProjectTest\Fixture\LoadIdeaImageData());
         $loader->addFixture(new \ProjectTest\Fixture\LoadIdeaDescriptionData());
         $loader->addFixture(new \ProjectTest\Fixture\LoadInviteData());
         $loader->addFixture(new \ProjectTest\Fixture\LoadProjectRationaleData());
         $loader->addFixture(new \GeneralTest\Fixture\LoadWebInfoData());
         $loader->addFixture(new \OrganisationTest\Fixture\LoadOrganisationData());
         $purger = new ORMPurger();
         $executor = new ORMExecutor($entityManager, $purger);
         $executor->execute($loader->getFixtures());
     }
 }
 public function setUp()
 {
     parent::setUp();
     $this->createDb();
     $loader = new FixtureLoader();
     $loader->addFixture(new TestFixture());
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->getEntityManager(), $purger);
     $executor->execute($loader->getFixtures());
     $this->hydrator = new DoctrineEntityHydrator($this->getEntityManager());
 }
Esempio n. 28
0
 /**
  * Загружаем необходимые фикстуры перед выполнением сценария
  *
  * @BeforeScenario
  */
 public function beforeScen()
 {
     $loader = new Loader();
     $loader->addFixture(new \Application\Bundle\UserBundle\DataFixtures\ORM\LoadUserData());
     /** @var $em \Doctrine\ORM\EntityManager */
     $em = $this->kernel->getContainer()->get('doctrine')->getManager();
     $purger = new ORMPurger();
     $executor = new ORMExecutor($em, $purger);
     $executor->purge();
     $executor->execute($loader->getFixtures());
 }
Esempio n. 29
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $loader = new Loader();
     $loader->loadFromDirectory($this->mainDir);
     foreach ($this->dirs as $dir) {
         $loader->loadFromDirectory($dir);
     }
     foreach ($loader->getFixtures() as $fixtureName => $fixture) {
         $output->writeln($fixtureName);
     }
 }
 public function setUp()
 {
     parent::setUp();
     $this->createDb();
     $loader = new FixtureLoader();
     $loader->addFixture(new TestFixture());
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->getEntityManager(), $purger);
     $executor->execute($loader->getFixtures());
     $this->element = new DoctrineEntityElement('foo', array('object_manager' => $this->getEntityManager(), 'target_class' => 'DoctrineORMModuleTest\\Assets\\Entity\\Test'));
 }