Пример #1
0
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     if ($this->coverage) {
         $this->coverage->stop();
     }
     return;
 }
Пример #2
0
 public function testPrintReport()
 {
     if (file_exists($file = CodeCoverageSession::getCacheFile())) {
         unlink($file);
     }
     $options = array('enabled' => true, 'output.text' => true, 'output.html' => getcwd(), 'output.clover' => getcwd() . '/clover.xml');
     static::$container->setParameter('session.results', array('some'));
     $runner = new CodeCoverageSession();
     $runner->setOptions($options);
     $runner->setContainer(static::$container);
     $event = new ProcessEvent(static::$container->get('plugins.test'));
     $genericEvent = new GenericEvent(static::$container);
     $genericEvent->addProcessEvent($event);
     // not display coverage when results file not exists
     $runner->process($genericEvent);
     $this->assertNotDisplayContains('html output');
     $this->assertNotDisplayContains('text output');
     $this->assertNotDisplayContains('clover output');
     // display coverage when cache file exists
     Filesystem::create()->serialize($file, $runner);
     $runner->process($genericEvent);
     $this->assertDisplayContains('html output');
     $this->assertDisplayContains('text output');
     $this->assertDisplayContains('clover output');
 }
Пример #3
0
 public function afterExample(ExampleEvent $event)
 {
     $type = $this->map[$event->getResult()];
     $this->addResult($type, $event->getSpecification(), $event->getTitle());
     if ($this->coverage) {
         $this->coverage->stop();
     }
 }
Пример #4
0
 protected function loadConfigurationFile(InputInterface $input, ServiceContainer $container)
 {
     $container->setShared('event_dispatcher.listeners.phpguard', function ($c) {
         $ext = new PhpGuardExtension();
         if ($runner = CodeCoverageSession::getCached()) {
             $ext->setCoverageRunner($runner);
         }
         $ext->load($c);
         return $ext;
     });
     parent::loadConfigurationFile($input, $container);
 }
Пример #5
0
 /**
  * @codeCoverageIgnore
  */
 public function handleShutdown()
 {
     $fatalErrors = array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR);
     $lastError = error_get_last();
     if ($lastError && in_array($lastError['type'], $fatalErrors)) {
         $message = 'Fatal Error ' . $lastError['message'];
         $error = $lastError;
         $trace = file($this->errorFile);
         $traces = array();
         for ($i = 0, $count = count($trace); $i < $count; $i++) {
             $text = trim($trace[$i]);
             if (false !== ($pos = strpos($text, 'PHP '))) {
                 $text = substr($text, $pos + 4);
             }
             $traces[] = $text;
         }
         $event = ResultEvent::createError($message, $error, null, $traces);
         Filesystem::create()->serialize(Inspector::getResultFileName(), array($event));
         if ($this->coverageRunner) {
             $this->coverageRunner->saveState();
         }
     }
 }
Пример #6
0
 function it_should_stop_coverage_when_test_ended(\PhpGuard\Application\Bridge\CodeCoverage\CodeCoverageSession $coverageRunner, MockTestCase $test)
 {
     $coverageRunner->stop()->shouldBeCalled();
     $this->endTest($test, 0);
 }
Пример #7
0
 public function __construct(CodeCoverageSession $coverageSession = null)
 {
     parent::__construct('PhpGuard-Behat');
     $this->coverageSession = CodeCoverageSession::getCached();
 }
Пример #8
0
 private function stopCoverage()
 {
     if ($this->coverageSession) {
         $this->coverageSession->stop();
     }
 }
 function it_should_save_coverage_sessions(\PhpGuard\Application\Bridge\CodeCoverage\CodeCoverageSession $coverageSession)
 {
     $coverageSession->saveState()->shouldBeCalled();
     $this->afterSuite();
 }
Пример #10
0
 public function setupServices(ContainerInterface $container)
 {
     $container->setShared('config', function () {
         return new Processor();
     });
     $container->setShared('dispatcher', function ($c) {
         $dispatcher = new EventDispatcher();
         array_map(array($dispatcher, 'addSubscriber'), $c->getByPrefix('dispatcher.listeners'));
         return $dispatcher;
     });
     $container->setShared('logger.handler', function ($c) {
         $format = "%start_tag%[%datetime%][%channel%][%level_name%] %message% %context% %extra% %end_tag%\n";
         $formatter = new ConsoleFormatter($format);
         $handler = new ConsoleHandler(null, true);
         $handler->setFormatter($formatter);
         return $handler;
     });
     $container->setShared('logger', function ($c) {
         $logger = new Logger('Main');
         $logger->pushHandler($c->get('logger.handler'));
         return $logger;
     });
     $container->setShared('listen.listener', function ($c) {
         $listener = Listen::to(getcwd());
         $options = $c->get('phpguard')->getOptions();
         foreach ($options['ignores'] as $ignored) {
             $listener->ignores($ignored);
         }
         $phpguard = $c->get('phpguard');
         $listener->latency($options['latency']);
         $listener->callback(array($phpguard, 'listen'));
         return $listener;
     });
     $container->setShared('listen.adapter', function () {
         $adapter = Listen::getDefaultAdapter();
         return $adapter;
     });
     $container->setShared('locator', function () {
         $locator = new Locator();
         return $locator;
     });
     $container->setShared('dispatcher.listeners.locator', function ($c) {
         return $c->get('locator');
     });
     $container->setShared('runner.logger', function ($c) {
         $logger = new Logger('Runner');
         $logger->pushHandler($c->get('logger.handler'));
         return $logger;
     });
     $container->setShared('runner', function () {
         return new Runner();
     });
     $container->setShared('filesystem', function () {
         return new Filesystem();
     });
     CodeCoverageSession::setupContainer($container);
 }
 function it_should_save_coverage_session_on_afterSuite_event(CodeCoverageSession $coverageSession)
 {
     $coverageSession->saveState()->shouldBeCalled();
     $this->afterSuite();
 }