Skip to content

Commit be6564e

Browse files
Fix issues identified by Phan
1 parent 1ff9e1b commit be6564e

File tree

6 files changed

+79
-31
lines changed

6 files changed

+79
-31
lines changed

src/Framework/Constraint/IsEqual.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function evaluate($other, $description = '', $returnResult = false)
117117
/**
118118
* Returns a string representation of the constraint.
119119
*
120-
* @throws SebastianBergmann\RecursionContext\InvalidArgumentException
120+
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
121121
*/
122122
public function toString(): string
123123
{

src/Framework/Constraint/IsIdentical.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function __construct($value)
5757
* @param bool $returnResult Whether to return a result or throw an exception
5858
*
5959
* @throws ExpectationFailedException
60-
* @throws SebastianBergmann\RecursionContext\InvalidArgumentException
60+
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
6161
*/
6262
public function evaluate($other, $description = '', $returnResult = false)
6363
{
@@ -103,7 +103,7 @@ public function evaluate($other, $description = '', $returnResult = false)
103103
/**
104104
* Returns a string representation of the constraint.
105105
*
106-
* @throws SebastianBergmann\RecursionContext\InvalidArgumentException
106+
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
107107
*/
108108
public function toString(): string
109109
{
@@ -123,7 +123,7 @@ public function toString(): string
123123
*
124124
* @param mixed $other evaluated value or object
125125
*
126-
* @throws SebastianBergmann\RecursionContext\InvalidArgumentException
126+
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
127127
*/
128128
protected function failureDescription($other): string
129129
{

src/Runner/TestSuiteSorter.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ function ($left, $right) {
203203
*/
204204
private function cmpDefectPriorityAndTime(Test $a, Test $b): int
205205
{
206+
if (!$a instanceof TestCase || !$b instanceof TestCase) {
207+
return 0;
208+
}
209+
206210
$priorityA = $this->defectSortOrder[$a->getName()] ?? 0;
207211
$priorityB = $this->defectSortOrder[$b->getName()] ?? 0;
208212

@@ -224,6 +228,10 @@ private function cmpDefectPriorityAndTime(Test $a, Test $b): int
224228
*/
225229
private function cmpDuration(Test $a, Test $b): int
226230
{
231+
if (!$a instanceof TestCase || !$b instanceof TestCase) {
232+
return 0;
233+
}
234+
227235
return $this->cache->getTime($a->getName()) <=> $this->cache->getTime($b->getName());
228236
}
229237

src/TextUI/TestRunner.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\Error\Warning;
1515
use PHPUnit\Framework\Exception;
1616
use PHPUnit\Framework\Test;
17+
use PHPUnit\Framework\TestCase;
1718
use PHPUnit\Framework\TestListener;
1819
use PHPUnit\Framework\TestResult;
1920
use PHPUnit\Framework\TestSuite;
@@ -161,16 +162,18 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te
161162
$GLOBALS['__PHPUNIT_BOOTSTRAP'] = $arguments['bootstrap'];
162163
}
163164

164-
if ($arguments['backupGlobals'] === true) {
165-
$suite->setBackupGlobals(true);
166-
}
165+
if ($suite instanceof TestCase || $suite instanceof TestSuite) {
166+
if ($arguments['backupGlobals'] === true) {
167+
$suite->setBackupGlobals(true);
168+
}
167169

168-
if ($arguments['backupStaticAttributes'] === true) {
169-
$suite->setBackupStaticAttributes(true);
170-
}
170+
if ($arguments['backupStaticAttributes'] === true) {
171+
$suite->setBackupStaticAttributes(true);
172+
}
171173

172-
if ($arguments['beStrictAboutChangesToGlobalState'] === true) {
173-
$suite->setBeStrictAboutChangesToGlobalState(true);
174+
if ($arguments['beStrictAboutChangesToGlobalState'] === true) {
175+
$suite->setBeStrictAboutChangesToGlobalState(true);
176+
}
174177
}
175178

176179
if ($arguments['executionOrder'] === TestSuiteSorter::ORDER_RANDOMIZED) {

src/Util/Log/JUnit.php

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -287,24 +287,27 @@ public function endTestSuite(TestSuite $suite): void
287287
* A test started.
288288
*
289289
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
290+
* @throws ReflectionException
290291
*/
291292
public function startTest(Test $test): void
292293
{
294+
if (!$test instanceof TestCase) {
295+
return;
296+
}
297+
293298
$testCase = $this->document->createElement('testcase');
294299
$testCase->setAttribute('name', $test->getName());
295300

296-
if ($test instanceof TestCase) {
297-
$class = new ReflectionClass($test);
298-
$methodName = $test->getName(!$test->usesDataProvider());
301+
$class = new ReflectionClass($test);
302+
$methodName = $test->getName(!$test->usesDataProvider());
299303

300-
if ($class->hasMethod($methodName)) {
301-
$method = $class->getMethod($methodName);
304+
if ($class->hasMethod($methodName)) {
305+
$method = $class->getMethod($methodName);
302306

303-
$testCase->setAttribute('class', $class->getName());
304-
$testCase->setAttribute('classname', \str_replace('\\', '.', $class->getName()));
305-
$testCase->setAttribute('file', $class->getFileName());
306-
$testCase->setAttribute('line', $method->getStartLine());
307-
}
307+
$testCase->setAttribute('class', $class->getName());
308+
$testCase->setAttribute('classname', \str_replace('\\', '.', $class->getName()));
309+
$testCase->setAttribute('file', $class->getFileName());
310+
$testCase->setAttribute('line', $method->getStartLine());
308311
}
309312

310313
$this->currentTestCase = $testCase;
@@ -315,16 +318,18 @@ public function startTest(Test $test): void
315318
*/
316319
public function endTest(Test $test, float $time): void
317320
{
318-
if ($test instanceof TestCase) {
319-
$numAssertions = $test->getNumAssertions();
320-
$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;
321-
322-
$this->currentTestCase->setAttribute(
323-
'assertions',
324-
$numAssertions
325-
);
321+
if (!$test instanceof TestCase) {
322+
return;
326323
}
327324

325+
$numAssertions = $test->getNumAssertions();
326+
$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;
327+
328+
$this->currentTestCase->setAttribute(
329+
'assertions',
330+
$numAssertions
331+
);
332+
328333
$this->currentTestCase->setAttribute(
329334
'time',
330335
\sprintf('%F', $time)
@@ -337,7 +342,7 @@ public function endTest(Test $test, float $time): void
337342
$this->testSuiteTests[$this->testSuiteLevel]++;
338343
$this->testSuiteTimes[$this->testSuiteLevel] += $time;
339344

340-
if (\method_exists($test, 'hasOutput') && $test->hasOutput()) {
345+
if ($test->hasOutput()) {
341346
$systemOut = $this->document->createElement(
342347
'system-out',
343348
Xml::prepareString($test->getActualOutput())

src/Util/Log/TeamCity.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public function printResult(TestResult $result): void
5757
*/
5858
public function addError(Test $test, \Throwable $t, float $time): void
5959
{
60+
if (!$test instanceof TestCase) {
61+
return;
62+
}
63+
6064
$this->printEvent(
6165
'testFailed',
6266
[
@@ -75,6 +79,10 @@ public function addError(Test $test, \Throwable $t, float $time): void
7579
*/
7680
public function addWarning(Test $test, Warning $e, float $time): void
7781
{
82+
if (!$test instanceof TestCase) {
83+
return;
84+
}
85+
7886
$this->printEvent(
7987
'testFailed',
8088
[
@@ -93,6 +101,10 @@ public function addWarning(Test $test, Warning $e, float $time): void
93101
*/
94102
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
95103
{
104+
if (!$test instanceof TestCase) {
105+
return;
106+
}
107+
96108
$parameters = [
97109
'name' => $test->getName(),
98110
'message' => self::getMessage($e),
@@ -132,6 +144,10 @@ public function addFailure(Test $test, AssertionFailedError $e, float $time): vo
132144
*/
133145
public function addIncompleteTest(Test $test, \Throwable $t, float $time): void
134146
{
147+
if (!$test instanceof TestCase) {
148+
return;
149+
}
150+
135151
$this->printIgnoredTest($test->getName(), $t, $time);
136152
}
137153

@@ -142,6 +158,10 @@ public function addIncompleteTest(Test $test, \Throwable $t, float $time): void
142158
*/
143159
public function addRiskyTest(Test $test, \Throwable $t, float $time): void
144160
{
161+
if (!$test instanceof TestCase) {
162+
return;
163+
}
164+
145165
$this->addError($test, $t, $time);
146166
}
147167

@@ -152,6 +172,10 @@ public function addRiskyTest(Test $test, \Throwable $t, float $time): void
152172
*/
153173
public function addSkippedTest(Test $test, \Throwable $t, float $time): void
154174
{
175+
if (!$test instanceof TestCase) {
176+
return;
177+
}
178+
155179
$testName = $test->getName();
156180

157181
if ($this->startedTestName !== $testName) {
@@ -253,6 +277,10 @@ public function endTestSuite(TestSuite $suite): void
253277
*/
254278
public function startTest(Test $test): void
255279
{
280+
if (!$test instanceof TestCase) {
281+
return;
282+
}
283+
256284
$testName = $test->getName();
257285
$this->startedTestName = $testName;
258286
$params = ['name' => $testName];
@@ -271,6 +299,10 @@ public function startTest(Test $test): void
271299
*/
272300
public function endTest(Test $test, float $time): void
273301
{
302+
if (!$test instanceof TestCase) {
303+
return;
304+
}
305+
274306
parent::endTest($test, $time);
275307

276308
$this->printEvent(

0 commit comments

Comments
 (0)