コード例 #1
0
 /**
  * Validate code examples in $file
  *
  * @param  \SplFileObject $file
  * @param  string         $formatIdentifier
  * @return void
  */
 public function assertFile(\SplFileObject $file, $formatIdentifier = '')
 {
     $format = $this->formatFactory->createFormat($formatIdentifier ?: $file->getExtension());
     $result = $this->testCase->getTestResultObject();
     foreach ($this->tester->test($file, $format) as $example => $returnObj) {
         $this->testCase->addToAssertionCount(1);
         if ($returnObj->isFailure()) {
             $result->addFailure($this->testCase, new \PHPUnit_Framework_AssertionFailedError("Example {$example}: {$returnObj->getMessage()}"), 0.0);
         }
     }
 }
コード例 #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $tester = new readmetester\ReadmeTester();
     $exitStatus = 0;
     foreach ($input->getArgument('filename') as $filename) {
         $file = new SplFileObject($filename);
         $output->writeln("Testing examples in <comment>{$file->getRealPath()}</comment>");
         $format = $this->createFormat($input, $file);
         $output->writeln("Using format <comment>{$format->getName()}</comment>");
         foreach ($tester->test($file, $format) as $example => $returnObj) {
             if ($returnObj->isSuccess()) {
                 $output->writeln(" <info>Example {$example}: {$returnObj->getMessage()} </info>");
                 continue;
             }
             $output->writeln(" <error>Example {$example}: {$returnObj->getMessage()} </error>");
             $exitStatus = 1;
         }
     }
     return $exitStatus;
 }