public function testXmlLoad() { $fixtures = <<<XML <Fixtures> <BookAuthor Namespace="Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader"> <BookAuthor_1 id="1" name="A famous one" /> </BookAuthor> <Book Namespace="Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader"> <Book_1 id="1" name="An important one" author_id="BookAuthor_1" /> </Book> </Fixtures> XML; $filename = $this->getTempFile($fixtures); $loader = new XmlDataLoader(__DIR__ . '/../../Fixtures/DataFixtures/Loader'); $loader->load(array($filename), 'default'); $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelect(new \Criteria(), $this->con); $this->assertCount(1, $books); $book = $books[0]; $this->assertInstanceOf('Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\BookAuthor', $book->getBookAuthor()); }
/** * Load fixtures * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @return void */ protected function loadFixtures(InputInterface $input, OutputInterface $output, $type = null) { if (null === $type) { return; } $datas = $this->getFixtureFiles($type); if (count(iterator_to_array($datas)) === 0) { return -1; } list($name, $defaultConfig) = $this->getConnection($input, $output); if ('yml' === $type) { $loader = new YamlDataLoader($this->getApplication()->getKernel()->getRootDir()); } elseif ('xml' === $type) { $loader = new XmlDataLoader($this->getApplication()->getKernel()->getRootDir()); } else { return; } try { $nb = $loader->load($datas, $name); } catch (\Exception $e) { $this->writeSection($output, array('[Propel] Exception', '', $e->getMessage()), 'fg=white;bg=red'); return false; } $this->writeSection($output, sprintf('<comment>%s</comment> %s fixtures file%s loaded.', $nb, strtoupper($type), $nb > 1 ? 's' : ''), 'fg=white;bg=black'); return true; }