/** * @see Command * * @throws \InvalidArgumentException When the target directory does not exist */ protected function execute(InputInterface $input, OutputInterface $output) { list($name, $defaultConfig) = $this->getConnection($input, $output); $fixtureDir = $input->getOption('dir') ? $input->getOption('dir') : $this->defaultFixturesDir; $path = realpath($this->getApplication()->getKernel()->getRootDir() . '/../') . '/' . $fixtureDir; if (!file_exists($path)) { $output->writeln("<info>The {$path} folder does not exists.</info>"); if ($this->askConfirmation($output, "<question>Do you want me to create it for you ?</question> [Yes]")) { $fs = new Filesystem(); $fs->mkdir($path); } else { throw new \IOException(sprintf('Unable to find the %s folder', $path)); } } $filename = $path . '/fixtures_' . time() . '.yml'; $dumper = new YamlDataDumper($this->getApplication()->getKernel()->getRootDir()); try { $dumper->dump($filename, $name); } catch (\Exception $e) { $this->writeSection($output, array('[Propel] Exception', '', $e->getMessage()), 'fg=white;bg=red'); return false; } $this->writeNewFile($output, $filename); return true; }
public function testYamlDump() { $author = new \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthor(); $author->setName('A famous one')->save($this->con); $complementary = new \stdClass(); $complementary->first_word_date = '2012-01-01'; $book = new \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\Book(); $book->setName('An important one')->setAuthorId(1)->setComplementaryInfos($complementary)->save($this->con); $filename = $this->getTempFile(); $loader = new YamlDataDumper(__DIR__ . '/../../Fixtures/DataFixtures/Loader'); $loader->dump($filename); $expected = <<<YAML Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\BookAuthor: BookAuthor_1: id: '1' name: 'A famous one' Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\Book: Book_1: id: '1' name: 'An important one' author_id: BookAuthor_1 complementary_infos: !!php/object:O:8:"stdClass":1:{s:15:"first_word_date";s:10:"2012-01-01";} YAML; $result = file_get_contents($filename); $this->assertEquals($expected, $result); }
/** * @see Command * * @throws \InvalidArgumentException When the target directory does not exist */ protected function execute(InputInterface $input, OutputInterface $output) { $this->writeSection($output, '[Propel] You are running the command: propel:fixtures:dump'); list($name, $defaultConfig) = $this->getConnection($input, $output); $path = realpath($this->getApplication()->getKernel()->getRootDir() . '/../') . '/' . $this->defaultFixturesDir; $filename = $path . '/fixtures_' . time() . '.yml'; $dumper = new YamlDataDumper($this->getApplication()->getKernel()->getRootDir()); try { $dumper->dump($filename, $name); } catch (\Exception $e) { $this->writeSection($output, array('[Propel] Exception', '', $e->getMessage()), 'fg=white;bg=red'); return false; } $output->writeln(''); $output->writeln(sprintf('>> <info>File+</info> %s', $filename)); return true; }
public function testYamlDump() { $author = new \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthor(); $author->setName('A famous one')->save($this->con); $book = new \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\Book(); $book->setName('An important one')->setAuthorId(1)->save($this->con); $filename = $this->getTempFile(); $loader = new YamlDataDumper(__DIR__ . '/../../Fixtures/DataFixtures/Loader'); $loader->dump($filename); $expected = <<<YAML Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\BookAuthor: BookAuthor_1: id: '1' name: 'A famous one' Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\Book: Book_1: id: '1' name: 'An important one' author_id: BookAuthor_1 YAML; $result = file_get_contents($filename); $this->assertEquals($expected, $result); }
public function transformArrayToData($array) { return parent::transformArrayToData($array); }