PK bq[NR#5 5 .travis.ymlnu W+A language: php
env:
CODECEPTION_VERSION: '2.6.x-dev'
php:
- 7.2
- 7.3
before_script:
- wget https://robo.li/robo.phar
- php robo.phar prepare
- composer update
script:
- php robo.phar test cli
- php robo.phar test "unit -g core"
- php robo.phar test "tests/unit/Codeception/Constraints/"
PK bq[N3Yx README.mdnu W+A # PHPUnit Wrapper
Builds:
* 6.0 [![Build Status](https://travis-ci.org/Codeception/phpunit-wrapper.svg?branch=6.0)](https://travis-ci.org/Codeception/phpunit-wrapper)
* 7.0 [![Build Status](https://travis-ci.org/Codeception/phpunit-wrapper.svg?branch=7.0)](https://travis-ci.org/Codeception/phpunit-wrapper)
Codeception heavily relies on PHPUnit for running and managing tests.
Not all PHPUnit classes fit the needs of Codeception, that's why they were extended or redefined.
Releases follow major PHPUnit versions.
PK bq[NߤeX
.gitignorenu W+A .idea
composer.lock
vendorPK bq[NY(? ? RoboFile.phpnu W+A '*'];
file_put_contents(__DIR__ . '/composer.json', json_encode($config));
}
public function test($params)
{
return $this->taskExec(__DIR__ . '/vendor/bin/codecept run ' . $params)
->dir(__DIR__ .'/vendor/codeception/codeception')
->run();
}
}PK bq[N* src/phpunit7-interfaces.phpnu W+A false,
'phpunit-xml' => false,
'html' => false,
'tap' => false,
'json' => false,
'report' => false
];
protected $config = [];
protected $logDir = null;
public function __construct()
{
$this->config = Configuration::config();
$this->logDir = Configuration::outputDir(); // prepare log dir
$this->phpUnitOverriders();
parent::__construct();
}
public function phpUnitOverriders()
{
require_once __DIR__ . DIRECTORY_SEPARATOR . 'Overrides/Filter.php';
}
/**
* @return null|\PHPUnit\TextUI\ResultPrinter
*/
public function getPrinter()
{
return $this->printer;
}
public function prepareSuite(\PHPUnit\Framework\Test $suite, array &$arguments)
{
$this->handleConfiguration($arguments);
$filterAdded = false;
$filterFactory = new \PHPUnit\Runner\Filter\Factory();
if ($arguments['groups']) {
$filterAdded = true;
$filterFactory->addFilter(
new \ReflectionClass('PHPUnit\Runner\Filter\IncludeGroupFilterIterator'),
$arguments['groups']
);
}
if ($arguments['excludeGroups']) {
$filterAdded = true;
$filterFactory->addFilter(
new \ReflectionClass('PHPUnit\Runner\Filter\ExcludeGroupFilterIterator'),
$arguments['excludeGroups']
);
}
if ($arguments['filter']) {
$filterAdded = true;
$filterFactory->addFilter(
new \ReflectionClass('Codeception\PHPUnit\FilterTest'),
$arguments['filter']
);
}
if ($filterAdded) {
$suite->injectFilter($filterFactory);
}
}
public function doEnhancedRun(
\PHPUnit\Framework\Test $suite,
\PHPUnit\Framework\TestResult $result,
array $arguments = []
) {
unset($GLOBALS['app']); // hook for not to serialize globals
$result->convertErrorsToExceptions(false);
if (isset($arguments['report_useless_tests'])) {
$result->beStrictAboutTestsThatDoNotTestAnything((bool)$arguments['report_useless_tests']);
}
if (isset($arguments['disallow_test_output'])) {
$result->beStrictAboutOutputDuringTests((bool)$arguments['disallow_test_output']);
}
if (empty(self::$persistentListeners)) {
$this->applyReporters($result, $arguments);
}
if (class_exists('\Symfony\Bridge\PhpUnit\SymfonyTestsListener')) {
$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : [];
$listener = new \Symfony\Bridge\PhpUnit\SymfonyTestsListener();
$listener->globalListenerDisabled();
$arguments['listeners'][] = $listener;
}
$arguments['listeners'][] = $this->printer;
// clean up listeners between suites
foreach ($arguments['listeners'] as $listener) {
$result->addListener($listener);
}
$suite->run($result);
unset($suite);
foreach ($arguments['listeners'] as $listener) {
$result->removeListener($listener);
}
return $result;
}
/**
* @param \PHPUnit\Framework\TestResult $result
* @param array $arguments
*
* @return array
*/
protected function applyReporters(\PHPUnit\Framework\TestResult $result, array $arguments)
{
foreach ($this->defaultListeners as $listener => $value) {
if (!isset($arguments[$listener])) {
$arguments[$listener] = $value;
}
}
if ($arguments['report']) {
self::$persistentListeners[] = $this->instantiateReporter('report');
}
if ($arguments['html']) {
codecept_debug('Printing HTML report into ' . $arguments['html']);
self::$persistentListeners[] = $this->instantiateReporter(
'html',
[$this->absolutePath($arguments['html'])]
);
}
if ($arguments['xml']) {
codecept_debug('Printing JUNIT report into ' . $arguments['xml']);
self::$persistentListeners[] = $this->instantiateReporter(
'xml',
[$this->absolutePath($arguments['xml']), (bool)$arguments['log_incomplete_skipped']]
);
}
if ($arguments['phpunit-xml']) {
codecept_debug('Printing PHPUNIT report into ' . $arguments['phpunit-xml']);
self::$persistentListeners[] = $this->instantiateReporter(
'phpunit-xml',
[$this->absolutePath($arguments['phpunit-xml']), (bool)$arguments['log_incomplete_skipped']]
);
}
if ($arguments['tap']) {
codecept_debug('Printing TAP report into ' . $arguments['tap']);
self::$persistentListeners[] = $this->instantiateReporter('tap', [$this->absolutePath($arguments['tap'])]);
}
if ($arguments['json']) {
codecept_debug('Printing JSON report into ' . $arguments['json']);
self::$persistentListeners[] = $this->instantiateReporter(
'json',
[$this->absolutePath($arguments['json'])]
);
}
foreach (self::$persistentListeners as $listener) {
if ($listener instanceof ConsolePrinter) {
$this->printer = $listener;
continue;
}
$result->addListener($listener);
}
}
protected function instantiateReporter($name, $args = [])
{
if (!isset($this->config['reporters'][$name])) {
throw new ConfigurationException("Reporter $name not defined");
}
return (new \ReflectionClass($this->config['reporters'][$name]))->newInstanceArgs($args);
}
private function absolutePath($path)
{
if ((strpos($path, '/') === 0) or (strpos($path, ':') === 1)) { // absolute path
return $path;
}
return $this->logDir . $path;
}
}
PK bq[N97MPv v src/ConsolePrinter.phpnu W+A testStatus = \PHPUnit\Runner\BaseTestRunner::STATUS_ERROR;
$this->failed++;
}
/**
* 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, float $time) : void
{
$this->testStatus = \PHPUnit\Runner\BaseTestRunner::STATUS_FAILURE;
$this->failed++;
}
/**
* A warning occurred.
*
* @param \PHPUnit\Framework\Test $test
* @param \PHPUnit\Framework\Warning $e
* @param float $time
*/
public function addWarning(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, float $time): void
{
$this->testStatus = \PHPUnit\Runner\BaseTestRunner::STATUS_WARNING;
$this->warned++;
}
/**
* Incomplete test.
*
* @param \PHPUnit\Framework\Test $test
* @param \Throwable $e
* @param float $time
*/
public function addIncompleteTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time) : void
{
$this->testStatus = \PHPUnit\Runner\BaseTestRunner::STATUS_INCOMPLETE;
$this->incomplete++;
}
/**
* Risky test.
*
* @param \PHPUnit\Framework\Test $test
* @param \Throwable $e
* @param float $time
*
* @since Method available since Release 4.0.0
*/
public function addRiskyTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time) : void
{
$this->testStatus = \PHPUnit\Runner\BaseTestRunner::STATUS_RISKY;
$this->risky++;
}
/**
* Skipped test.
*
* @param \PHPUnit\Framework\Test $test
* @param \Throwable $e
* @param float $time
*
* @since Method available since Release 3.0.0
*/
public function addSkippedTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time) : void
{
$this->testStatus = \PHPUnit\Runner\BaseTestRunner::STATUS_SKIPPED;
$this->skipped++;
}
public function startTest(\PHPUnit\Framework\Test $test) : void
{
$this->testStatus = \PHPUnit\Runner\BaseTestRunner::STATUS_PASSED;
}
}
PK bq[N\I^9 9 src/Listener.phpnu W+A dispatcher = $dispatcher;
}
/**
* Risky test.
*
* @param PHPUnit\Framework\Test $test
* @param \Throwable $e
* @param float $time
* @since Method available since Release 4.0.0
*/
public function addRiskyTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time) : void
{
}
public function addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\AssertionFailedError $e, float $time) : void
{
$this->unsuccessfulTests[] = spl_object_hash($test);
$this->fire(Events::TEST_FAIL, new FailEvent($test, $time, $e));
}
public function addError(\PHPUnit\Framework\Test $test, \Throwable $e, float $time) : void
{
$this->unsuccessfulTests[] = spl_object_hash($test);
$this->fire(Events::TEST_ERROR, new FailEvent($test, $time, $e));
}
// This method was added in PHPUnit 6
public function addWarning(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, float $time) : void
{
$this->unsuccessfulTests[] = spl_object_hash($test);
$this->fire(Events::TEST_WARNING, new FailEvent($test, $time, $e));
}
public function addIncompleteTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time) : void
{
if (in_array(spl_object_hash($test), $this->skippedTests)) {
return;
}
$this->unsuccessfulTests[] = spl_object_hash($test);
$this->fire(Events::TEST_INCOMPLETE, new FailEvent($test, $time, $e));
$this->skippedTests[] = spl_object_hash($test);
}
public function addSkippedTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time) : void
{
if (in_array(spl_object_hash($test), $this->skippedTests)) {
return;
}
$this->unsuccessfulTests[] = spl_object_hash($test);
$this->fire(Events::TEST_SKIPPED, new FailEvent($test, $time, $e));
$this->skippedTests[] = spl_object_hash($test);
}
public function startTestSuite(\PHPUnit\Framework\TestSuite $suite) : void
{
$this->dispatcher->dispatch('suite.start', new SuiteEvent($suite));
}
public function endTestSuite(\PHPUnit\Framework\TestSuite $suite) : void
{
$this->dispatcher->dispatch('suite.end', new SuiteEvent($suite));
}
public function startTest(\PHPUnit\Framework\Test $test) : void
{
$this->dispatcher->dispatch(Events::TEST_START, new TestEvent($test));
if (!$test instanceof TestInterface) {
return;
}
if ($test->getMetadata()->isBlocked()) {
return;
}
try {
$this->startedTests[] = spl_object_hash($test);
$this->fire(Events::TEST_BEFORE, new TestEvent($test));
} catch (\PHPUnit\Framework\IncompleteTestError $e) {
$test->getTestResultObject()->addFailure($test, $e, 0);
} catch (\PHPUnit\Framework\SkippedTestError $e) {
$test->getTestResultObject()->addFailure($test, $e, 0);
} catch (\Throwable $e) {
$test->getTestResultObject()->addError($test, $e, 0);
}
}
public function endTest(\PHPUnit\Framework\Test $test, float $time) : void
{
$hash = spl_object_hash($test);
if (!in_array($hash, $this->unsuccessfulTests)) {
$this->fire(Events::TEST_SUCCESS, new TestEvent($test, $time));
}
if (in_array($hash, $this->startedTests)) {
$this->fire(Events::TEST_AFTER, new TestEvent($test, $time));
}
$this->dispatcher->dispatch(Events::TEST_END, new TestEvent($test, $time));
}
protected function fire($event, TestEvent $eventType)
{
$test = $eventType->getTest();
if ($test instanceof TestInterface) {
foreach ($test->getMetadata()->getGroups() as $group) {
$this->dispatcher->dispatch($event . '.' . $group, $eventType);
}
}
$this->dispatcher->dispatch($event, $eventType);
}
}
PK bq[NzK K src/Constraint/CrawlerNot.phpnu W+A string) {
throw new \PHPUnit\Framework\ExpectationFailedException(
"Element '$selector' was found",
$comparisonFailure
);
}
/** @var $nodes DomCrawler * */
$output = "There was '$selector' element";
$output .= $this->uriMessage('on page');
$output .= $this->nodesList($nodes, $this->string);
$output .= "\ncontaining '{$this->string}'";
throw new \PHPUnit\Framework\ExpectationFailedException(
$output,
$comparisonFailure
);
}
public function toString() : string
{
if ($this->string) {
return 'that contains text "' . $this->string . '"';
}
}
}
PK bq[NcL src/Constraint/JsonContains.phpnu W+A expected = $expected;
}
/**
* Evaluates the constraint for parameter $other. Returns true if the
* constraint is met, false otherwise.
*
* @param mixed $other Value or object to evaluate.
*
* @return bool
*/
protected function matches($other) : bool
{
$jsonResponseArray = new JsonArray($other);
if (!is_array($jsonResponseArray->toArray())) {
throw new \PHPUnit\Framework\AssertionFailedError('JSON response is not an array: ' . $other);
}
if ($jsonResponseArray->containsArray($this->expected)) {
return true;
}
$comparator = new ArrayComparator();
$comparator->setFactory(new Factory);
try {
$comparator->assertEquals($this->expected, $jsonResponseArray->toArray());
} catch (ComparisonFailure $failure) {
throw new \PHPUnit\Framework\ExpectationFailedException(
"Response JSON does not contain the provided JSON\n",
$failure
);
}
return false;
}
/**
* Returns a string representation of the constraint.
*
* @return string
*/
public function toString() : string
{
//unused
return '';
}
protected function failureDescription($other) : string
{
//unused
return '';
}
}
PK bq[N,1 1 src/Constraint/Crawler.phpnu W+A count()) {
return false;
}
if ($this->string === '') {
return true;
}
foreach ($nodes as $node) {
if (parent::matches($node->nodeValue)) {
return true;
}
}
return false;
}
protected function fail($nodes, $selector, ComparisonFailure $comparisonFailure = null):void
{
/** @var $nodes DomCrawler * */
if (!$nodes->count()) {
throw new ElementNotFound($selector, 'Element located either by name, CSS or XPath');
}
$output = "Failed asserting that any element by '$selector'";
$output .= $this->uriMessage('on page');
$output .= " ";
if ($nodes->count() < 10) {
$output .= $this->nodesList($nodes);
} else {
$message = new Message("[total %s elements]");
$output .= $message->with($nodes->count())->getMessage();
}
$output .= "\ncontains text '{$this->string}'";
throw new \PHPUnit\Framework\ExpectationFailedException(
$output,
$comparisonFailure
);
}
protected function failureDescription($other) : string
{
$desc = '';
foreach ($other as $o) {
$desc .= parent::failureDescription($o->textContent);
}
return $desc;
}
protected function nodesList(DomCrawler $nodes, $contains = null)
{
$output = "";
foreach ($nodes as $node) {
if ($contains && strpos($node->nodeValue, $contains) === false) {
continue;
}
$output .= "\n+ " . $node->C14N();
}
return $output;
}
}
PK bq[N src/Constraint/JsonType.phpnu W+A jsonType = $jsonType;
$this->match = $match;
}
/**
* Evaluates the constraint for parameter $other. Returns true if the
* constraint is met, false otherwise.
*
* @param mixed $jsonArray Value or object to evaluate.
*
* @return bool
*/
protected function matches($jsonArray) : bool
{
if ($jsonArray instanceof JsonArray) {
$jsonArray = $jsonArray->toArray();
}
$matched = (new JsonTypeUtil($jsonArray))->matches($this->jsonType);
if ($this->match) {
if ($matched !== true) {
throw new \PHPUnit\Framework\ExpectationFailedException($matched);
}
} else {
if ($matched === true) {
throw new \PHPUnit\Framework\ExpectationFailedException('Unexpectedly response matched: ' . json_encode($jsonArray));
}
}
return true;
}
/**
* Returns a string representation of the constraint.
*
* @return string
*/
public function toString() : string
{
//unused
return '';
}
protected function failureDescription($other) : string
{
//unused
return '';
}
}
PK bq[Nۄ src/Constraint/WebDriver.phpnu W+A string === '') {
return true;
}
foreach ($nodes as $node) {
/** @var $node \WebDriverElement * */
if (!$node->isDisplayed()) {
continue;
}
if (parent::matches(htmlspecialchars_decode($node->getText()))) {
return true;
}
}
return false;
}
protected function fail($nodes, $selector, ComparisonFailure $comparisonFailure = null) : void
{
if (!count($nodes)) {
throw new ElementNotFound($selector, 'Element located either by name, CSS or XPath');
}
$output = "Failed asserting that any element by " . Locator::humanReadableString($selector);
$output .= $this->uriMessage('on page');
if (count($nodes) < 5) {
$output .= "\nElements: ";
$output .= $this->nodesList($nodes);
} else {
$message = new Message("[total %s elements]");
$output .= $message->with(count($nodes));
}
$output .= "\ncontains text '" . $this->string . "'";
throw new \PHPUnit\Framework\ExpectationFailedException(
$output,
$comparisonFailure
);
}
protected function failureDescription($nodes) : string
{
$desc = '';
foreach ($nodes as $node) {
$desc .= parent::failureDescription($node->getText());
}
return $desc;
}
protected function nodesList($nodes, $contains = null)
{
$output = "";
foreach ($nodes as $node) {
if ($contains && strpos($node->getText(), $contains) === false) {
continue;
}
/** @var $node \WebDriverElement * */
$message = new Message("\n+ <%s> %s");
$output .= $message->with($node->getTagName(), $node->getText());
}
return $output;
}
}
PK bq[N/ src/Constraint/Page.phpnu W+A string = $this->normalizeText((string)$string);
$this->uri = $uri;
}
/**
* Evaluates the constraint for parameter $other. Returns true if the
* constraint is met, false otherwise.
*
* @param mixed $other Value or object to evaluate.
*
* @return bool
*/
protected function matches($other) : bool
{
$other = $this->normalizeText($other);
return mb_stripos($other, $this->string, null, 'UTF-8') !== false;
}
/**
* @param $text
* @return string
*/
private function normalizeText($text)
{
$text = strtr($text, "\r\n", " ");
return trim(preg_replace('/\\s{2,}/', ' ', $text));
}
/**
* Returns a string representation of the constraint.
*
* @return string
*/
public function toString() : string
{
return sprintf(
'contains "%s"',
$this->string
);
}
protected function failureDescription($pageContent) : string
{
$message = $this->uriMessage('on page');
$message->append("\n--> ");
$message->append(substr($pageContent, 0, 300));
if (strlen($pageContent) > 300) {
$debugMessage = new Message(
"[Content too long to display. See complete response in '" . codecept_output_dir() . "' directory]"
);
$message->append("\n")->append($debugMessage);
}
$message->append("\n--> ");
return $message->getMessage() . $this->toString();
}
protected function uriMessage($onPage = "")
{
if (!$this->uri) {
return new Message('');
}
$message = new Message($this->uri);
$message->prepend(" $onPage ");
return $message;
}
}
PK bq[N
N src/Constraint/WebDriverNot.phpnu W+A string) {
throw new \PHPUnit\Framework\ExpectationFailedException(
"Element $selector was found",
$comparisonFailure
);
}
$output = "There was $selector element";
$output .= $this->uriMessage("on page");
$output .= $this->nodesList($nodes, $this->string);
$output .= "\ncontaining '{$this->string}'";
throw new \PHPUnit\Framework\ExpectationFailedException(
$output,
$comparisonFailure
);
}
public function toString() : string
{
if ($this->string) {
return 'that contains text "' . $this->string . '"';
}
}
}
PK bq[NB= src/TestCase.phpnu W+A _setUp();
}
}
protected function tearDown(): void
{
if (method_exists($this, '_tearDown')) {
$this->_tearDown();
}
}
public static function setUpBeforeClass(): void
{
if (method_exists(get_called_class(), '_setUpBeforeClass')) {
static::_setUpBeforeClass();
}
}
public static function tearDownAfterClass(): void
{
if (method_exists(get_called_class(), '_tearDownAfterClass')) {
static::_tearDownAfterClass();
}
}
}
PK bq[N src/Init.phpnu W+A getFileName();
} else {
$reflector = new \ReflectionClass($test);
$filename = $reflector->getFileName();
}
if ($filename !== $this->currentFile) {
if ($this->currentFile !== null) {
parent::endTestSuite(new TestSuite());
}
//initialize all values to avoid warnings
$this->testSuiteAssertions[self::FILE_LEVEL] = 0;
$this->testSuiteTests[self::FILE_LEVEL] = 0;
$this->testSuiteTimes[self::FILE_LEVEL] = 0;
$this->testSuiteErrors[self::FILE_LEVEL] = 0;
$this->testSuiteFailures[self::FILE_LEVEL] = 0;
$this->testSuiteSkipped[self::FILE_LEVEL] = 0;
$this->testSuiteLevel = self::FILE_LEVEL;
$this->currentFile = $filename;
$this->currentFileSuite = $this->document->createElement('testsuite');
if ($test instanceof Reported) {
$reportFields = $test->getReportFields();
$class = isset($reportFields['class']) ? $reportFields['class'] : $reportFields['name'];
$this->currentFileSuite->setAttribute('name', $class);
} else {
$this->currentFileSuite->setAttribute('name', get_class($test));
}
$this->currentFileSuite->setAttribute('file', $filename);
$this->testSuites[self::SUITE_LEVEL]->appendChild($this->currentFileSuite);
$this->testSuites[self::FILE_LEVEL] = $this->currentFileSuite;
}
if (!$test instanceof Reported) {
parent::startTest($test);
return;
}
$this->currentTestCase = $this->document->createElement('testcase');
$isStrict = Configuration::config()['settings']['strict_xml'];
foreach ($test->getReportFields() as $attr => $value) {
if ($isStrict and !in_array($attr, $this->strictAttributes)) {
continue;
}
$this->currentTestCase->setAttribute($attr, $value);
}
}
public function endTest(\PHPUnit\Framework\Test $test, float $time):void
{
if ($this->currentTestCase !== null && $test instanceof Test) {
$numAssertions = $test->getNumAssertions();
$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;
$this->currentTestCase->setAttribute(
'assertions',
$numAssertions
);
}
if ($test instanceof TestCase) {
parent::endTest($test, $time);
return;
}
// In PhpUnit 7.4.*, parent::endTest ignores tests that aren't instances of TestCase
// so I copied this code from PhpUnit 7.3.5
$this->currentTestCase->setAttribute(
'time',
\sprintf('%F', $time)
);
$this->testSuites[$this->testSuiteLevel]->appendChild(
$this->currentTestCase
);
$this->testSuiteTests[$this->testSuiteLevel]++;
$this->testSuiteTimes[$this->testSuiteLevel] += $time;
$this->currentTestCase = null;
}
/**
* Cleans the mess caused by test suite manipulation in startTest
*/
public function endTestSuite(TestSuite $suite): void
{
if ($suite->getName()) {
if ($this->currentFile) {
//close last file in the test suite
parent::endTestSuite(new TestSuite());
$this->currentFile = null;
}
$this->testSuiteLevel = self::SUITE_LEVEL;
}
parent::endTestSuite($suite);
}
}
PK bq[Nh src/Log/JUnit.phpnu W+A currentTestCase = $this->document->createElement('testcase');
$isStrict = Configuration::config()['settings']['strict_xml'];
foreach ($test->getReportFields() as $attr => $value) {
if ($isStrict and !in_array($attr, $this->strictAttributes)) {
continue;
}
$this->currentTestCase->setAttribute($attr, $value);
}
}
public function endTest(\PHPUnit\Framework\Test $test, float $time):void
{
if ($this->currentTestCase !== null and $test instanceof Test) {
$numAssertions = $test->getNumAssertions();
$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;
$this->currentTestCase->setAttribute(
'assertions',
$numAssertions
);
}
if ($test instanceof TestCase) {
parent::endTest($test, $time);
return;
}
// since PhpUnit 7.4.0, parent::endTest ignores tests that aren't instances of TestCase
// so I copied this code from PhpUnit 7.3.5
$this->currentTestCase->setAttribute(
'time',
\sprintf('%F', $time)
);
$this->testSuites[$this->testSuiteLevel]->appendChild(
$this->currentTestCase
);
$this->testSuiteTests[$this->testSuiteLevel]++;
$this->testSuiteTimes[$this->testSuiteLevel] += $time;
$this->currentTestCase = null;
}
}
PK bq[NVaY src/shim.phpnu W+A getPrevious() ? $e->getPrevious()->getTrace() : $e->getTrace();
if ($e instanceof \PHPUnit\Framework\ExceptionWrapper) {
$trace = $e->getSerializableTrace();
}
$eFile = $e->getFile();
$eLine = $e->getLine();
if (!self::frameExists($trace, $eFile, $eLine)) {
array_unshift(
$trace,
['file' => $eFile, 'line' => $eLine]
);
}
foreach ($trace as $step) {
if (self::classIsFiltered($step) and $filter) {
continue;
}
if (self::fileIsFiltered($step) and $filter) {
continue;
}
if (!$asString) {
$stackTrace[] = $step;
continue;
}
if (!isset($step['file'])) {
continue;
}
$stackTrace .= $step['file'] . ':' . $step['line'] . "\n";
}
return $stackTrace;
}
protected static function classIsFiltered($step)
{
if (!isset($step['class'])) {
return false;
}
$className = $step['class'];
foreach (self::$filteredClassesPattern as $filteredClassName) {
if (strpos($className, $filteredClassName) === 0) {
return true;
}
}
return false;
}
protected static function fileIsFiltered($step)
{
if (!isset($step['file'])) {
return false;
}
if (strpos($step['file'], 'codecept.phar/') !== false) {
return true;
}
if (strpos($step['file'], 'vendor' . DIRECTORY_SEPARATOR . 'phpunit') !== false) {
return true;
}
if (strpos($step['file'], 'vendor' . DIRECTORY_SEPARATOR . 'codeception') !== false) {
return true;
}
$modulePath = 'src' . DIRECTORY_SEPARATOR . 'Codeception' . DIRECTORY_SEPARATOR . 'Module';
if (strpos($step['file'], $modulePath) !== false) {
return false; // don`t filter modules
}
if (strpos($step['file'], 'src' . DIRECTORY_SEPARATOR . 'Codeception' . DIRECTORY_SEPARATOR) !== false) {
return true;
}
return false;
}
/**
* @param array $trace
* @param string $file
* @param int $line
*
* @return bool
*/
private static function frameExists(array $trace, $file, $line)
{
foreach ($trace as $frame) {
if (isset($frame['file']) && $frame['file'] == $file &&
isset($frame['line']) && $frame['line'] == $line) {
return true;
}
}
return false;
}
}
PK bq[N8 src/ResultPrinter/Report.phpnu W+A testStatus == \PHPUnit\Runner\BaseTestRunner::STATUS_PASSED);
if ($success) {
$this->successful++;
}
if ($this->testStatus == \PHPUnit\Runner\BaseTestRunner::STATUS_FAILURE) {
$status = "\033[41;37mFAIL\033[0m";
} 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");
}
protected function endRun() : void
{
$this->write("\nCodeception Results\n");
$this->write(sprintf(
"Successful: %s. Failed: %s. Incomplete: %s. Skipped: %s",
$this->successful,
$this->failed,
$this->skipped,
$this->incomplete
) . "\n");
}
public function printResult(\PHPUnit\Framework\TestResult $result)
{
}
public function write(string $buffer) : void
{
parent::write($buffer);
}
}
PK bq[N(1Zo% o% src/ResultPrinter/HTML.phpnu W+A templatePath = sprintf(
'%s%stemplate%s',
__DIR__,
DIRECTORY_SEPARATOR,
DIRECTORY_SEPARATOR
);
}
/**
* Handler for 'start class' event.
*
* @param string $name
*/
protected function startClass(string $name):void
{
}
public function endTest(\PHPUnit\Framework\Test $test, float $time) : void
{
$steps = [];
$success = ($this->testStatus == \PHPUnit\Runner\BaseTestRunner::STATUS_PASSED);
if ($success) {
$this->successful++;
}
if ($test instanceof ScenarioDriven) {
$steps = $test->getScenario()->getSteps();
}
$this->timeTaken += $time;
switch ($this->testStatus) {
case \PHPUnit\Runner\BaseTestRunner::STATUS_FAILURE:
$scenarioStatus = 'scenarioFailed';
break;
case \PHPUnit\Runner\BaseTestRunner::STATUS_SKIPPED:
$scenarioStatus = 'scenarioSkipped';
break;
case \PHPUnit\Runner\BaseTestRunner::STATUS_INCOMPLETE:
$scenarioStatus = 'scenarioIncomplete';
break;
case \PHPUnit\Runner\BaseTestRunner::STATUS_ERROR:
$scenarioStatus = 'scenarioFailed';
break;
default:
$scenarioStatus = 'scenarioSuccess';
}
$stepsBuffer = '';
$subStepsBuffer = '';
$subStepsRendered = [];
foreach ($steps as $step) {
if ($step->getMetaStep()) {
$subStepsRendered[$step->getMetaStep()->getAction()][] = $this->renderStep($step);
}
}
foreach ($steps as $step) {
if ($step->getMetaStep()) {
if (! empty($subStepsRendered[$step->getMetaStep()->getAction()])) {
$subStepsBuffer = implode('', $subStepsRendered[$step->getMetaStep()->getAction()]);
unset($subStepsRendered[$step->getMetaStep()->getAction()]);
$stepsBuffer .= $this->renderSubsteps($step->getMetaStep(), $subStepsBuffer);
}
} else {
$stepsBuffer .= $this->renderStep($step);
}
}
$scenarioTemplate = new \Text_Template(
$this->templatePath . 'scenario.html'
);
$failures = '';
$name = Descriptor::getTestSignatureUnique($test);
if (isset($this->failures[$name])) {
$failTemplate = new \Text_Template(
$this->templatePath . 'fail.html'
);
foreach ($this->failures[$name] as $failure) {
$failTemplate->setVar(['fail' => nl2br($failure)]);
$failures .= $failTemplate->render() . PHP_EOL;
}
$this->failures[$name] = [];
}
$png = '';
$html = '';
if ($test instanceof TestInterface) {
$reports = $test->getMetadata()->getReports();
if (isset($reports['png'])) {
$localPath = PathResolver::getRelativeDir($reports['png'], codecept_output_dir());
$png = "
|
";
}
if (isset($reports['html'])) {
$localPath = PathResolver::getRelativeDir($reports['html'], codecept_output_dir());
$html = "See HTML snapshot of a failed page |
";
}
}
$toggle = $stepsBuffer ? '+' : '';
$testString = htmlspecialchars(ucfirst(Descriptor::getTestAsString($test)));
$testString = preg_replace('~^([\s\w\\\]+):\s~', '$1 » ', $testString);
$scenarioTemplate->setVar(
[
'id' => ++$this->id,
'name' => $testString,
'scenarioStatus' => $scenarioStatus,
'steps' => $stepsBuffer,
'toggle' => $toggle,
'failure' => $failures,
'png' => $png,
'html' => $html,
'time' => round($time, 2)
]
);
$this->scenarios .= $scenarioTemplate->render();
}
public function startTestSuite(\PHPUnit\Framework\TestSuite $suite) : void
{
$suiteTemplate = new \Text_Template(
$this->templatePath . 'suite.html'
);
if (!$suite->getName()) {
return;
}
$suiteTemplate->setVar(['suite' => ucfirst($suite->getName())]);
$this->scenarios .= $suiteTemplate->render();
}
/**
* Handler for 'end run' event.
*/
protected function endRun():void
{
$scenarioHeaderTemplate = new \Text_Template(
$this->templatePath . 'scenario_header.html'
);
$status = !$this->failed
? 'OK'
: 'FAILED';
$scenarioHeaderTemplate->setVar(
[
'name' => 'Codeception Results',
'status' => $status,
'time' => round($this->timeTaken, 1)
]
);
$header = $scenarioHeaderTemplate->render();
$scenariosTemplate = new \Text_Template(
$this->templatePath . 'scenarios.html'
);
$scenariosTemplate->setVar(
[
'header' => $header,
'scenarios' => $this->scenarios,
'successfulScenarios' => $this->successful,
'failedScenarios' => $this->failed,
'skippedScenarios' => $this->skipped,
'incompleteScenarios' => $this->incomplete
]
);
$this->write($scenariosTemplate->render());
}
/**
* An error occurred.
*
* @param \PHPUnit\Framework\Test $test
* @param \Exception $e
* @param float $time
*/
public function addError(\PHPUnit\Framework\Test $test, \Throwable $e, float $time) : void
{
$this->failures[Descriptor::getTestSignatureUnique($test)][] = $this->cleanMessage($e);
parent::addError($test, $e, $time);
}
/**
* 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, float $time) : void
{
$this->failures[Descriptor::getTestSignatureUnique($test)][] = $this->cleanMessage($e);
parent::addFailure($test, $e, $time);
}
/**
* Starts test
*
* @param \PHPUnit\Framework\Test $test
*/
public function startTest(\PHPUnit\Framework\Test $test):void
{
$name = Descriptor::getTestSignatureUnique($test);
if (isset($this->failures[$name])) {
// test failed in before hook
return;
}
// start test and mark initialize as passed
parent::startTest($test);
}
/**
* @param $step
* @return string
*/
protected function renderStep(Step $step)
{
$stepTemplate = new \Text_Template($this->templatePath . 'step.html');
$stepTemplate->setVar(['action' => $step->getHtml(), 'error' => $step->hasFailed() ? 'failedStep' : '']);
return $stepTemplate->render();
}
/**
* @param $metaStep
* @param $substepsBuffer
* @return string
*/
protected function renderSubsteps(Meta $metaStep, $substepsBuffer)
{
$metaTemplate = new \Text_Template($this->templatePath . 'substeps.html');
$metaTemplate->setVar(['metaStep' => $metaStep->getHtml(), 'error' => $metaStep->hasFailed() ? 'failedStep' : '', 'steps' => $substepsBuffer, 'id' => uniqid()]);
return $metaTemplate->render();
}
private function cleanMessage($exception)
{
$msg = $exception->getMessage();
if ($exception instanceof \PHPUnit\Framework\ExpectationFailedException && $exception->getComparisonFailure()) {
$msg .= $exception->getComparisonFailure()->getDiff();
}
$msg = str_replace(['','','',''], ['','','',''], $msg);
return htmlentities($msg);
}
}
PK bq[N1S S src/ResultPrinter/UI.phpnu W+A OutputInterface::VERBOSITY_NORMAL, $options['colors'] ? 'always' : 'never');
$this->dispatcher = $dispatcher;
}
protected function printDefect(\PHPUnit\Framework\TestFailure $defect, int $count): void
{
$this->write("\n---------\n");
$this->dispatcher->dispatch(
Events::TEST_FAIL_PRINT,
new FailEvent($defect->failedTest(), null, $defect->thrownException(), $count)
);
}
/**
* @param \PHPUnit\Framework\TestFailure $defect
*/
protected function printDefectTrace(\PHPUnit\Framework\TestFailure $defect): void
{
$this->write($defect->getExceptionAsString());
$this->writeNewLine();
$stackTrace = \PHPUnit\Util\Filter::getFilteredStacktrace($defect->thrownException());
foreach ($stackTrace as $i => $frame) {
if (!isset($frame['file'])) {
continue;
}
$this->write(
sprintf(
"#%d %s(%s)",
$i + 1,
$frame['file'],
isset($frame['line']) ? $frame['line'] : '?'
)
);
$this->writeNewLine();
}
}
public function startTest(\PHPUnit\Framework\Test $test) : void
{
if ($test instanceof Unit) {
parent::startTest($test);
}
}
public function endTest(\PHPUnit\Framework\Test $test, float $time) : void
{
if ($test instanceof \PHPUnit\Framework\TestCase or $test instanceof \Codeception\Test\Test) {
$this->numAssertions += $test->getNumAssertions();
}
$this->lastTestFailed = false;
}
public function addError(\PHPUnit\Framework\Test $test, \Throwable $e, float $time) : void
{
$this->lastTestFailed = true;
}
public function addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\AssertionFailedError $e, float $time) : void
{
$this->lastTestFailed = true;
}
public function addWarning(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, float $time) : void
{
$this->lastTestFailed = true;
}
public function addIncompleteTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time) : void
{
$this->lastTestFailed = true;
}
public function addRiskyTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time) : void
{
$this->lastTestFailed = true;
}
public function addSkippedTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time) : void
{
$this->lastTestFailed = true;
}
}
PK bq[NyZ, . src/ResultPrinter/template/scenarios.html.distnu W+A
Test results
{header}
{scenarios}
Summary
Successful scenarios: |
{successfulScenarios} |
Failed scenarios: |
{failedScenarios} |
Skipped scenarios: |
{skippedScenarios} |
Incomplete scenarios: |
{incompleteScenarios} |
|
PK bq[NS& - src/ResultPrinter/template/scenario.html.distnu W+A
{toggle}
{name} {time}s
|
{steps}
{failure}
{png}
{html}
|
PK bq[Nʤ3 3 4 src/ResultPrinter/template/scenario_header.html.distnu W+A {name} {status} ({time}s)
PK bq[N˟; ; ) src/ResultPrinter/template/fail.html.distnu W+A
{fail}
|
PK bq[N͠w# # - src/ResultPrinter/template/substeps.html.distnu W+A
+ {metaStep}
|
|
PK bq[N|3 3 * src/ResultPrinter/template/suite.html.distnu W+A
{suite} Tests
|
PK bq[Ndb b ) src/ResultPrinter/template/step.html.distnu W+A
{action} |
PK bq[N K K src/phpunit5-loggers.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace {
if (!class_exists('PHPUnit_Util_String')) {
/**
* String helpers.
*/
class PHPUnit_Util_String
{
/**
* Converts a string to UTF-8 encoding.
*
* @param string $string
*
* @return string
*/
public static function convertToUtf8($string)
{
return mb_convert_encoding($string, 'UTF-8');
}
/**
* Checks a string for UTF-8 encoding.
*
* @param string $string
*
* @return bool
*/
protected static function isUtf8($string)
{
$length = strlen($string);
for ($i = 0; $i < $length; $i++) {
if (ord($string[$i]) < 0x80) {
$n = 0;
} elseif ((ord($string[$i]) & 0xE0) == 0xC0) {
$n = 1;
} elseif ((ord($string[$i]) & 0xF0) == 0xE0) {
$n = 2;
} elseif ((ord($string[$i]) & 0xF0) == 0xF0) {
$n = 3;
} else {
return false;
}
for ($j = 0; $j < $n; $j++) {
if ((++$i == $length) || ((ord($string[$i]) & 0xC0) != 0x80)) {
return false;
}
}
}
return true;
}
}
}
}
namespace PHPUnit\Util\Log {
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Codeception\Test\Descriptor;
/**
* A TestListener that generates JSON messages.
*/
if (!class_exists('\PHPUnit\Util\Log\JSON')) {
class JSON extends \PHPUnit\Util\Printer implements \PHPUnit\Framework\TestListener
{
/**
* @var string
*/
protected $currentTestSuiteName = '';
/**
* @var string
*/
protected $currentTestName = '';
/**
* @var bool
*/
protected $currentTestPass = true;
/**
* @var array
*/
protected $logEvents = [];
/**
* An error occurred.
*
* @param \PHPUnit\Framework\Test $test
* @param \Throwable $e
* @param float $time
*/
public function addError(\PHPUnit\Framework\Test $test, \Throwable $e, float $time): void
{
$this->writeCase(
'error',
$time,
\PHPUnit\Util\Filter::getFilteredStacktrace($e, false),
\PHPUnit\Framework\TestFailure::exceptionToString($e),
$test
);
$this->currentTestPass = false;
}
/**
* A warning occurred.
*
* @param \PHPUnit\Framework\Test $test
* @param \PHPUnit\Framework\Warning $e
* @param float $time
*/
public function addWarning(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, float $time): void
{
$this->writeCase(
'warning',
$time,
\PHPUnit\Util\Filter::getFilteredStacktrace($e, false),
\PHPUnit\Framework\TestFailure::exceptionToString($e),
$test
);
$this->currentTestPass = false;
}
/**
* 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,
float $time
): void{
$this->writeCase(
'fail',
$time,
\PHPUnit\Util\Filter::getFilteredStacktrace($e, false),
\PHPUnit\Framework\TestFailure::exceptionToString($e),
$test
);
$this->currentTestPass = false;
}
/**
* Incomplete test.
*
* @param \PHPUnit\Framework\Test $test
* @param Throwable $e
* @param float $time
*/
public function addIncompleteTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time): void
{
$this->writeCase(
'error',
$time,
\PHPUnit\Util\Filter::getFilteredStacktrace($e, false),
'Incomplete Test: ' . $e->getMessage(),
$test
);
$this->currentTestPass = false;
}
/**
* Risky test.
*
* @param \PHPUnit\Framework\Test $test
* @param Throwable $e
* @param float $time
*/
public function addRiskyTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time): void
{
$this->writeCase(
'error',
$time,
\PHPUnit\Util\Filter::getFilteredStacktrace($e, false),
'Risky Test: ' . $e->getMessage(),
$test
);
$this->currentTestPass = false;
}
/**
* Skipped test.
*
* @param \PHPUnit\Framework\Test $test
* @param Throwable $e
* @param float $time
*/
public function addSkippedTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time): void
{
$this->writeCase(
'error',
$time,
\PHPUnit\Util\Filter::getFilteredStacktrace($e, false),
'Skipped Test: ' . $e->getMessage(),
$test
);
$this->currentTestPass = false;
}
/**
* A testsuite started.
*
* @param \PHPUnit\Framework\TestSuite $suite
*/
public function startTestSuite(\PHPUnit\Framework\TestSuite $suite): void
{
$this->currentTestSuiteName = $suite->getName();
$this->currentTestName = '';
$this->addLogEvent(
[
'event' => 'suiteStart',
'suite' => $this->currentTestSuiteName,
'tests' => count($suite)
]
);
}
/**
* A testsuite ended.
*
* @param \PHPUnit\Framework\TestSuite $suite
*/
public function endTestSuite(\PHPUnit\Framework\TestSuite $suite): void
{
$this->currentTestSuiteName = '';
$this->currentTestName = '';
$this->writeArray($this->logEvents);
}
/**
* A test started.
*
* @param \PHPUnit\Framework\Test $test
*/
public function startTest(\PHPUnit\Framework\Test $test): void
{
$this->currentTestName = \PHPUnit\Util\Test::describe($test);
$this->currentTestPass = true;
$this->addLogEvent(
[
'event' => 'testStart',
'suite' => $this->currentTestSuiteName,
'test' => $this->currentTestName
]
);
}
/**
* A test ended.
*
* @param \PHPUnit\Framework\Test $test
* @param float $time
*/
public function endTest(\PHPUnit\Framework\Test $test, float $time): void
{
if ($this->currentTestPass) {
$this->writeCase('pass', $time, [], '', $test);
}
}
/**
* @param string $status
* @param float $time
* @param array $trace
* @param string $message
* @param \PHPUnit\Framework\TestCase|null $test
*/
protected function writeCase($status, float $time, array $trace = [], $message = '', $test = null): void
{
$output = '';
// take care of TestSuite producing error (e.g. by running into exception) as TestSuite doesn't have hasOutput
if ($test !== null && method_exists($test, 'hasOutput') && $test->hasOutput()) {
$output = $test->getActualOutput();
}
$this->addLogEvent(
[
'event' => 'test',
'suite' => $this->currentTestSuiteName,
'test' => $this->currentTestName,
'status' => $status,
'time' => $time,
'trace' => $trace,
'message' => \PHPUnit_Util_String::convertToUtf8($message),
'output' => $output,
]
);
}
/**
* @param array $event_data
*/
protected function addLogEvent($event_data = []): void
{
if (count($event_data)) {
array_push($this->logEvents, $event_data);
}
}
/**
* @param array $buffer
*/
public function writeArray($buffer)
{
array_walk_recursive(
$buffer, function (&$input){
if (is_string($input)) {
$input = \PHPUnit_Util_String::convertToUtf8($input);
}
}
);
$this->write(json_encode($buffer, JSON_PRETTY_PRINT));
}
}
}
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!class_exists('\PHPUnit\Util\Log\TAP')) {
/**
* A TestListener that generates a logfile of the
* test execution using the Test Anything Protocol (TAP).
*/
class TAP extends \PHPUnit\Util\Printer implements \PHPUnit\Framework\TestListener
{
/**
* @var int
*/
protected $testNumber = 0;
/**
* @var int
*/
protected $testSuiteLevel = 0;
/**
* @var bool
*/
protected $testSuccessful = true;
/**
* Constructor.
*
* @param mixed $out
*
* @throws \PHPUnit\Framework\Throwable
*/
public function __construct($out = null)
{
parent::__construct($out);
$this->write("TAP version 13\n");
}
/**
* An error occurred.
*
* @param \PHPUnit\Framework\Test $test
* @param Throwable $e
* @param float $time
*/
public function addError(\PHPUnit\Framework\Test $test, \Throwable $e, float $time): void
{
$this->writeNotOk($test, 'Error');
}
/**
* A warning occurred.
*
* @param \PHPUnit\Framework\Test $test
* @param \PHPUnit\Framework\Warning $e
* @param float $time
*/
public function addWarning(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, float $time): void
{
$this->writeNotOk($test, 'Warning');
}
/**
* 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,
float $time
): void{
$this->writeNotOk($test, 'Failure');
$message = explode(
"\n",
\PHPUnit\Framework\TestFailure::exceptionToString($e)
);
$diagnostic = [
'message' => $message[0],
'severity' => 'fail'
];
if ($e instanceof \PHPUnit\Framework\ExpectationFailedThrowable) {
$cf = $e->getComparisonFailure();
if ($cf !== null) {
$diagnostic['data'] = [
'got' => $cf->getActual(),
'expected' => $cf->getExpected()
];
}
}
$yaml = new \Symfony\Component\Yaml\Dumper;
$this->write(
sprintf(
" ---\n%s ...\n",
$yaml->dump($diagnostic, 2, 2)
)
);
}
/**
* Incomplete test.
*
* @param \PHPUnit\Framework\Test $test
* @param \Throwable $e
* @param float $time
*/
public function addIncompleteTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time): void
{
$this->writeNotOk($test, '', 'TODO Incomplete Test');
}
/**
* Risky test.
*
* @param \PHPUnit\Framework\Test $test
* @param Throwable $e
* @param float $time
*/
public function addRiskyTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time): void
{
$this->write(
sprintf(
"ok %d - # RISKY%s\n",
$this->testNumber,
$e->getMessage() != '' ? ' ' . $e->getMessage() : ''
)
);
$this->testSuccessful = false;
}
/**
* Skipped test.
*
* @param \PHPUnit\Framework\Test $test
* @param Throwable $e
* @param float $time
*/
public function addSkippedTest(\PHPUnit\Framework\Test $test, \Throwable $e, float $time): void
{
$this->write(
sprintf(
"ok %d - # SKIP%s\n",
$this->testNumber,
$e->getMessage() != '' ? ' ' . $e->getMessage() : ''
)
);
$this->testSuccessful = false;
}
/**
* A testsuite started.
*
* @param \PHPUnit\Framework\TestSuite $suite
*/
public function startTestSuite(\PHPUnit\Framework\TestSuite $suite): void
{
$this->testSuiteLevel++;
}
/**
* A testsuite ended.
*
* @param \PHPUnit\Framework\TestSuite $suite
*/
public function endTestSuite(\PHPUnit\Framework\TestSuite $suite): void
{
$this->testSuiteLevel--;
if ($this->testSuiteLevel == 0) {
$this->write(sprintf("1..%d\n", $this->testNumber));
}
}
/**
* A test started.
*
* @param \PHPUnit\Framework\Test $test
*/
public function startTest(\PHPUnit\Framework\Test $test): void
{
$this->testNumber++;
$this->testSuccessful = true;
}
/**
* A test ended.
*
* @param \PHPUnit\Framework\Test $test
* @param float $time
*/
public function endTest(\PHPUnit\Framework\Test $test, float $time): void
{
if ($this->testSuccessful === true) {
$this->write(
sprintf(
"ok %d - %s\n",
$this->testNumber,
Descriptor::getTestSignature($test)
)
);
}
$this->writeDiagnostics($test);
}
/**
* @param \PHPUnit\Framework\Test $test
* @param string $prefix
* @param string $directive
*/
protected function writeNotOk(\PHPUnit\Framework\Test $test, $prefix = '', $directive = '')
{
$this->write(
sprintf(
"not ok %d - %s%s%s\n",
$this->testNumber,
$prefix != '' ? $prefix . ': ' : '',
\PHPUnit\Util\Test::describeAsString($test),
$directive != '' ? ' # ' . $directive : ''
)
);
$this->testSuccessful = false;
}
/**
* @param \PHPUnit\Framework\Test $test
*/
private function writeDiagnostics(\PHPUnit\Framework\Test $test)
{
if (!$test instanceof \PHPUnit\Framework\TestCase) {
return;
}
if (!$test->hasOutput()) {
return;
}
foreach (explode("\n", trim($test->getActualOutput())) as $line) {
$this->write(
sprintf(
"# %s\n",
$line
)
);
}
}
}
}
}
// @codingStandardsIgnoreEnd
PK bq[Nf= = src/FilterTest.phpnu W+A getInnerIterator()->current();
if ($test instanceof \PHPUnit\Framework\TestSuite) {
return true;
}
$name = Descriptor::getTestSignature($test);
$index = Descriptor::getTestDataSetIndex($test);
if (!is_null($index)) {
$name .= " with data set #{$index}";
}
$accepted = preg_match($this->filter, $name, $matches);
// This fix the issue when an invalid dataprovider method generate a warning
// See issue https://github.com/Codeception/Codeception/issues/4888
if($test instanceof \PHPUnit\Framework\WarningTestCase) {
$message = $test->getMessage();
$accepted = preg_match($this->filter, $message, $matches);
}
if ($accepted && isset($this->filterMax)) {
$set = end($matches);
$accepted = $set >= $this->filterMin && $set <= $this->filterMax;
}
return $accepted;
}
}
PK bq[N 6[ [ src/NonFinal/TestRunner.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Codeception\PHPUnit\NonFinal;
use PHPUnit\Framework\Error\Deprecated;
use PHPUnit\Framework\Error\Notice;
use PHPUnit\Framework\Error\Warning;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestResult;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Runner\AfterLastTestHook;
use PHPUnit\Runner\BaseTestRunner;
use PHPUnit\Runner\BeforeFirstTestHook;
use PHPUnit\Runner\Filter\ExcludeGroupFilterIterator;
use PHPUnit\Runner\Filter\Factory;
use PHPUnit\Runner\Filter\IncludeGroupFilterIterator;
use PHPUnit\Runner\Filter\NameFilterIterator;
use PHPUnit\Runner\Hook;
use PHPUnit\Runner\NullTestResultCache;
use PHPUnit\Runner\ResultCacheExtension;
use PHPUnit\Runner\StandardTestSuiteLoader;
use PHPUnit\Runner\TestHook;
use PHPUnit\Runner\TestListenerAdapter;
use PHPUnit\Runner\TestResultCache;
use PHPUnit\Runner\TestSuiteLoader;
use PHPUnit\Runner\TestSuiteSorter;
use PHPUnit\Runner\Version;
use PHPUnit\TextUI\ResultPrinter;
use PHPUnit\Util\Configuration;
use PHPUnit\Util\Filesystem;
use PHPUnit\Util\Log\JUnit;
use PHPUnit\Util\Log\TeamCity;
use PHPUnit\Util\Printer;
use PHPUnit\Util\TestDox\CliTestDoxPrinter;
use PHPUnit\Util\TestDox\HtmlResultPrinter;
use PHPUnit\Util\TestDox\TextResultPrinter;
use PHPUnit\Util\TestDox\XmlResultPrinter;
use PHPUnit\Util\XdebugFilterScriptGenerator;
use ReflectionClass;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Exception as CodeCoverageException;
use SebastianBergmann\CodeCoverage\Filter as CodeCoverageFilter;
use SebastianBergmann\CodeCoverage\Report\Clover as CloverReport;
use SebastianBergmann\CodeCoverage\Report\Crap4j as Crap4jReport;
use SebastianBergmann\CodeCoverage\Report\Html\Facade as HtmlReport;
use SebastianBergmann\CodeCoverage\Report\PHP as PhpReport;
use SebastianBergmann\CodeCoverage\Report\Text as TextReport;
use SebastianBergmann\CodeCoverage\Report\Xml\Facade as XmlReport;
use SebastianBergmann\Comparator\Comparator;
use SebastianBergmann\Environment\Runtime;
use SebastianBergmann\Invoker\Invoker;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
class TestRunner extends BaseTestRunner
{
public const SUCCESS_EXIT = 0;
public const FAILURE_EXIT = 1;
public const EXCEPTION_EXIT = 2;
/**
* @var bool
*/
protected static $versionStringPrinted = false;
/**
* @var CodeCoverageFilter
*/
protected $codeCoverageFilter;
/**
* @var TestSuiteLoader
*/
protected $loader;
/**
* @var ResultPrinter
*/
protected $printer;
/**
* @var Runtime
*/
private $runtime;
/**
* @var bool
*/
private $messagePrinted = false;
/**
* @var Hook[]
*/
private $extensions = [];
/**
* @param ReflectionClass|Test $test
* @param bool $exit
*
* @throws \RuntimeException
* @throws \InvalidArgumentException
* @throws Exception
* @throws \ReflectionException
*/
public static function run($test, array $arguments = [], $exit = true): TestResult
{
if ($test instanceof ReflectionClass) {
$test = new TestSuite($test);
}
if ($test instanceof Test) {
$aTestRunner = new self;
return $aTestRunner->doRun(
$test,
$arguments,
$exit
);
}
throw new Exception('No test case or test suite found.');
}
public function __construct(TestSuiteLoader $loader = null, CodeCoverageFilter $filter = null)
{
if ($filter === null) {
$filter = new CodeCoverageFilter;
}
$this->codeCoverageFilter = $filter;
$this->loader = $loader;
$this->runtime = new Runtime;
}
/**
* @throws \PHPUnit\Runner\Exception
* @throws Exception
* @throws \InvalidArgumentException
* @throws \RuntimeException
* @throws \ReflectionException
*/
public function doRun(Test $suite, array $arguments = [], bool $exit = true): TestResult
{
if (isset($arguments['configuration'])) {
$GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] = $arguments['configuration'];
}
$this->handleConfiguration($arguments);
if (\is_int($arguments['columns']) && $arguments['columns'] < 16) {
$arguments['columns'] = 16;
$tooFewColumnsRequested = true;
}
if (isset($arguments['bootstrap'])) {
$GLOBALS['__PHPUNIT_BOOTSTRAP'] = $arguments['bootstrap'];
}
if ($suite instanceof TestCase || $suite instanceof TestSuite) {
if ($arguments['backupGlobals'] === true) {
$suite->setBackupGlobals(true);
}
if ($arguments['backupStaticAttributes'] === true) {
$suite->setBackupStaticAttributes(true);
}
if ($arguments['beStrictAboutChangesToGlobalState'] === true) {
$suite->setBeStrictAboutChangesToGlobalState(true);
}
}
if ($arguments['executionOrder'] === TestSuiteSorter::ORDER_RANDOMIZED) {
\mt_srand($arguments['randomOrderSeed']);
}
if ($arguments['cacheResult']) {
if (isset($arguments['cacheResultFile'])) {
$cache = new TestResultCache($arguments['cacheResultFile']);
} else {
$cache = new TestResultCache;
}
$this->addExtension(new ResultCacheExtension($cache));
}
if ($arguments['executionOrder'] !== TestSuiteSorter::ORDER_DEFAULT || $arguments['executionOrderDefects'] !== TestSuiteSorter::ORDER_DEFAULT || $arguments['resolveDependencies']) {
$cache = $cache ?? new NullTestResultCache;
$cache->load();
$sorter = new TestSuiteSorter($cache);
$sorter->reorderTestsInSuite($suite, $arguments['executionOrder'], $arguments['resolveDependencies'], $arguments['executionOrderDefects']);
$originalExecutionOrder = $sorter->getOriginalExecutionOrder();
unset($sorter);
}
if (\is_int($arguments['repeat']) && $arguments['repeat'] > 0) {
$_suite = new TestSuite;
/* @noinspection PhpUnusedLocalVariableInspection */
foreach (\range(1, $arguments['repeat']) as $step) {
$_suite->addTest($suite);
}
$suite = $_suite;
unset($_suite);
}
$result = $this->createTestResult();
$listener = new TestListenerAdapter;
$listenerNeeded = false;
foreach ($this->extensions as $extension) {
if ($extension instanceof TestHook) {
$listener->add($extension);
$listenerNeeded = true;
}
}
if ($listenerNeeded) {
$result->addListener($listener);
}
unset($listener, $listenerNeeded);
if (!$arguments['convertErrorsToExceptions']) {
$result->convertErrorsToExceptions(false);
}
if (!$arguments['convertDeprecationsToExceptions']) {
Deprecated::$enabled = false;
}
if (!$arguments['convertNoticesToExceptions']) {
Notice::$enabled = false;
}
if (!$arguments['convertWarningsToExceptions']) {
Warning::$enabled = false;
}
if ($arguments['stopOnError']) {
$result->stopOnError(true);
}
if ($arguments['stopOnFailure']) {
$result->stopOnFailure(true);
}
if ($arguments['stopOnWarning']) {
$result->stopOnWarning(true);
}
if ($arguments['stopOnIncomplete']) {
$result->stopOnIncomplete(true);
}
if ($arguments['stopOnRisky']) {
$result->stopOnRisky(true);
}
if ($arguments['stopOnSkipped']) {
$result->stopOnSkipped(true);
}
if ($arguments['stopOnDefect']) {
$result->stopOnDefect(true);
}
if ($arguments['registerMockObjectsFromTestArgumentsRecursively']) {
$result->setRegisterMockObjectsFromTestArgumentsRecursively(true);
}
if ($this->printer === null) {
if (isset($arguments['printer']) &&
$arguments['printer'] instanceof Printer) {
$this->printer = $arguments['printer'];
} else {
$printerClass = ResultPrinter::class;
if (isset($arguments['printer']) && \is_string($arguments['printer']) && \class_exists($arguments['printer'], false)) {
$class = new ReflectionClass($arguments['printer']);
if ($class->isSubclassOf(ResultPrinter::class)) {
$printerClass = $arguments['printer'];
}
}
$this->printer = new $printerClass(
(isset($arguments['stderr']) && $arguments['stderr'] === true) ? 'php://stderr' : null,
$arguments['verbose'],
$arguments['colors'],
$arguments['debug'],
$arguments['columns'],
$arguments['reverseList']
);
if (isset($originalExecutionOrder) && ($this->printer instanceof CliTestDoxPrinter)) {
/* @var CliTestDoxPrinter */
$this->printer->setOriginalExecutionOrder($originalExecutionOrder);
}
}
}
$this->printer->write(
Version::getVersionString() . "\n"
);
self::$versionStringPrinted = true;
if ($arguments['verbose']) {
$this->writeMessage('Runtime', $this->runtime->getNameWithVersionAndCodeCoverageDriver());
if ($arguments['executionOrder'] === TestSuiteSorter::ORDER_RANDOMIZED) {
$this->writeMessage(
'Random seed',
(string) $arguments['randomOrderSeed']
);
}
if (isset($arguments['configuration'])) {
$this->writeMessage(
'Configuration',
$arguments['configuration']->getFilename()
);
}
foreach ($arguments['loadedExtensions'] as $extension) {
$this->writeMessage(
'Extension',
$extension
);
}
foreach ($arguments['notLoadedExtensions'] as $extension) {
$this->writeMessage(
'Extension',
$extension
);
}
}
if (isset($tooFewColumnsRequested)) {
$this->writeMessage('Error', 'Less than 16 columns requested, number of columns set to 16');
}
if ($this->runtime->discardsComments()) {
$this->writeMessage('Warning', 'opcache.save_comments=0 set; annotations will not work');
}
if (isset($arguments['configuration']) && $arguments['configuration']->hasValidationErrors()) {
$this->write(
"\n Warning - The configuration file did not pass validation!\n The following problems have been detected:\n"
);
foreach ($arguments['configuration']->getValidationErrors() as $line => $errors) {
$this->write(\sprintf("\n Line %d:\n", $line));
foreach ($errors as $msg) {
$this->write(\sprintf(" - %s\n", $msg));
}
}
$this->write("\n Test results may not be as expected.\n\n");
}
foreach ($arguments['listeners'] as $listener) {
$result->addListener($listener);
}
$result->addListener($this->printer);
$codeCoverageReports = 0;
if (!isset($arguments['noLogging'])) {
if (isset($arguments['testdoxHTMLFile'])) {
$result->addListener(
new HtmlResultPrinter(
$arguments['testdoxHTMLFile'],
$arguments['testdoxGroups'],
$arguments['testdoxExcludeGroups']
)
);
}
if (isset($arguments['testdoxTextFile'])) {
$result->addListener(
new TextResultPrinter(
$arguments['testdoxTextFile'],
$arguments['testdoxGroups'],
$arguments['testdoxExcludeGroups']
)
);
}
if (isset($arguments['testdoxXMLFile'])) {
$result->addListener(
new XmlResultPrinter(
$arguments['testdoxXMLFile']
)
);
}
if (isset($arguments['teamcityLogfile'])) {
$result->addListener(
new TeamCity($arguments['teamcityLogfile'])
);
}
if (isset($arguments['junitLogfile'])) {
$result->addListener(
new JUnit(
$arguments['junitLogfile'],
$arguments['reportUselessTests']
)
);
}
if (isset($arguments['coverageClover'])) {
$codeCoverageReports++;
}
if (isset($arguments['coverageCrap4J'])) {
$codeCoverageReports++;
}
if (isset($arguments['coverageHtml'])) {
$codeCoverageReports++;
}
if (isset($arguments['coveragePHP'])) {
$codeCoverageReports++;
}
if (isset($arguments['coverageText'])) {
$codeCoverageReports++;
}
if (isset($arguments['coverageXml'])) {
$codeCoverageReports++;
}
}
if (isset($arguments['noCoverage'])) {
$codeCoverageReports = 0;
}
if ($codeCoverageReports > 0 && !$this->runtime->canCollectCodeCoverage()) {
$this->writeMessage('Error', 'No code coverage driver is available');
$codeCoverageReports = 0;
}
if ($codeCoverageReports > 0 || isset($arguments['xdebugFilterFile'])) {
$whitelistFromConfigurationFile = false;
$whitelistFromOption = false;
if (isset($arguments['whitelist'])) {
$this->codeCoverageFilter->addDirectoryToWhitelist($arguments['whitelist']);
$whitelistFromOption = true;
}
if (isset($arguments['configuration'])) {
$filterConfiguration = $arguments['configuration']->getFilterConfiguration();
if (!empty($filterConfiguration['whitelist'])) {
$whitelistFromConfigurationFile = true;
}
if (!empty($filterConfiguration['whitelist'])) {
foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) {
$this->codeCoverageFilter->addDirectoryToWhitelist(
$dir['path'],
$dir['suffix'],
$dir['prefix']
);
}
foreach ($filterConfiguration['whitelist']['include']['file'] as $file) {
$this->codeCoverageFilter->addFileToWhitelist($file);
}
foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) {
$this->codeCoverageFilter->removeDirectoryFromWhitelist(
$dir['path'],
$dir['suffix'],
$dir['prefix']
);
}
foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) {
$this->codeCoverageFilter->removeFileFromWhitelist($file);
}
}
}
}
if ($codeCoverageReports > 0) {
$codeCoverage = new CodeCoverage(
null,
$this->codeCoverageFilter
);
$codeCoverage->setUnintentionallyCoveredSubclassesWhitelist(
[Comparator::class]
);
$codeCoverage->setCheckForUnintentionallyCoveredCode(
$arguments['strictCoverage']
);
$codeCoverage->setCheckForMissingCoversAnnotation(
$arguments['strictCoverage']
);
if (isset($arguments['forceCoversAnnotation'])) {
$codeCoverage->setForceCoversAnnotation(
$arguments['forceCoversAnnotation']
);
}
if (isset($arguments['ignoreDeprecatedCodeUnitsFromCodeCoverage'])) {
$codeCoverage->setIgnoreDeprecatedCode(
$arguments['ignoreDeprecatedCodeUnitsFromCodeCoverage']
);
}
if (isset($arguments['disableCodeCoverageIgnore'])) {
$codeCoverage->setDisableIgnoredLines(true);
}
if (!empty($filterConfiguration['whitelist'])) {
$codeCoverage->setAddUncoveredFilesFromWhitelist(
$filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist']
);
$codeCoverage->setProcessUncoveredFilesFromWhitelist(
$filterConfiguration['whitelist']['processUncoveredFilesFromWhitelist']
);
}
if (!$this->codeCoverageFilter->hasWhitelist()) {
if (!$whitelistFromConfigurationFile && !$whitelistFromOption) {
$this->writeMessage('Error', 'No whitelist is configured, no code coverage will be generated.');
} else {
$this->writeMessage('Error', 'Incorrect whitelist config, no code coverage will be generated.');
}
$codeCoverageReports = 0;
unset($codeCoverage);
}
}
if (isset($arguments['xdebugFilterFile'], $filterConfiguration)) {
$this->write("\n");
$script = (new XdebugFilterScriptGenerator)->generate($filterConfiguration['whitelist']);
if ($arguments['xdebugFilterFile'] !== 'php://stdout' && $arguments['xdebugFilterFile'] !== 'php://stderr' && !Filesystem::createDirectory(\dirname($arguments['xdebugFilterFile']))) {
$this->write(\sprintf('Cannot write Xdebug filter script to %s ' . \PHP_EOL, $arguments['xdebugFilterFile']));
exit(self::EXCEPTION_EXIT);
}
\file_put_contents($arguments['xdebugFilterFile'], $script);
$this->write(\sprintf('Wrote Xdebug filter script to %s ' . \PHP_EOL, $arguments['xdebugFilterFile']));
exit(self::SUCCESS_EXIT);
}
$this->printer->write("\n");
if (isset($codeCoverage)) {
$result->setCodeCoverage($codeCoverage);
if ($codeCoverageReports > 1 && isset($arguments['cacheTokens'])) {
$codeCoverage->setCacheTokens($arguments['cacheTokens']);
}
}
$result->beStrictAboutTestsThatDoNotTestAnything($arguments['reportUselessTests']);
$result->beStrictAboutOutputDuringTests($arguments['disallowTestOutput']);
$result->beStrictAboutTodoAnnotatedTests($arguments['disallowTodoAnnotatedTests']);
$result->beStrictAboutResourceUsageDuringSmallTests($arguments['beStrictAboutResourceUsageDuringSmallTests']);
if ($arguments['enforceTimeLimit'] === true) {
if (!\class_exists(Invoker::class)) {
$this->writeMessage('Error', 'Package phpunit/php-invoker is required for enforcing time limits');
}
if (!\extension_loaded('pcntl') || \strpos(\ini_get('disable_functions'), 'pcntl') !== false) {
$this->writeMessage('Error', 'PHP extension pcntl is required for enforcing time limits');
}
}
$result->enforceTimeLimit($arguments['enforceTimeLimit']);
$result->setDefaultTimeLimit($arguments['defaultTimeLimit']);
$result->setTimeoutForSmallTests($arguments['timeoutForSmallTests']);
$result->setTimeoutForMediumTests($arguments['timeoutForMediumTests']);
$result->setTimeoutForLargeTests($arguments['timeoutForLargeTests']);
if ($suite instanceof TestSuite) {
$this->processSuiteFilters($suite, $arguments);
$suite->setRunTestInSeparateProcess($arguments['processIsolation']);
}
foreach ($this->extensions as $extension) {
if ($extension instanceof BeforeFirstTestHook) {
$extension->executeBeforeFirstTest();
}
}
$suite->run($result);
foreach ($this->extensions as $extension) {
if ($extension instanceof AfterLastTestHook) {
$extension->executeAfterLastTest();
}
}
$result->flushListeners();
if ($this->printer instanceof ResultPrinter) {
$this->printer->printResult($result);
}
if (isset($codeCoverage)) {
if (isset($arguments['coverageClover'])) {
$this->printer->write(
"\nGenerating code coverage report in Clover XML format ..."
);
try {
$writer = new CloverReport;
$writer->process($codeCoverage, $arguments['coverageClover']);
$this->printer->write(" done\n");
unset($writer);
} catch (CodeCoverageException $e) {
$this->printer->write(
" failed\n" . $e->getMessage() . "\n"
);
}
}
if (isset($arguments['coverageCrap4J'])) {
$this->printer->write(
"\nGenerating Crap4J report XML file ..."
);
try {
$writer = new Crap4jReport($arguments['crap4jThreshold']);
$writer->process($codeCoverage, $arguments['coverageCrap4J']);
$this->printer->write(" done\n");
unset($writer);
} catch (CodeCoverageException $e) {
$this->printer->write(
" failed\n" . $e->getMessage() . "\n"
);
}
}
if (isset($arguments['coverageHtml'])) {
$this->printer->write(
"\nGenerating code coverage report in HTML format ..."
);
try {
$writer = new HtmlReport(
$arguments['reportLowUpperBound'],
$arguments['reportHighLowerBound'],
\sprintf(
' and PHPUnit %s',
Version::id()
)
);
$writer->process($codeCoverage, $arguments['coverageHtml']);
$this->printer->write(" done\n");
unset($writer);
} catch (CodeCoverageException $e) {
$this->printer->write(
" failed\n" . $e->getMessage() . "\n"
);
}
}
if (isset($arguments['coveragePHP'])) {
$this->printer->write(
"\nGenerating code coverage report in PHP format ..."
);
try {
$writer = new PhpReport;
$writer->process($codeCoverage, $arguments['coveragePHP']);
$this->printer->write(" done\n");
unset($writer);
} catch (CodeCoverageException $e) {
$this->printer->write(
" failed\n" . $e->getMessage() . "\n"
);
}
}
if (isset($arguments['coverageText'])) {
if ($arguments['coverageText'] == 'php://stdout') {
$outputStream = $this->printer;
$colors = $arguments['colors'] && $arguments['colors'] != ResultPrinter::COLOR_NEVER;
} else {
$outputStream = new Printer($arguments['coverageText']);
$colors = false;
}
$processor = new TextReport(
$arguments['reportLowUpperBound'],
$arguments['reportHighLowerBound'],
$arguments['coverageTextShowUncoveredFiles'],
$arguments['coverageTextShowOnlySummary']
);
$outputStream->write(
$processor->process($codeCoverage, $colors)
);
}
if (isset($arguments['coverageXml'])) {
$this->printer->write(
"\nGenerating code coverage report in PHPUnit XML format ..."
);
try {
$writer = new XmlReport(Version::id());
$writer->process($codeCoverage, $arguments['coverageXml']);
$this->printer->write(" done\n");
unset($writer);
} catch (CodeCoverageException $e) {
$this->printer->write(
" failed\n" . $e->getMessage() . "\n"
);
}
}
}
if ($exit) {
if ($result->wasSuccessful()) {
if ($arguments['failOnRisky'] && !$result->allHarmless()) {
exit(self::FAILURE_EXIT);
}
if ($arguments['failOnWarning'] && $result->warningCount() > 0) {
exit(self::FAILURE_EXIT);
}
exit(self::SUCCESS_EXIT);
}
if ($result->errorCount() > 0) {
exit(self::EXCEPTION_EXIT);
}
if ($result->failureCount() > 0) {
exit(self::FAILURE_EXIT);
}
}
return $result;
}
public function setPrinter(ResultPrinter $resultPrinter): void
{
$this->printer = $resultPrinter;
}
/**
* Returns the loader to be used.
*/
public function getLoader(): TestSuiteLoader
{
if ($this->loader === null) {
$this->loader = new StandardTestSuiteLoader;
}
return $this->loader;
}
public function addExtension(TestHook $extension): void
{
$this->extensions[] = $extension;
}
protected function createTestResult(): TestResult
{
return new TestResult;
}
/**
* Override to define how to handle a failed loading of
* a test suite.
*/
protected function runFailed(string $message): void
{
$this->write($message . \PHP_EOL);
exit(self::FAILURE_EXIT);
}
protected function write(string $buffer): void
{
if (\PHP_SAPI != 'cli' && \PHP_SAPI != 'phpdbg') {
$buffer = \htmlspecialchars($buffer);
}
if ($this->printer !== null) {
$this->printer->write($buffer);
} else {
print $buffer;
}
}
/**
* @throws Exception
*/
protected function handleConfiguration(array &$arguments): void
{
if (isset($arguments['configuration']) &&
!$arguments['configuration'] instanceof Configuration) {
$arguments['configuration'] = Configuration::getInstance(
$arguments['configuration']
);
}
$arguments['debug'] = $arguments['debug'] ?? false;
$arguments['filter'] = $arguments['filter'] ?? false;
$arguments['listeners'] = $arguments['listeners'] ?? [];
if (isset($arguments['configuration'])) {
$arguments['configuration']->handlePHPConfiguration();
$phpunitConfiguration = $arguments['configuration']->getPHPUnitConfiguration();
if (isset($phpunitConfiguration['backupGlobals']) && !isset($arguments['backupGlobals'])) {
$arguments['backupGlobals'] = $phpunitConfiguration['backupGlobals'];
}
if (isset($phpunitConfiguration['backupStaticAttributes']) && !isset($arguments['backupStaticAttributes'])) {
$arguments['backupStaticAttributes'] = $phpunitConfiguration['backupStaticAttributes'];
}
if (isset($phpunitConfiguration['beStrictAboutChangesToGlobalState']) && !isset($arguments['beStrictAboutChangesToGlobalState'])) {
$arguments['beStrictAboutChangesToGlobalState'] = $phpunitConfiguration['beStrictAboutChangesToGlobalState'];
}
if (isset($phpunitConfiguration['bootstrap']) && !isset($arguments['bootstrap'])) {
$arguments['bootstrap'] = $phpunitConfiguration['bootstrap'];
}
if (isset($phpunitConfiguration['cacheResult']) && !isset($arguments['cacheResult'])) {
$arguments['cacheResult'] = $phpunitConfiguration['cacheResult'];
}
if (isset($phpunitConfiguration['cacheResultFile']) && !isset($arguments['cacheResultFile'])) {
$arguments['cacheResultFile'] = $phpunitConfiguration['cacheResultFile'];
}
if (isset($phpunitConfiguration['cacheTokens']) && !isset($arguments['cacheTokens'])) {
$arguments['cacheTokens'] = $phpunitConfiguration['cacheTokens'];
}
if (isset($phpunitConfiguration['cacheTokens']) && !isset($arguments['cacheTokens'])) {
$arguments['cacheTokens'] = $phpunitConfiguration['cacheTokens'];
}
if (isset($phpunitConfiguration['colors']) && !isset($arguments['colors'])) {
$arguments['colors'] = $phpunitConfiguration['colors'];
}
if (isset($phpunitConfiguration['convertDeprecationsToExceptions']) && !isset($arguments['convertDeprecationsToExceptions'])) {
$arguments['convertDeprecationsToExceptions'] = $phpunitConfiguration['convertDeprecationsToExceptions'];
}
if (isset($phpunitConfiguration['convertErrorsToExceptions']) && !isset($arguments['convertErrorsToExceptions'])) {
$arguments['convertErrorsToExceptions'] = $phpunitConfiguration['convertErrorsToExceptions'];
}
if (isset($phpunitConfiguration['convertNoticesToExceptions']) && !isset($arguments['convertNoticesToExceptions'])) {
$arguments['convertNoticesToExceptions'] = $phpunitConfiguration['convertNoticesToExceptions'];
}
if (isset($phpunitConfiguration['convertWarningsToExceptions']) && !isset($arguments['convertWarningsToExceptions'])) {
$arguments['convertWarningsToExceptions'] = $phpunitConfiguration['convertWarningsToExceptions'];
}
if (isset($phpunitConfiguration['processIsolation']) && !isset($arguments['processIsolation'])) {
$arguments['processIsolation'] = $phpunitConfiguration['processIsolation'];
}
if (isset($phpunitConfiguration['stopOnDefect']) && !isset($arguments['stopOnDefect'])) {
$arguments['stopOnDefect'] = $phpunitConfiguration['stopOnDefect'];
}
if (isset($phpunitConfiguration['stopOnError']) && !isset($arguments['stopOnError'])) {
$arguments['stopOnError'] = $phpunitConfiguration['stopOnError'];
}
if (isset($phpunitConfiguration['stopOnFailure']) && !isset($arguments['stopOnFailure'])) {
$arguments['stopOnFailure'] = $phpunitConfiguration['stopOnFailure'];
}
if (isset($phpunitConfiguration['stopOnWarning']) && !isset($arguments['stopOnWarning'])) {
$arguments['stopOnWarning'] = $phpunitConfiguration['stopOnWarning'];
}
if (isset($phpunitConfiguration['stopOnIncomplete']) && !isset($arguments['stopOnIncomplete'])) {
$arguments['stopOnIncomplete'] = $phpunitConfiguration['stopOnIncomplete'];
}
if (isset($phpunitConfiguration['stopOnRisky']) && !isset($arguments['stopOnRisky'])) {
$arguments['stopOnRisky'] = $phpunitConfiguration['stopOnRisky'];
}
if (isset($phpunitConfiguration['stopOnSkipped']) && !isset($arguments['stopOnSkipped'])) {
$arguments['stopOnSkipped'] = $phpunitConfiguration['stopOnSkipped'];
}
if (isset($phpunitConfiguration['failOnWarning']) && !isset($arguments['failOnWarning'])) {
$arguments['failOnWarning'] = $phpunitConfiguration['failOnWarning'];
}
if (isset($phpunitConfiguration['failOnRisky']) && !isset($arguments['failOnRisky'])) {
$arguments['failOnRisky'] = $phpunitConfiguration['failOnRisky'];
}
if (isset($phpunitConfiguration['timeoutForSmallTests']) && !isset($arguments['timeoutForSmallTests'])) {
$arguments['timeoutForSmallTests'] = $phpunitConfiguration['timeoutForSmallTests'];
}
if (isset($phpunitConfiguration['timeoutForMediumTests']) && !isset($arguments['timeoutForMediumTests'])) {
$arguments['timeoutForMediumTests'] = $phpunitConfiguration['timeoutForMediumTests'];
}
if (isset($phpunitConfiguration['timeoutForLargeTests']) && !isset($arguments['timeoutForLargeTests'])) {
$arguments['timeoutForLargeTests'] = $phpunitConfiguration['timeoutForLargeTests'];
}
if (isset($phpunitConfiguration['reportUselessTests']) && !isset($arguments['reportUselessTests'])) {
$arguments['reportUselessTests'] = $phpunitConfiguration['reportUselessTests'];
}
if (isset($phpunitConfiguration['strictCoverage']) && !isset($arguments['strictCoverage'])) {
$arguments['strictCoverage'] = $phpunitConfiguration['strictCoverage'];
}
if (isset($phpunitConfiguration['ignoreDeprecatedCodeUnitsFromCodeCoverage']) && !isset($arguments['ignoreDeprecatedCodeUnitsFromCodeCoverage'])) {
$arguments['ignoreDeprecatedCodeUnitsFromCodeCoverage'] = $phpunitConfiguration['ignoreDeprecatedCodeUnitsFromCodeCoverage'];
}
if (isset($phpunitConfiguration['disallowTestOutput']) && !isset($arguments['disallowTestOutput'])) {
$arguments['disallowTestOutput'] = $phpunitConfiguration['disallowTestOutput'];
}
if (isset($phpunitConfiguration['defaultTimeLimit']) && !isset($arguments['defaultTimeLimit'])) {
$arguments['defaultTimeLimit'] = $phpunitConfiguration['defaultTimeLimit'];
}
if (isset($phpunitConfiguration['enforceTimeLimit']) && !isset($arguments['enforceTimeLimit'])) {
$arguments['enforceTimeLimit'] = $phpunitConfiguration['enforceTimeLimit'];
}
if (isset($phpunitConfiguration['disallowTodoAnnotatedTests']) && !isset($arguments['disallowTodoAnnotatedTests'])) {
$arguments['disallowTodoAnnotatedTests'] = $phpunitConfiguration['disallowTodoAnnotatedTests'];
}
if (isset($phpunitConfiguration['beStrictAboutResourceUsageDuringSmallTests']) && !isset($arguments['beStrictAboutResourceUsageDuringSmallTests'])) {
$arguments['beStrictAboutResourceUsageDuringSmallTests'] = $phpunitConfiguration['beStrictAboutResourceUsageDuringSmallTests'];
}
if (isset($phpunitConfiguration['verbose']) && !isset($arguments['verbose'])) {
$arguments['verbose'] = $phpunitConfiguration['verbose'];
}
if (isset($phpunitConfiguration['reverseDefectList']) && !isset($arguments['reverseList'])) {
$arguments['reverseList'] = $phpunitConfiguration['reverseDefectList'];
}
if (isset($phpunitConfiguration['forceCoversAnnotation']) && !isset($arguments['forceCoversAnnotation'])) {
$arguments['forceCoversAnnotation'] = $phpunitConfiguration['forceCoversAnnotation'];
}
if (isset($phpunitConfiguration['disableCodeCoverageIgnore']) && !isset($arguments['disableCodeCoverageIgnore'])) {
$arguments['disableCodeCoverageIgnore'] = $phpunitConfiguration['disableCodeCoverageIgnore'];
}
if (isset($phpunitConfiguration['registerMockObjectsFromTestArgumentsRecursively']) && !isset($arguments['registerMockObjectsFromTestArgumentsRecursively'])) {
$arguments['registerMockObjectsFromTestArgumentsRecursively'] = $phpunitConfiguration['registerMockObjectsFromTestArgumentsRecursively'];
}
if (isset($phpunitConfiguration['executionOrder']) && !isset($arguments['executionOrder'])) {
$arguments['executionOrder'] = $phpunitConfiguration['executionOrder'];
}
if (isset($phpunitConfiguration['executionOrderDefects']) && !isset($arguments['executionOrderDefects'])) {
$arguments['executionOrderDefects'] = $phpunitConfiguration['executionOrderDefects'];
}
if (isset($phpunitConfiguration['resolveDependencies']) && !isset($arguments['resolveDependencies'])) {
$arguments['resolveDependencies'] = $phpunitConfiguration['resolveDependencies'];
}
$groupCliArgs = [];
if (!empty($arguments['groups'])) {
$groupCliArgs = $arguments['groups'];
}
$groupConfiguration = $arguments['configuration']->getGroupConfiguration();
if (!empty($groupConfiguration['include']) && !isset($arguments['groups'])) {
$arguments['groups'] = $groupConfiguration['include'];
}
if (!empty($groupConfiguration['exclude']) && !isset($arguments['excludeGroups'])) {
$arguments['excludeGroups'] = \array_diff($groupConfiguration['exclude'], $groupCliArgs);
}
foreach ($arguments['configuration']->getExtensionConfiguration() as $extension) {
if (!\class_exists($extension['class'], false) && $extension['file'] !== '') {
require_once $extension['file'];
}
if (!\class_exists($extension['class'])) {
throw new Exception(
\sprintf(
'Class "%s" does not exist',
$extension['class']
)
);
}
$extensionClass = new ReflectionClass($extension['class']);
if (!$extensionClass->implementsInterface(Hook::class)) {
throw new Exception(
\sprintf(
'Class "%s" does not implement a PHPUnit\Runner\Hook interface',
$extension['class']
)
);
}
if (\count($extension['arguments']) == 0) {
$extensionObject = $extensionClass->newInstance();
} else {
$extensionObject = $extensionClass->newInstanceArgs(
$extension['arguments']
);
}
\assert($extensionObject instanceof TestHook);
$this->addExtension($extensionObject);
}
foreach ($arguments['configuration']->getListenerConfiguration() as $listener) {
if (!\class_exists($listener['class'], false) &&
$listener['file'] !== '') {
require_once $listener['file'];
}
if (!\class_exists($listener['class'])) {
throw new Exception(
\sprintf(
'Class "%s" does not exist',
$listener['class']
)
);
}
$listenerClass = new ReflectionClass($listener['class']);
if (!$listenerClass->implementsInterface(TestListener::class)) {
throw new Exception(
\sprintf(
'Class "%s" does not implement the PHPUnit\Framework\TestListener interface',
$listener['class']
)
);
}
if (\count($listener['arguments']) == 0) {
$listener = new $listener['class'];
} else {
$listener = $listenerClass->newInstanceArgs(
$listener['arguments']
);
}
$arguments['listeners'][] = $listener;
}
$loggingConfiguration = $arguments['configuration']->getLoggingConfiguration();
if (isset($loggingConfiguration['coverage-clover']) && !isset($arguments['coverageClover'])) {
$arguments['coverageClover'] = $loggingConfiguration['coverage-clover'];
}
if (isset($loggingConfiguration['coverage-crap4j']) && !isset($arguments['coverageCrap4J'])) {
$arguments['coverageCrap4J'] = $loggingConfiguration['coverage-crap4j'];
if (isset($loggingConfiguration['crap4jThreshold']) && !isset($arguments['crap4jThreshold'])) {
$arguments['crap4jThreshold'] = $loggingConfiguration['crap4jThreshold'];
}
}
if (isset($loggingConfiguration['coverage-html']) && !isset($arguments['coverageHtml'])) {
if (isset($loggingConfiguration['lowUpperBound']) && !isset($arguments['reportLowUpperBound'])) {
$arguments['reportLowUpperBound'] = $loggingConfiguration['lowUpperBound'];
}
if (isset($loggingConfiguration['highLowerBound']) && !isset($arguments['reportHighLowerBound'])) {
$arguments['reportHighLowerBound'] = $loggingConfiguration['highLowerBound'];
}
$arguments['coverageHtml'] = $loggingConfiguration['coverage-html'];
}
if (isset($loggingConfiguration['coverage-php']) && !isset($arguments['coveragePHP'])) {
$arguments['coveragePHP'] = $loggingConfiguration['coverage-php'];
}
if (isset($loggingConfiguration['coverage-text']) && !isset($arguments['coverageText'])) {
$arguments['coverageText'] = $loggingConfiguration['coverage-text'];
if (isset($loggingConfiguration['coverageTextShowUncoveredFiles'])) {
$arguments['coverageTextShowUncoveredFiles'] = $loggingConfiguration['coverageTextShowUncoveredFiles'];
} else {
$arguments['coverageTextShowUncoveredFiles'] = false;
}
if (isset($loggingConfiguration['coverageTextShowOnlySummary'])) {
$arguments['coverageTextShowOnlySummary'] = $loggingConfiguration['coverageTextShowOnlySummary'];
} else {
$arguments['coverageTextShowOnlySummary'] = false;
}
}
if (isset($loggingConfiguration['coverage-xml']) && !isset($arguments['coverageXml'])) {
$arguments['coverageXml'] = $loggingConfiguration['coverage-xml'];
}
if (isset($loggingConfiguration['plain'])) {
$arguments['listeners'][] = new ResultPrinter(
$loggingConfiguration['plain'],
true
);
}
if (isset($loggingConfiguration['teamcity']) && !isset($arguments['teamcityLogfile'])) {
$arguments['teamcityLogfile'] = $loggingConfiguration['teamcity'];
}
if (isset($loggingConfiguration['junit']) && !isset($arguments['junitLogfile'])) {
$arguments['junitLogfile'] = $loggingConfiguration['junit'];
}
if (isset($loggingConfiguration['testdox-html']) && !isset($arguments['testdoxHTMLFile'])) {
$arguments['testdoxHTMLFile'] = $loggingConfiguration['testdox-html'];
}
if (isset($loggingConfiguration['testdox-text']) && !isset($arguments['testdoxTextFile'])) {
$arguments['testdoxTextFile'] = $loggingConfiguration['testdox-text'];
}
if (isset($loggingConfiguration['testdox-xml']) && !isset($arguments['testdoxXMLFile'])) {
$arguments['testdoxXMLFile'] = $loggingConfiguration['testdox-xml'];
}
$testdoxGroupConfiguration = $arguments['configuration']->getTestdoxGroupConfiguration();
if (isset($testdoxGroupConfiguration['include']) &&
!isset($arguments['testdoxGroups'])) {
$arguments['testdoxGroups'] = $testdoxGroupConfiguration['include'];
}
if (isset($testdoxGroupConfiguration['exclude']) &&
!isset($arguments['testdoxExcludeGroups'])) {
$arguments['testdoxExcludeGroups'] = $testdoxGroupConfiguration['exclude'];
}
}
$arguments['addUncoveredFilesFromWhitelist'] = $arguments['addUncoveredFilesFromWhitelist'] ?? true;
$arguments['backupGlobals'] = $arguments['backupGlobals'] ?? null;
$arguments['backupStaticAttributes'] = $arguments['backupStaticAttributes'] ?? null;
$arguments['beStrictAboutChangesToGlobalState'] = $arguments['beStrictAboutChangesToGlobalState'] ?? null;
$arguments['beStrictAboutResourceUsageDuringSmallTests'] = $arguments['beStrictAboutResourceUsageDuringSmallTests'] ?? false;
$arguments['cacheResult'] = $arguments['cacheResult'] ?? true;
$arguments['cacheTokens'] = $arguments['cacheTokens'] ?? false;
$arguments['colors'] = $arguments['colors'] ?? ResultPrinter::COLOR_DEFAULT;
$arguments['columns'] = $arguments['columns'] ?? 80;
$arguments['convertDeprecationsToExceptions'] = $arguments['convertDeprecationsToExceptions'] ?? true;
$arguments['convertErrorsToExceptions'] = $arguments['convertErrorsToExceptions'] ?? true;
$arguments['convertNoticesToExceptions'] = $arguments['convertNoticesToExceptions'] ?? true;
$arguments['convertWarningsToExceptions'] = $arguments['convertWarningsToExceptions'] ?? true;
$arguments['crap4jThreshold'] = $arguments['crap4jThreshold'] ?? 30;
$arguments['disallowTestOutput'] = $arguments['disallowTestOutput'] ?? false;
$arguments['disallowTodoAnnotatedTests'] = $arguments['disallowTodoAnnotatedTests'] ?? false;
$arguments['defaultTimeLimit'] = $arguments['defaultTimeLimit'] ?? 0;
$arguments['enforceTimeLimit'] = $arguments['enforceTimeLimit'] ?? false;
$arguments['excludeGroups'] = $arguments['excludeGroups'] ?? [];
$arguments['failOnRisky'] = $arguments['failOnRisky'] ?? false;
$arguments['failOnWarning'] = $arguments['failOnWarning'] ?? false;
$arguments['executionOrderDefects'] = $arguments['executionOrderDefects'] ?? TestSuiteSorter::ORDER_DEFAULT;
$arguments['groups'] = $arguments['groups'] ?? [];
$arguments['processIsolation'] = $arguments['processIsolation'] ?? false;
$arguments['processUncoveredFilesFromWhitelist'] = $arguments['processUncoveredFilesFromWhitelist'] ?? false;
$arguments['randomOrderSeed'] = $arguments['randomOrderSeed'] ?? \time();
$arguments['registerMockObjectsFromTestArgumentsRecursively'] = $arguments['registerMockObjectsFromTestArgumentsRecursively'] ?? false;
$arguments['repeat'] = $arguments['repeat'] ?? false;
$arguments['reportHighLowerBound'] = $arguments['reportHighLowerBound'] ?? 90;
$arguments['reportLowUpperBound'] = $arguments['reportLowUpperBound'] ?? 50;
$arguments['reportUselessTests'] = $arguments['reportUselessTests'] ?? true;
$arguments['reverseList'] = $arguments['reverseList'] ?? false;
$arguments['executionOrder'] = $arguments['executionOrder'] ?? TestSuiteSorter::ORDER_DEFAULT;
$arguments['resolveDependencies'] = $arguments['resolveDependencies'] ?? true;
$arguments['stopOnError'] = $arguments['stopOnError'] ?? false;
$arguments['stopOnFailure'] = $arguments['stopOnFailure'] ?? false;
$arguments['stopOnIncomplete'] = $arguments['stopOnIncomplete'] ?? false;
$arguments['stopOnRisky'] = $arguments['stopOnRisky'] ?? false;
$arguments['stopOnSkipped'] = $arguments['stopOnSkipped'] ?? false;
$arguments['stopOnWarning'] = $arguments['stopOnWarning'] ?? false;
$arguments['stopOnDefect'] = $arguments['stopOnDefect'] ?? false;
$arguments['strictCoverage'] = $arguments['strictCoverage'] ?? false;
$arguments['testdoxExcludeGroups'] = $arguments['testdoxExcludeGroups'] ?? [];
$arguments['testdoxGroups'] = $arguments['testdoxGroups'] ?? [];
$arguments['timeoutForLargeTests'] = $arguments['timeoutForLargeTests'] ?? 60;
$arguments['timeoutForMediumTests'] = $arguments['timeoutForMediumTests'] ?? 10;
$arguments['timeoutForSmallTests'] = $arguments['timeoutForSmallTests'] ?? 1;
$arguments['verbose'] = $arguments['verbose'] ?? false;
}
/**
* @throws \ReflectionException
* @throws \InvalidArgumentException
*/
private function processSuiteFilters(TestSuite $suite, array $arguments): void
{
if (!$arguments['filter'] &&
empty($arguments['groups']) &&
empty($arguments['excludeGroups'])) {
return;
}
$filterFactory = new Factory;
if (!empty($arguments['excludeGroups'])) {
$filterFactory->addFilter(
new ReflectionClass(ExcludeGroupFilterIterator::class),
$arguments['excludeGroups']
);
}
if (!empty($arguments['groups'])) {
$filterFactory->addFilter(
new ReflectionClass(IncludeGroupFilterIterator::class),
$arguments['groups']
);
}
if ($arguments['filter']) {
$filterFactory->addFilter(
new ReflectionClass(NameFilterIterator::class),
$arguments['filter']
);
}
$suite->injectFilter($filterFactory);
}
private function writeMessage(string $type, string $message): void
{
if (!$this->messagePrinted) {
$this->write("\n");
}
$this->write(
\sprintf(
"%-15s%s\n",
$type . ':',
$message
)
);
$this->messagePrinted = true;
}
}
PK bq[N91/'. '. src/NonFinal/JUnit.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Codeception\PHPUnit\NonFinal;
use DOMDocument;
use DOMElement;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\ExceptionWrapper;
use PHPUnit\Framework\SelfDescribing;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestFailure;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;
use PHPUnit\Util\Filter;
use PHPUnit\Util\Printer;
use PHPUnit\Util\Xml;
use ReflectionClass;
use ReflectionException;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
class JUnit extends Printer implements TestListener
{
/**
* @var DOMDocument
*/
protected $document;
/**
* @var DOMElement
*/
protected $root;
/**
* @var bool
*/
protected $reportUselessTests = false;
/**
* @var bool
*/
protected $writeDocument = true;
/**
* @var DOMElement[]
*/
protected $testSuites = [];
/**
* @var int[]
*/
protected $testSuiteTests = [0];
/**
* @var int[]
*/
protected $testSuiteAssertions = [0];
/**
* @var int[]
*/
protected $testSuiteErrors = [0];
/**
* @var int[]
*/
protected $testSuiteFailures = [0];
/**
* @var int[]
*/
protected $testSuiteSkipped = [0];
/**
* @var int[]
*/
protected $testSuiteTimes = [0];
/**
* @var int
*/
protected $testSuiteLevel = 0;
/**
* @var DOMElement
*/
protected $currentTestCase;
/**
* Constructor.
*
* @param null|mixed $out
*
* @throws \PHPUnit\Framework\Exception
*/
public function __construct($out = null, bool $reportUselessTests = false)
{
$this->document = new DOMDocument('1.0', 'UTF-8');
$this->document->formatOutput = true;
$this->root = $this->document->createElement('testsuites');
$this->document->appendChild($this->root);
parent::__construct($out);
$this->reportUselessTests = $reportUselessTests;
}
/**
* Flush buffer and close output.
*/
public function flush(): void
{
if ($this->writeDocument === true) {
$this->write($this->getXML());
}
parent::flush();
}
/**
* An error occurred.
*
* @throws \InvalidArgumentException
* @throws ReflectionException
*/
public function addError(Test $test, \Throwable $t, float $time): void
{
$this->doAddFault($test, $t, $time, 'error');
$this->testSuiteErrors[$this->testSuiteLevel]++;
}
/**
* A warning occurred.
*
* @throws \InvalidArgumentException
* @throws ReflectionException
*/
public function addWarning(Test $test, Warning $e, float $time): void
{
$this->doAddFault($test, $e, $time, 'warning');
$this->testSuiteFailures[$this->testSuiteLevel]++;
}
/**
* A failure occurred.
*
* @throws \InvalidArgumentException
* @throws ReflectionException
*/
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
{
$this->doAddFault($test, $e, $time, 'failure');
$this->testSuiteFailures[$this->testSuiteLevel]++;
}
/**
* Incomplete test.
*/
public function addIncompleteTest(Test $test, \Throwable $t, float $time): void
{
$this->doAddSkipped($test);
}
/**
* Risky test.
*
* @throws ReflectionException
*/
public function addRiskyTest(Test $test, \Throwable $t, float $time): void
{
if (!$this->reportUselessTests || $this->currentTestCase === null) {
return;
}
$error = $this->document->createElement(
'error',
Xml::prepareString(
"Risky Test\n" .
Filter::getFilteredStacktrace($t)
)
);
$error->setAttribute('type', \get_class($t));
$this->currentTestCase->appendChild($error);
$this->testSuiteErrors[$this->testSuiteLevel]++;
}
/**
* Skipped test.
*/
public function addSkippedTest(Test $test, \Throwable $t, float $time): void
{
$this->doAddSkipped($test);
}
/**
* A testsuite started.
*/
public function startTestSuite(TestSuite $suite): void
{
$testSuite = $this->document->createElement('testsuite');
$testSuite->setAttribute('name', $suite->getName());
if (\class_exists($suite->getName(), false)) {
try {
$class = new ReflectionClass($suite->getName());
$testSuite->setAttribute('file', $class->getFileName());
} catch (ReflectionException $e) {
}
}
if ($this->testSuiteLevel > 0) {
$this->testSuites[$this->testSuiteLevel]->appendChild($testSuite);
} else {
$this->root->appendChild($testSuite);
}
$this->testSuiteLevel++;
$this->testSuites[$this->testSuiteLevel] = $testSuite;
$this->testSuiteTests[$this->testSuiteLevel] = 0;
$this->testSuiteAssertions[$this->testSuiteLevel] = 0;
$this->testSuiteErrors[$this->testSuiteLevel] = 0;
$this->testSuiteFailures[$this->testSuiteLevel] = 0;
$this->testSuiteSkipped[$this->testSuiteLevel] = 0;
$this->testSuiteTimes[$this->testSuiteLevel] = 0;
}
/**
* A testsuite ended.
*/
public function endTestSuite(TestSuite $suite): void
{
$this->testSuites[$this->testSuiteLevel]->setAttribute(
'tests',
(string) $this->testSuiteTests[$this->testSuiteLevel]
);
$this->testSuites[$this->testSuiteLevel]->setAttribute(
'assertions',
(string) $this->testSuiteAssertions[$this->testSuiteLevel]
);
$this->testSuites[$this->testSuiteLevel]->setAttribute(
'errors',
(string) $this->testSuiteErrors[$this->testSuiteLevel]
);
$this->testSuites[$this->testSuiteLevel]->setAttribute(
'failures',
(string) $this->testSuiteFailures[$this->testSuiteLevel]
);
$this->testSuites[$this->testSuiteLevel]->setAttribute(
'skipped',
(string) $this->testSuiteSkipped[$this->testSuiteLevel]
);
$this->testSuites[$this->testSuiteLevel]->setAttribute(
'time',
\sprintf('%F', $this->testSuiteTimes[$this->testSuiteLevel])
);
if ($this->testSuiteLevel > 1) {
$this->testSuiteTests[$this->testSuiteLevel - 1] += $this->testSuiteTests[$this->testSuiteLevel];
$this->testSuiteAssertions[$this->testSuiteLevel - 1] += $this->testSuiteAssertions[$this->testSuiteLevel];
$this->testSuiteErrors[$this->testSuiteLevel - 1] += $this->testSuiteErrors[$this->testSuiteLevel];
$this->testSuiteFailures[$this->testSuiteLevel - 1] += $this->testSuiteFailures[$this->testSuiteLevel];
$this->testSuiteSkipped[$this->testSuiteLevel - 1] += $this->testSuiteSkipped[$this->testSuiteLevel];
$this->testSuiteTimes[$this->testSuiteLevel - 1] += $this->testSuiteTimes[$this->testSuiteLevel];
}
$this->testSuiteLevel--;
}
/**
* A test started.
*
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
* @throws ReflectionException
*/
public function startTest(Test $test): void
{
$usesDataprovider = false;
if (\method_exists($test, 'usesDataProvider')) {
$usesDataprovider = $test->usesDataProvider();
}
$testCase = $this->document->createElement('testcase');
$testCase->setAttribute('name', $test->getName());
$class = new ReflectionClass($test);
$methodName = $test->getName(!$usesDataprovider);
if ($class->hasMethod($methodName)) {
$method = $class->getMethod($methodName);
$testCase->setAttribute('class', $class->getName());
$testCase->setAttribute('classname', \str_replace('\\', '.', $class->getName()));
$testCase->setAttribute('file', $class->getFileName());
$testCase->setAttribute('line', (string) $method->getStartLine());
}
$this->currentTestCase = $testCase;
}
/**
* A test ended.
*/
public function endTest(Test $test, float $time): void
{
$numAssertions = 0;
if (\method_exists($test, 'getNumAssertions')) {
$numAssertions = $test->getNumAssertions();
}
$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;
$this->currentTestCase->setAttribute(
'assertions',
(string) $numAssertions
);
$this->currentTestCase->setAttribute(
'time',
\sprintf('%F', $time)
);
$this->testSuites[$this->testSuiteLevel]->appendChild(
$this->currentTestCase
);
$this->testSuiteTests[$this->testSuiteLevel]++;
$this->testSuiteTimes[$this->testSuiteLevel] += $time;
$testOutput = '';
if (\method_exists($test, 'hasOutput') && \method_exists($test, 'getActualOutput')) {
$testOutput = $test->hasOutput() ? $test->getActualOutput() : '';
}
if (!empty($testOutput)) {
$systemOut = $this->document->createElement(
'system-out',
Xml::prepareString($testOutput)
);
$this->currentTestCase->appendChild($systemOut);
}
$this->currentTestCase = null;
}
/**
* Returns the XML as a string.
*/
public function getXML(): string
{
return $this->document->saveXML();
}
/**
* Enables or disables the writing of the document
* in flush().
*
* This is a "hack" needed for the integration of
* PHPUnit with Phing.
*/
public function setWriteDocument(/*bool*/ $flag): void
{
if (\is_bool($flag)) {
$this->writeDocument = $flag;
}
}
/**
* Method which generalizes addError() and addFailure()
*
* @throws \InvalidArgumentException
* @throws ReflectionException
*/
private function doAddFault(Test $test, \Throwable $t, float $time, $type): void
{
if ($this->currentTestCase === null) {
return;
}
if ($test instanceof SelfDescribing) {
$buffer = $test->toString() . "\n";
} else {
$buffer = '';
}
$buffer .= TestFailure::exceptionToString($t) . "\n" .
Filter::getFilteredStacktrace($t);
$fault = $this->document->createElement(
$type,
Xml::prepareString($buffer)
);
if ($t instanceof ExceptionWrapper) {
$fault->setAttribute('type', $t->getClassName());
} else {
$fault->setAttribute('type', \get_class($t));
}
$this->currentTestCase->appendChild($fault);
}
private function doAddSkipped(Test $test): void
{
if ($this->currentTestCase === null) {
return;
}
$skipped = $this->document->createElement('skipped');
$this->currentTestCase->appendChild($skipped);
$this->testSuiteSkipped[$this->testSuiteLevel]++;
}
}
PK bq[N:
# src/NonFinal/NameFilterIterator.phpnu W+A
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Codeception\PHPUnit\NonFinal;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\WarningTestCase;
use PHPUnit\Util\RegularExpression;
use RecursiveFilterIterator;
use RecursiveIterator;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
class NameFilterIterator extends RecursiveFilterIterator
{
/**
* @var string
*/
protected $filter;
/**
* @var int
*/
protected $filterMin;
/**
* @var int
*/
protected $filterMax;
/**
* @throws \Exception
*/
public function __construct(RecursiveIterator $iterator, string $filter)
{
parent::__construct($iterator);
$this->setFilter($filter);
}
/**
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function accept(): bool
{
$test = $this->getInnerIterator()->current();
if ($test instanceof TestSuite) {
return true;
}
$tmp = \PHPUnit\Util\Test::describe($test);
if ($test instanceof WarningTestCase) {
$name = $test->getMessage();
} else {
if ($tmp[0] !== '') {
$name = \implode('::', $tmp);
} else {
$name = $tmp[1];
}
}
$accepted = @\preg_match($this->filter, $name, $matches);
if ($accepted && isset($this->filterMax)) {
$set = \end($matches);
$accepted = $set >= $this->filterMin && $set <= $this->filterMax;
}
return (bool) $accepted;
}
/**
* @throws \Exception
*/
protected function setFilter(string $filter): void
{
if (RegularExpression::safeMatch($filter, '') === false) {
// Handles:
// * testAssertEqualsSucceeds#4
// * testAssertEqualsSucceeds#4-8
if (\preg_match('/^(.*?)#(\d+)(?:-(\d+))?$/', $filter, $matches)) {
if (isset($matches[3]) && $matches[2] < $matches[3]) {
$filter = \sprintf(
'%s.*with data set #(\d+)$',
$matches[1]
);
$this->filterMin = $matches[2];
$this->filterMax = $matches[3];
} else {
$filter = \sprintf(
'%s.*with data set #%s$',
$matches[1],
$matches[2]
);
}
} // Handles:
// * testDetermineJsonError@JSON_ERROR_NONE
// * testDetermineJsonError@JSON.*
elseif (\preg_match('/^(.*?)@(.+)$/', $filter, $matches)) {
$filter = \sprintf(
'%s.*with data set "%s"$',
$matches[1],
$matches[2]
);
}
// Escape delimiters in regular expression. Do NOT use preg_quote,
// to keep magic characters.
$filter = \sprintf('/%s/i', \str_replace(
'/',
'\\/',
$filter
));
}
$this->filter = $filter;
}
}
PK bq[Nҙ
composer.jsonnu W+A {
"name": "codeception/phpunit-wrapper",
"description": "PHPUnit classes used by Codeception",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Davert",
"email": "davert.php@resend.cc"
}
],
"require": {
"php": ">=7.2",
"phpunit/phpunit": "^8.0",
"phpunit/php-code-coverage": "^7.0",
"sebastian/comparator": "^3.0",
"sebastian/diff": "^3.0"
},
"autoload":{
"psr-4":{
"Codeception\\PHPUnit\\": "src\\"
}
},
"require-dev": {
"vlucas/phpdotenv": "^3.0",
"codeception/specify": "*"
}
}
PK bq[NR#5 5 .travis.ymlnu W+A PK bq[N3Yx p README.mdnu W+A PK bq[NߤeX
.gitignorenu W+A PK bq[NY(? ? RoboFile.phpnu W+A PK bq[N* src/phpunit7-interfaces.phpnu W+A PK bq[N(T3Y Y src/Runner.phpnu W+A PK bq[N97MPv v *# src/ConsolePrinter.phpnu W+A PK bq[NDž
$ src/ResultPrinter.phpnu W+A PK bq[N\I^9 9 / src/Listener.phpnu W+A PK bq[NzK K MB src/Constraint/CrawlerNot.phpnu W+A PK bq[NcL F src/Constraint/JsonContains.phpnu W+A PK bq[N,1 1 HN src/Constraint/Crawler.phpnu W+A PK bq[N V src/Constraint/JsonType.phpnu W+A PK bq[Nۄ #] src/Constraint/WebDriver.phpnu W+A PK bq[N/ qf src/Constraint/Page.phpnu W+A PK bq[N
N n src/Constraint/WebDriverNot.phpnu W+A PK bq[NB= s src/TestCase.phpnu W+A PK bq[N w src/Init.phpnu W+A PK bq[N. hx src/Log/PhpUnit.phpnu W+A PK bq[Nh J src/Log/JUnit.phpnu W+A PK bq[NVaY = src/shim.phpnu W+A PK bq[NX6N N src/Overrides/Filter.phpnu W+A PK bq[N8 src/ResultPrinter/Report.phpnu W+A PK bq[N(1Zo% o% src/ResultPrinter/HTML.phpnu W+A PK bq[N1S S <