/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('processing fixtures');
     $dirOrFile = $input->getOption('fixtures');
     if ($dirOrFile) {
         $dirOrFile = array($dirOrFile);
     } else {
         $dirOrFile = array();
         // application
         if (is_dir($dir = $this->getContainer()->getParameter('kernel.root_dir') . '/fixtures/mandango')) {
             $dirOrFile[] = $dir;
         }
         // bundles
         foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) {
             if (is_dir($dir = $bundle->getPath() . '/Resources/fixtures/mandango')) {
                 $dirOrFile[] = $dir;
             }
         }
     }
     $files = array();
     foreach ($dirOrFile as $dir) {
         if (is_file($dir)) {
             $files[] = $dir;
             continue;
         }
         if (is_dir($dir)) {
             $finder = new Finder();
             foreach ($finder->files()->name('*.yml')->followLinks()->in($dir) as $file) {
                 $files[] = $file;
             }
             continue;
         }
         throw new \InvalidArgumentException(sprintf('"%s" is not a dir or file.', $dir));
     }
     $data = array();
     foreach ($files as $file) {
         $data = Util::arrayDeepMerge($data, (array) Yaml::parse($file));
     }
     if (!$data) {
         $output->writeln('there are not fixtures');
         return;
     }
     $output->writeln('loading fixtures');
     $dataLoader = new DataLoader($this->getContainer()->get('mandango'));
     $dataLoader->load($data, $input->getOption('append'));
 }
예제 #2
0
 /**
  * @expectedException \RuntimeException
  */
 public function testLoadMandangoUnitOfWorkHasPending()
 {
     $author = $this->mandango->create('Model\\Author');
     $this->mandango->persist($author);
     $dataLoader = new DataLoader($this->mandango);
     $dataLoader->load(array('Model\\Author' => array('barbelith' => array('name' => 'Pedro'))));
 }