Skip to content

Commit

Permalink
Fix issues identified by Phan
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 28, 2018
1 parent 1ff9e1b commit be6564e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/Framework/Constraint/IsEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function evaluate($other, $description = '', $returnResult = false)
/**
* Returns a string representation of the constraint.
*
* @throws SebastianBergmann\RecursionContext\InvalidArgumentException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function toString(): string
{
Expand Down
6 changes: 3 additions & 3 deletions src/Framework/Constraint/IsIdentical.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct($value)
* @param bool $returnResult Whether to return a result or throw an exception
*
* @throws ExpectationFailedException
* @throws SebastianBergmann\RecursionContext\InvalidArgumentException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function evaluate($other, $description = '', $returnResult = false)
{
Expand Down Expand Up @@ -103,7 +103,7 @@ public function evaluate($other, $description = '', $returnResult = false)
/**
* Returns a string representation of the constraint.
*
* @throws SebastianBergmann\RecursionContext\InvalidArgumentException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function toString(): string
{
Expand All @@ -123,7 +123,7 @@ public function toString(): string
*
* @param mixed $other evaluated value or object
*
* @throws SebastianBergmann\RecursionContext\InvalidArgumentException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
protected function failureDescription($other): string
{
Expand Down
8 changes: 8 additions & 0 deletions src/Runner/TestSuiteSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ function ($left, $right) {
*/
private function cmpDefectPriorityAndTime(Test $a, Test $b): int
{
if (!$a instanceof TestCase || !$b instanceof TestCase) {
return 0;
}

$priorityA = $this->defectSortOrder[$a->getName()] ?? 0;
$priorityB = $this->defectSortOrder[$b->getName()] ?? 0;

Expand All @@ -224,6 +228,10 @@ private function cmpDefectPriorityAndTime(Test $a, Test $b): int
*/
private function cmpDuration(Test $a, Test $b): int
{
if (!$a instanceof TestCase || !$b instanceof TestCase) {
return 0;
}

return $this->cache->getTime($a->getName()) <=> $this->cache->getTime($b->getName());
}

Expand Down
19 changes: 11 additions & 8 deletions src/TextUI/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -161,16 +162,18 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te
$GLOBALS['__PHPUNIT_BOOTSTRAP'] = $arguments['bootstrap'];
}

if ($arguments['backupGlobals'] === true) {
$suite->setBackupGlobals(true);
}
if ($suite instanceof TestCase || $suite instanceof TestSuite) {
if ($arguments['backupGlobals'] === true) {
$suite->setBackupGlobals(true);
}

if ($arguments['backupStaticAttributes'] === true) {
$suite->setBackupStaticAttributes(true);
}
if ($arguments['backupStaticAttributes'] === true) {
$suite->setBackupStaticAttributes(true);
}

if ($arguments['beStrictAboutChangesToGlobalState'] === true) {
$suite->setBeStrictAboutChangesToGlobalState(true);
if ($arguments['beStrictAboutChangesToGlobalState'] === true) {
$suite->setBeStrictAboutChangesToGlobalState(true);
}
}

if ($arguments['executionOrder'] === TestSuiteSorter::ORDER_RANDOMIZED) {
Expand Down
43 changes: 24 additions & 19 deletions src/Util/Log/JUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,24 +287,27 @@ public function endTestSuite(TestSuite $suite): void
* A test started.
*
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
* @throws ReflectionException
*/
public function startTest(Test $test): void
{
if (!$test instanceof TestCase) {
return;
}

$testCase = $this->document->createElement('testcase');
$testCase->setAttribute('name', $test->getName());

if ($test instanceof TestCase) {
$class = new ReflectionClass($test);
$methodName = $test->getName(!$test->usesDataProvider());
$class = new ReflectionClass($test);
$methodName = $test->getName(!$test->usesDataProvider());

if ($class->hasMethod($methodName)) {
$method = $class->getMethod($methodName);
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', $method->getStartLine());
}
$testCase->setAttribute('class', $class->getName());
$testCase->setAttribute('classname', \str_replace('\\', '.', $class->getName()));
$testCase->setAttribute('file', $class->getFileName());
$testCase->setAttribute('line', $method->getStartLine());
}

$this->currentTestCase = $testCase;
Expand All @@ -315,16 +318,18 @@ public function startTest(Test $test): void
*/
public function endTest(Test $test, float $time): void
{
if ($test instanceof TestCase) {
$numAssertions = $test->getNumAssertions();
$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;

$this->currentTestCase->setAttribute(
'assertions',
$numAssertions
);
if (!$test instanceof TestCase) {
return;
}

$numAssertions = $test->getNumAssertions();
$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;

$this->currentTestCase->setAttribute(
'assertions',
$numAssertions
);

$this->currentTestCase->setAttribute(
'time',
\sprintf('%F', $time)
Expand All @@ -337,7 +342,7 @@ public function endTest(Test $test, float $time): void
$this->testSuiteTests[$this->testSuiteLevel]++;
$this->testSuiteTimes[$this->testSuiteLevel] += $time;

if (\method_exists($test, 'hasOutput') && $test->hasOutput()) {
if ($test->hasOutput()) {
$systemOut = $this->document->createElement(
'system-out',
Xml::prepareString($test->getActualOutput())
Expand Down
32 changes: 32 additions & 0 deletions src/Util/Log/TeamCity.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public function printResult(TestResult $result): void
*/
public function addError(Test $test, \Throwable $t, float $time): void
{
if (!$test instanceof TestCase) {
return;
}

$this->printEvent(
'testFailed',
[
Expand All @@ -75,6 +79,10 @@ public function addError(Test $test, \Throwable $t, float $time): void
*/
public function addWarning(Test $test, Warning $e, float $time): void
{
if (!$test instanceof TestCase) {
return;
}

$this->printEvent(
'testFailed',
[
Expand All @@ -93,6 +101,10 @@ public function addWarning(Test $test, Warning $e, float $time): void
*/
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
{
if (!$test instanceof TestCase) {
return;
}

$parameters = [
'name' => $test->getName(),
'message' => self::getMessage($e),
Expand Down Expand Up @@ -132,6 +144,10 @@ public function addFailure(Test $test, AssertionFailedError $e, float $time): vo
*/
public function addIncompleteTest(Test $test, \Throwable $t, float $time): void
{
if (!$test instanceof TestCase) {
return;
}

$this->printIgnoredTest($test->getName(), $t, $time);
}

Expand All @@ -142,6 +158,10 @@ public function addIncompleteTest(Test $test, \Throwable $t, float $time): void
*/
public function addRiskyTest(Test $test, \Throwable $t, float $time): void
{
if (!$test instanceof TestCase) {
return;
}

$this->addError($test, $t, $time);
}

Expand All @@ -152,6 +172,10 @@ public function addRiskyTest(Test $test, \Throwable $t, float $time): void
*/
public function addSkippedTest(Test $test, \Throwable $t, float $time): void
{
if (!$test instanceof TestCase) {
return;
}

$testName = $test->getName();

if ($this->startedTestName !== $testName) {
Expand Down Expand Up @@ -253,6 +277,10 @@ public function endTestSuite(TestSuite $suite): void
*/
public function startTest(Test $test): void
{
if (!$test instanceof TestCase) {
return;
}

$testName = $test->getName();
$this->startedTestName = $testName;
$params = ['name' => $testName];
Expand All @@ -271,6 +299,10 @@ public function startTest(Test $test): void
*/
public function endTest(Test $test, float $time): void
{
if (!$test instanceof TestCase) {
return;
}

parent::endTest($test, $time);

$this->printEvent(
Expand Down

0 comments on commit be6564e

Please sign in to comment.