/** * @dataProvider getNonInteractiveCommandData */ public function testNonInteractiveCommand($options, $expected) { list($namespace, $bundleName, $dir, $format, $shared) = $expected; $bundle = new Bundle($namespace, $bundleName, $dir, $format, $shared); $container = $this->getContainer(); // not shared? the tests should be at the root of the project if (!$shared) { $bundle->setTestsDirectory($container->getParameter('kernel.root_dir') . '/../tests/' . $bundleName); } $generator = $this->getGenerator(); $generator->expects($this->once())->method('generateBundle')->with($bundle); $tester = new CommandTester($this->getCommand($generator, '', $container)); $tester->execute($options, array('interactive' => false)); }
/** * Creates the Bundle object based on the user's (non-interactive) input. * * @param InputInterface $input * * @return Bundle */ protected function createBundleObject(InputInterface $input) { foreach (array('namespace', 'dir') as $option) { if (null === $input->getOption($option)) { throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option)); } } $shared = $input->getOption('shared'); $namespace = Validators::validateBundleNamespace($input->getOption('namespace'), $shared); if (!($bundleName = $input->getOption('bundle-name'))) { $bundleName = strtr($namespace, array('\\' => '')); } $bundleName = Validators::validateBundleName($bundleName); $dir = $input->getOption('dir'); if (null === $input->getOption('format')) { $input->setOption('format', 'annotation'); } $format = Validators::validateFormat($input->getOption('format')); // an assumption that the kernel root dir is in a directory (like app/) $projectRootDirectory = $this->getContainer()->getParameter('kernel.root_dir') . '/..'; if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) { $dir = $projectRootDirectory . '/' . $dir; } // add trailing / if necessary $dir = '/' === substr($dir, -1, 1) ? $dir : $dir . '/'; $bundle = new Bundle($namespace, $bundleName, $dir, $format, $shared); // not shared - put the tests in the root if (!$shared) { $testsDir = $projectRootDirectory . '/tests/' . $bundleName; $bundle->setTestsDirectory($testsDir); } return $bundle; }
public function testAlternateTestsDirectory() { $bundle = new Bundle('Foo\\BarBundle', 'FooBarBundle', $this->tmpDir, 'xml', true); $bundle->setTestsDirectory($this->tmpDir . '/other/path/tests'); $this->getGenerator()->generateBundle($bundle); $this->assertTrue(file_exists($this->tmpDir . '/other/path/tests/Controller/DefaultControllerTest.php')); }