/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $file = $input->getArgument('file'); /* @var KernelInterface $kernel */ $kernel = $this->getContainer()->get('kernel'); $km = new KernelManipulator($kernel); $resp = $km->addCode($file); if ($resp) { $output->writeln(''); $output->writeln(implode('', array('<info>', 'Method "registerModuleBundles" has been successfully added to app/AppKernel.php!', '</info>'))); $output->writeln(''); } }
public function testAddCode() { $kernel = new DummyModulesAppKernel('test', true); $km = new KernelManipulator($kernel); $km->addCode($this->appBundlesFilename); // making it possible to load the same class twice by simply renaming it $contents = file_get_contents($this->kernelFilename); $contents = str_replace('DummyModulesAppKernel', 'PatchedDummyModulesAppKernel', $contents); file_put_contents($this->kernelFilename, $contents); require $this->kernelFilename; file_put_contents(__DIR__ . '/AppBundles.php', <<<CODE <?php return array( new \\Modera\\ModuleBundle\\Tests\\Unit\\Manipulator\\AnotherDummyBundle() ); CODE ); $patchedKernel = new PatchedDummyModulesAppKernel('test', true); $this->assertTrue(false !== array_search('registerModuleBundles', get_class_methods($patchedKernel))); $bundles = $patchedKernel->registerBundles(); $this->assertTrue(is_array($bundles)); $this->assertEquals(2, count($bundles)); $this->assertInstanceOf(DummyBundle::clazz(), $bundles[0]); $this->assertInstanceOf(AnotherDummyBundle::clazz(), $bundles[1]); }