/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $configuration = InputHandler::handleInput($input); $suiteList = TestSuiteLoader::loadSuite($configuration); if (!count($suiteList)) { $output->writeln('No tests found to validate.'); return 0; } $allValid = true; /** @var \PHPUnit_Framework_TestSuite $suite */ foreach ($suiteList as $suite) { $testClass = $suite->getName(); /** @var \PHPUnit_Framework_TestSuite $test */ foreach ($suite as $test) { $testMethod = $test->getName(); $isValid = Validator::isValidMethod($testClass, $testMethod); // Change exit code to 1 if invalid $allValid = $allValid && $isValid; $validityText = $isValid ? 'Valid' : 'Invalid'; $output->writeln($validityText . ' - ' . $testClass . '::' . $testMethod); } } // Return exit code 1 if any of the tags are invalid // otherwise return exit code 0 return (int) (!$allValid); }
/** * @covers ::handleInput */ public function testBootstrapInInputOverridesConfig() { $input = $this->prophesize('Symfony\\Component\\Console\\Input\\InputInterface'); $input->getOption('configuration')->shouldBeCalled()->willReturn('tests/Fixtures/configuration-bootstrap.xml'); $input->getOption('bootstrap')->shouldBeCalled()->willReturn('tests/Fixtures/bootstrap-2.php'); $this->assertFalse(class_exists('SomeNamespace\\NotAutoloaded\\AnotherClassThatNeedsBootstrap')); $config = InputHandler::handleInput($input->reveal()); $this->assertInstanceOf('PHPUnit_Util_Configuration', $config); $this->assertTrue(class_exists('SomeNamespace\\NotAutoloaded\\AnotherClassThatNeedsBootstrap')); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln($this->getApplication()->getLongVersion()); $configuration = InputHandler::handleInput($input); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { $output->writeln(PHP_EOL . sprintf('Configuration file loaded: %s', $configuration->getFilename())); } $suiteList = TestSuiteLoader::loadSuite($configuration); if (!count($suiteList)) { $output->writeln(PHP_EOL . 'No tests found to validate.'); return 0; } $failedCount = 0; $suiteIterator = new \RecursiveIteratorIterator($suiteList); /** @var \PHPUnit_Framework_TestCase $suite */ foreach ($suiteIterator as $suite) { if ($suite instanceof \PHPUnit_Framework_Warning) { continue; } $testClass = get_class($suite); $testMethod = $suite->getName(); $testSignature = $testClass . '::' . $testMethod; if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) { $this->writeValidity($output, 'Validating ' . $testSignature . '...'); } $isValid = Validator::isValidMethod($testClass, $testMethod); if (!$isValid) { $failedCount++; $this->writeValidity($output, $testSignature, false); } elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $this->writeValidity($output, $testSignature, true); } } $output->writeln(''); if ($failedCount > 0) { $output->writeln("There were {$failedCount} test(s) with invalid @covers tags."); return 1; } $output->writeln('Validation complete. All @covers tags are valid.'); return 0; }