/** * @see FixturesExportCommand::execute */ public function testExecute_SpecificEntity_Association() { $directoryPath = sys_get_temp_dir(); $dumper = $this->getMockBuilder('\\Cosma\\Bundle\\TestingBundle\\Fixture\\Dumper')->disableOriginalConstructor()->setMethods(['dumpToYaml', 'setAssociation', 'setClassMetadataInfo'])->getMock(); $dumper->expects($this->once())->method('dumpToYaml')->with($directoryPath)->will($this->returnValue($directoryPath . '/table.yml')); $dumper->expects($this->once())->method('setAssociation')->with(true)->will($this->returnValue(null)); $classMetaDataInfo = $this->getMockBuilder('\\Doctrine\\ORM\\Mapping\\ClassMetadataInfo')->disableOriginalConstructor()->getMock(); $dumper->expects($this->once())->method('setClassMetadataInfo')->with($classMetaDataInfo)->will($this->returnValue(null)); $metaDataFactory = $this->getMockBuilder('\\Doctrine\\Common\\Persistence\\Mapping\\ClassMetadataFactory')->disableOriginalConstructor()->setMethods(['getMetadataFor'])->getMockForAbstractClass(); $metaDataFactory->expects($this->once())->method('getMetadataFor')->with('BundleName:EntityName')->will($this->returnValue($classMetaDataInfo)); $entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->setMethods(['getMetadataFactory'])->getMock(); $entityManager->expects($this->once())->method('getMetadataFactory')->will($this->returnValue($metaDataFactory)); $doctrine = $this->getMockBuilder('\\Doctrine\\Bundle\\DoctrineBundle\\Registry')->disableOriginalConstructor()->setMethods(['getManager'])->getMock(); $doctrine->expects($this->once())->method('getManager')->will($this->returnValue($entityManager)); $container = new Container(); $container->set('doctrine', $doctrine); $container->set('cosma_testing.fixture_dumper', $dumper); $command = $this->getMockBuilder('\\Cosma\\Bundle\\TestingBundle\\Command\\FixturesExportCommand')->disableOriginalConstructor()->setMethods(['getContainer'])->getMock(); $command->expects($this->exactly(2))->method('getContainer')->will($this->returnValue($container)); $reflectionClass = new \ReflectionClass($command); $dumperProperty = $reflectionClass->getParentClass()->getProperty('dumper'); $dumperProperty->setAccessible(true); $dumperProperty->setValue($command, $dumper); $inputDefinition = new InputDefinition([new InputArgument('dumpDirectory', InputArgument::REQUIRED), new InputArgument('entity', InputArgument::OPTIONAL), new InputOption('associations', 'a', InputOption::VALUE_NONE)]); $input = new ArgvInput(['dummySoInputValidates' => 'dummy', 'dumpDirectory' => $directoryPath, 'entity' => 'BundleName:EntityName'], $inputDefinition); $input->setOption('associations', true); $output = new BufferedOutput(); $reflectionClass = new \ReflectionClass($command); $executeMethod = $reflectionClass->getMethod('execute'); $executeMethod->setAccessible(true); $executeMethod->invoke($command, $input, $output); $this->assertContains("successfully dumped in file {$directoryPath}/table.yml", $output->fetch(), 'The entity was not dump successfully'); }
/** * Do the locateFile Action * * @param $arg * @param $dir * @return string */ protected function runLocateFile($arg, $dir) { chdir($this->baseDir . '/' . $dir); $definition = new InputDefinition(array(new InputOption('configuration'))); $input = new ArgvInput(array(), $definition); if ($arg) { $input->setOption('configuration', $arg); } $command = new VoidCommand('void'); return $command->locateConfigFile($input); }
/** * Handles the brood default options/arguments. */ public static final function ArgvInput() { # get the raw commands $raws = ['--env', '--timeout']; # get the options from Brood $options = [Brood::environmentOption(), Brood::timeoutOption()]; $instances = []; $reflect = new ReflectionClass(InputOption::class); foreach ($options as $opt) { $instances[] = $reflect->newInstanceArgs($opt); } # still, listen to the php $_SERVER['argv'] $cmd_input = new ArgvInput(); # get the default brood options $brood_input = new ArgvInput($raws, new InputDefinition($instances)); foreach ($raws as $raw) { if ($cmd_input->hasParameterOption([$raw])) { $val = $cmd_input->getParameterOption($raw); $val = is_numeric($val) ? (int) $val : $val; $brood_input->setOption(str_replace('-', '', $raw), $val); } } return $brood_input; }