Beispiel #1
0
 public function _failed(TestInterface $test, $fail)
 {
     if (!$this->client || !$this->client->getInternalResponse()) {
         return;
     }
     $this->_savePageSource(codecept_output_dir() . str_replace(['::', '\\', '/'], ['.', '.', '.'], Descriptor::getTestSignature($test)) . '.fail.html');
 }
Beispiel #2
0
 /**
  * @param \PHPUnit_Framework_Test $test
  * @param float $time
  */
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     $name = Descriptor::getTestAsString($test);
     $success = $this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
     if ($success) {
         $this->successful++;
     }
     if ($this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
         $status = "FAIL";
     } elseif ($this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED) {
         $status = 'Skipped';
     } elseif ($this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE) {
         $status = 'Incomplete';
     } elseif ($this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_ERROR) {
         $status = 'ERROR';
     } else {
         $status = 'Ok';
     }
     if (strlen($name) > 75) {
         $name = substr($name, 0, 70);
     }
     $line = $name . str_repeat('.', 75 - strlen($name));
     $line .= $status;
     $this->write($line . "\n");
 }
Beispiel #3
0
 /**
  * @group core
  */
 public function testCeptNamings()
 {
     $cept = new \Codeception\Test\Cept('Login', 'tests/acceptance/LoginCept.php');
     $this->assertEquals('tests/acceptance/LoginCept.php', \Codeception\Test\Descriptor::getTestFileName($cept));
     $this->assertEquals('tests/acceptance/LoginCept.php', \Codeception\Test\Descriptor::getTestFullName($cept));
     $this->assertEquals('LoginCept', \Codeception\Test\Descriptor::getTestSignature($cept));
 }
Beispiel #4
0
 public function groupsForTest(\PHPUnit_Framework_Test $test)
 {
     $groups = [];
     $filename = Descriptor::getTestFileName($test);
     if ($test instanceof TestInterface) {
         $groups = $test->getMetadata()->getGroups();
     }
     if ($test instanceof Reported) {
         $info = $test->getReportFields();
         if (isset($info['class'])) {
             $groups = array_merge($groups, \PHPUnit_Util_Test::getGroups($info['class'], $info['name']));
         }
         $filename = str_replace(['\\\\', '//'], ['\\', '/'], $info['file']);
     }
     if ($test instanceof \PHPUnit_Framework_TestCase) {
         $groups = array_merge($groups, \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName(false)));
     }
     foreach ($this->testsInGroups as $group => $tests) {
         foreach ($tests as $testPattern) {
             if ($filename == $testPattern) {
                 $groups[] = $group;
             }
             if (strpos($filename . ':' . $test->getName(false), $testPattern) === 0) {
                 $groups[] = $group;
             }
         }
     }
     return array_unique($groups);
 }
 public function endTest(PHPUnit_Framework_Test $test, $time)
 {
     $name = \Codeception\Test\Descriptor::getTestAsString($test);
     if ($this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
         $this->write('×');
     } else {
         if ($this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED) {
             $this->write('S');
         } else {
             if ($this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE) {
                 $this->write('I');
             } else {
                 if ($this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_ERROR) {
                     $this->write('E');
                 } else {
                     $this->write('✔');
                 }
             }
         }
     }
     if (strlen($name) > 75) {
         $name = substr($name, 0, 70);
     }
     $this->write(" {$name} \n");
 }
Beispiel #6
0
 public function beforeTest(TestEvent $e)
 {
     $this->logger = new \Monolog\Logger(Descriptor::getTestFileName($e->getTest()));
     $this->logger->pushHandler($this->logHandler);
     $this->logger->info('------------------------------------');
     $this->logger->info("STARTED: " . ucfirst(Descriptor::getTestAsString($e->getTest())));
 }
 public function testSuccess(TestEvent $event)
 {
     $test = $event->getTest();
     if (!$test instanceof TestInterface) {
         return;
     }
     $this->successfulTests[] = Descriptor::getTestSignature($test);
 }
 public function codeCoverageStart()
 {
     $codeCoverage = $this->getTestResultObject()->getCodeCoverage();
     if (!$codeCoverage) {
         return;
     }
     $codeCoverage->start(Descriptor::getTestSignature($this));
 }
Beispiel #9
0
 /**
  * @group core
  */
 public function testCestNamings()
 {
     $klass = new stdClass();
     $cest = new \Codeception\Test\Cest($klass, 'user', 'tests/acceptance/LoginCest.php');
     $this->assertEquals('tests/acceptance/LoginCest.php:user', \Codeception\Test\Descriptor::getTestFullName($cest));
     $this->assertEquals('tests/acceptance/LoginCest.php', \Codeception\Test\Descriptor::getTestFileName($cest));
     $this->assertEquals('stdClass:user', \Codeception\Test\Descriptor::getTestSignature($cest));
 }
 protected function getTestNames($tests)
 {
     $testNames = [];
     foreach ($tests as $test) {
         $testNames[] = \Codeception\Test\Descriptor::getTestSignature($test);
     }
     return $testNames;
 }
 public function _failed(TestInterface $test, $fail)
 {
     if (!$this->client || !$this->client->getInternalResponse()) {
         return;
     }
     $filename = preg_replace('~\\W~', '.', Descriptor::getTestSignature($test));
     $filename = mb_strcut($filename, 0, 244, 'utf-8') . '.fail.html';
     $this->_savePageSource(codecept_output_dir() . $filename);
 }
 public function after(TestEvent $e)
 {
     $seconds_input = $e->getTime();
     // stack overflow: http://stackoverflow.com/questions/16825240/how-to-convert-microtime-to-hhmmssuu
     $seconds = (int) ($milliseconds = (int) ($seconds_input * 1000)) / 1000;
     $time = $seconds % 60 . ($milliseconds === 0 ? '' : '.' . $milliseconds);
     $this->write(Descriptor::getTestSignature($e->getTest()));
     $this->writeln(' (' . $time . 's)');
 }
 public function afterTest(TestEvent $e)
 {
     $test = new \stdClass();
     $test->name = \Codeception\Test\Descriptor::getTestFileName($e->getTest());
     // stack overflow: http://stackoverflow.com/questions/16825240/how-to-convert-microtime-to-hhmmssuu
     $seconds_input = $e->getTime();
     $seconds = (int) ($milliseconds = (int) ($seconds_input * 1000)) / 1000;
     $time = $seconds % 60;
     $test->time = $time;
     self::$testTimes[] = $test;
 }
Beispiel #14
0
 protected function findMatchedTest($testSignature)
 {
     foreach ($this->tests as $test) {
         $signature = Descriptor::getTestSignature($test);
         if ($signature === $testSignature) {
             return $test;
         }
     }
     if ($test instanceof TestInterface) {
         $test->getMetadata()->setSkip("Dependent test for {$testSignature} not found");
     }
 }
Beispiel #15
0
 protected function enhancePhpunitTest(\PHPUnit_Framework_TestCase $test)
 {
     $className = get_class($test);
     $methodName = $test->getName(false);
     $dependencies = \PHPUnit_Util_Test::getDependencies($className, $methodName);
     $test->setDependencies($dependencies);
     if ($test instanceof UnitFormat) {
         $test->getMetadata()->setFilename(Descriptor::getTestFileName($test));
         $test->getMetadata()->setDependencies($dependencies);
         $test->getMetadata()->setEnv(Annotation::forMethod($test, $methodName)->fetchAll('env'));
     }
 }
 public function accept()
 {
     $test = $this->getInnerIterator()->current();
     if ($test instanceof \PHPUnit_Framework_TestSuite) {
         return true;
     }
     $name = Descriptor::getTestSignature($test);
     $accepted = preg_match($this->filter, $name, $matches);
     if ($accepted && isset($this->filterMax)) {
         $set = end($matches);
         $accepted = $set >= $this->filterMin && $set <= $this->filterMax;
     }
     return $accepted;
 }
Beispiel #17
0
 public function saveFailed(PrintResultEvent $e)
 {
     $file = $this->getLogDir() . $this->config['file'];
     $result = $e->getResult();
     if ($result->wasSuccessful()) {
         if (is_file($file)) {
             unlink($file);
         }
         return;
     }
     $output = [];
     foreach ($result->failures() as $fail) {
         $output[] = $this->localizePath(Descriptor::getTestFullName($fail->failedTest()));
     }
     foreach ($result->errors() as $fail) {
         $output[] = $this->localizePath(Descriptor::getTestFullName($fail->failedTest()));
     }
     file_put_contents($file, implode("\n", $output));
 }
 public function run()
 {
     if (!class_exists('\\Codeception\\Test\\Loader')) {
         throw new TaskException($this, "This task requires Codeception to be loaded. Please require autoload.php of Codeception");
     }
     $testLoader = new \Codeception\Test\Loader(['path' => $this->testsFrom]);
     $testLoader->loadTests($this->testsFrom);
     $tests = $testLoader->getTests();
     $i = 0;
     $groups = [];
     $this->printTaskInfo("Processing " . count($tests) . " tests");
     // splitting tests by groups
     foreach ($tests as $test) {
         $groups[$i % $this->numGroups + 1][] = \Codeception\Test\Descriptor::getTestFullName($test);
         $i++;
     }
     // saving group files
     foreach ($groups as $i => $tests) {
         $filename = $this->saveTo . $i;
         $this->printTaskInfo("Writing {$filename}");
         file_put_contents($filename, implode("\n", $tests));
     }
 }
 /**
  * @param \PHPUnit_Framework_SelfDescribing $test
  * @param bool $inProgress
  */
 protected function writeCurrentTest(\PHPUnit_Framework_SelfDescribing $test, $inProgress = true)
 {
     $prefix = ($this->output->isInteractive() and !$this->isDetailed($test) and $inProgress) ? '- ' : '';
     $testString = Descriptor::getTestAsString($test);
     $testString = preg_replace('~^([\\s\\w\\\\]+):\\s~', "<focus>\$1{$this->chars['of']}</focus> ", $testString);
     $this->message($testString)->prepend($prefix)->write();
 }
Beispiel #20
0
 protected function checkEnvironmentExists(TestInterface $test)
 {
     $envs = $test->getMetadata()->getEnv();
     if (empty($envs)) {
         return;
     }
     if (!isset($this->settings['env'])) {
         Notification::warning("Environments are not configured", Descriptor::getTestFullName($test));
         return;
     }
     $availableEnvironments = array_keys($this->settings['env']);
     $listedEnvironments = explode(',', implode(',', $envs));
     foreach ($listedEnvironments as $env) {
         if (!in_array($env, $availableEnvironments)) {
             Notification::warning("Environment {$env} was not configured but used in test", Descriptor::getTestFullName($test));
         }
     }
 }
Beispiel #21
0
 public function _failed(TestInterface $test, $fail)
 {
     $this->debugWebDriverLogs();
     $filename = str_replace([':', '\\', '/'], ['.', '', ''], Descriptor::getTestSignature($test)) . '.fail';
     $this->_saveScreenshot(codecept_output_dir() . $filename . '.png');
     $this->_savePageSource(codecept_output_dir() . $filename . '.html');
     $this->debug("Screenshot and page source were saved into '_output' dir");
 }
Beispiel #22
0
 /**
  * A failure occurred.
  *
  * @param \PHPUnit_Framework_Test                 $test
  * @param \PHPUnit_Framework_AssertionFailedError $e
  * @param float                                  $time
  */
 public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time)
 {
     $this->failures[Descriptor::getTestSignature($test)] = $this->cleanMessage($e);
     parent::addFailure($test, $e, $time);
 }
Beispiel #23
0
 /**
  * @param \PHPUnit_Framework_SelfDescribing $test
  * @param bool $inProgress
  */
 protected function writeCurrentTest(\PHPUnit_Framework_SelfDescribing $test, $inProgress = true)
 {
     $prefix = ($this->output->isInteractive() and !$this->isDetailed($test) and $inProgress) ? '- ' : '';
     $atMessage = $this->message(' ');
     $filename = basename(Descriptor::getTestFileName($test));
     if ($filename) {
         $atMessage = $atMessage->append($this->options['colors'] ? '' : 'at ')->append($filename);
     }
     $stripDataSet = function ($str) {
         return str_replace('with data set', "|", $str);
     };
     if (!$test instanceof Descriptive) {
         $title = $this->message(str_replace('::', ':', $test->toString()))->apply($stripDataSet);
         $atMessage->cut($this->width - 4 - strlen($title))->style('info');
         $this->message($title)->append($atMessage)->prepend($prefix)->write();
         return;
     }
     $feature = $test->getName(true);
     if ($test instanceof TestInterface and $test->getMetadata()->getFeature()) {
         $feature = $test->getMetadata()->getFeature();
     }
     $title = $this->message(ucfirst($feature))->apply($stripDataSet);
     $atMessage->cut($this->width - 4 - strlen($title))->style('info');
     $this->message($title)->prepend($prefix)->append($atMessage)->write();
 }
<!DOCTYPE html>
<html>
    <head>
        <title>VisualCeption Report</title>
    </head>
    <body>

        <img src="http://www.thewebhatesme.com/wp-content/uploads/visualception.png" />

        <?php 
foreach ($failedTests as $failedTest) {
    ?>
          <div class="failedTest">
            <h2><?php 
    $failedMetadata = $failedTest->getFailedTest()->getMetadata();
    echo \Codeception\Test\Descriptor::getTestSignature($failedTest->getFailedTest()) . " (" . $failedMetadata->getCurrent('env') . ")";
    ?>
</h2>
            <div class="deviationimage">
                Deviation Image <br />
                <img src='data:image/png;base64,<?php 
    echo base64_encode(file_get_contents($failedTest->getDeviationImage()));
    ?>
' />
            </div>

            <div class="expectedimage">
                Expected Image <br />
                <img src='data:image/png;base64,<?php 
    echo base64_encode(file_get_contents($failedTest->getExpectedImage()));
    ?>
Beispiel #25
0
 public function persist(TestEvent $e)
 {
     if (!$this->webDriverModule or !$this->dir) {
         return;
     }
     $indicatorHtml = '';
     $slideHtml = '';
     foreach ($this->slides as $i => $step) {
         $indicatorHtml .= (new Template($this->indicatorTemplate))->place('step', (int) $i)->place('isActive', (int) $i ? '' : 'class="active"')->produce();
         $slideHtml .= (new Template($this->slidesTemplate))->place('image', $i)->place('caption', $step->getHtml('#3498db'))->place('isActive', (int) $i ? '' : 'active')->place('isError', $step->hasFailed() ? 'error' : '')->produce();
     }
     $html = (new Template($this->template))->place('indicators', $indicatorHtml)->place('slides', $slideHtml)->place('feature', ucfirst($e->getTest()->getFeature()))->place('test', Descriptor::getTestSignature($e->getTest()))->place('carousel_class', $this->config['animate_slides'] ? ' slide' : '')->produce();
     $indexFile = $this->dir . DIRECTORY_SEPARATOR . 'index.html';
     file_put_contents($indexFile, $html);
     $testName = Descriptor::getTestSignature($e->getTest()) . ' - ' . ucfirst($e->getTest()->getFeature());
     $this->recordedTests[$testName] = substr($indexFile, strlen(codecept_output_dir()));
 }
Beispiel #26
0
 public function _failed(TestInterface $test, $fail)
 {
     $this->debugWebDriverLogs();
     $filename = preg_replace('~\\W~', '.', Descriptor::getTestSignature($test));
     $outputDir = codecept_output_dir();
     $this->_saveScreenshot($outputDir . mb_strcut($filename, 0, 245, 'utf-8') . '.fail.png');
     $this->_savePageSource($outputDir . mb_strcut($filename, 0, 244, 'utf-8') . '.fail.html');
     $this->debug("Screenshot and page source were saved into '{$outputDir}' dir");
 }