/** * @param array $fixtures * @param $dropDatabaseBefore * * @return array */ protected function loadFixtures(array $fixtures, $dropDatabaseBefore = true) { if ($dropDatabaseBefore) { $this->fixtureManager->persist([], true); } $fixturesFiles = array_map([$this, 'getFixtureFile'], $fixtures); $objects = $this->fixtureManager->loadFiles($fixturesFiles); $this->fixtureManager->persist($objects); return $objects; }
/** * Issue 11 https://github.com/h4cc/AliceFixturesBundle/issues/11 * Load objects, but do not return the "local" ones, because these can not be persisted by doctrine. */ public function testLocalEntities() { // We need a real YAML Loader for this. $this->factoryMock->expects($this->any())->method('getLoader')->with('en_EN')->will($this->returnValue(new Loader())); $this->managerRegistryMock->expects($this->any())->method('getManagerForClass')->will($this->returnValue($this->objectManagerMock)); $objects = $this->manager->loadFiles(array(__DIR__ . '/../testdata/local_date.yml')); // The result should only contain the "group", not the "date". $this->assertEquals(array('group'), array_keys($objects)); $this->assertEquals("2000-01-01 00:00:00", $objects['group']->getCreationDate()->format('Y-m-d H:i:s')); }
/** * @param array $files * @param bool $doDrop */ public function load(array $files, $doDrop = true) { try { $this->em->getConnection()->beginTransaction(); $userProcessor = new UserProcessor(realpath(SystemUtil::getRootDir() . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR), $this->userService, $this->mimeTypeGuesser, $this->extensionGuesser); // Create Alice manager and fixture set $this->fixtureManager->addProcessor($userProcessor); $set = $this->fixtureManager->createFixtureSet(); // Add the fixture files foreach ($files as $file) { $set->addFile($file, 'yaml'); } $set->setDoDrop($doDrop); $set->setDoPersist(true); $set->setSeed(1337 + 42); // TODO Keep Module data intact $bundles = $this->em->getRepository("CampaignChain\\CoreBundle\\Entity\\Bundle")->findAll(); $modules = $this->em->getRepository("CampaignChain\\CoreBundle\\Entity\\Module")->findAll(); if ($this->fixtureManager->load($set)) { // TODO: Restore modules data foreach ($bundles as $bundle) { $this->em->persist($bundle); } foreach ($modules as $module) { $this->em->persist($module); } $this->em->flush(); $this->em->getConnection()->commit(); return true; } return false; } catch (\Exception $e) { $this->em->getConnection()->rollback(); $this->setException($e); return false; } }