Skip to content

Commit

Permalink
Remove functionality that has not been documented (and has been advis…
Browse files Browse the repository at this point in the history
…ed against) for years
  • Loading branch information
sebastianbergmann committed Dec 26, 2020
1 parent 2fc1036 commit 36354a9
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 325 deletions.
1 change: 1 addition & 0 deletions ChangeLog-10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes of the PHPUnit 10.0 release series are documented in this fi
### Changed

* [#3871](https://github.com/sebastianbergmann/phpunit/issues/3871): Declare return types for `InvocationStubber` methods
* PHPUnit no longer invokes a static method named `suite` on a class that is declared in a file that is passed as an argument to the CLI test runner
* PHPUnit no longer promotes variables that are global in the bootstrap script's scope to global variables in the test runner's scope (use `$GLOBALS['variable'] = 'value'` instead of `$variable = 'value'` in your bootstrap script)
* The `status` attribute of `<test>` elements in the TestDox XML logfile now contains a textual representation instead of a number (`"success"` instead of `"0"`, for instance)

Expand Down
89 changes: 21 additions & 68 deletions src/Framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use function substr;
use Iterator;
use IteratorAggregate;
use PHPUnit\Runner\BaseTestRunner;
use PHPUnit\Runner\Filter\Factory;
use PHPUnit\Runner\PhptTestCase;
use PHPUnit\Util\Test as TestUtil;
Expand Down Expand Up @@ -311,33 +310,7 @@ public function addTestSuite($testClass): void
if ($testClass instanceof self) {
$this->addTest($testClass);
} elseif ($testClass instanceof ReflectionClass) {
$suiteMethod = false;

if (!$testClass->isAbstract() && $testClass->hasMethod(BaseTestRunner::SUITE_METHOD_NAME)) {
try {
$method = $testClass->getMethod(
BaseTestRunner::SUITE_METHOD_NAME
);
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new Exception(
$e->getMessage(),
(int) $e->getCode(),
$e
);
}
// @codeCoverageIgnoreEnd

if ($method->isStatic()) {
$this->addTest(
$method->invoke(null, $testClass->getName())
);

$suiteMethod = true;
}
}

if (!$suiteMethod && !$testClass->isAbstract() && $testClass->isSubclassOf(TestCase::class)) {
if (!$testClass->isAbstract() && $testClass->isSubclassOf(TestCase::class)) {
$this->addTest(new self($testClass));
}
} else {
Expand Down Expand Up @@ -436,49 +409,29 @@ public function addTestFile(string $filename): void
continue;
}

if (!$class->isAbstract()) {
if ($class->hasMethod(BaseTestRunner::SUITE_METHOD_NAME)) {
try {
$method = $class->getMethod(
BaseTestRunner::SUITE_METHOD_NAME
);
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new Exception(
$e->getMessage(),
(int) $e->getCode(),
$e
);
}
// @codeCoverageIgnoreEnd

if ($method->isStatic()) {
$this->addTest($method->invoke(null, $className));
}
} elseif ($class->implementsInterface(Test::class)) {
$expectedClassName = $shortName;

if (($pos = strpos($expectedClassName, '.')) !== false) {
$expectedClassName = substr(
$expectedClassName,
0,
$pos
);
}
if (!$class->isAbstract() && $class->implementsInterface(Test::class)) {
$expectedClassName = $shortName;

if ($class->getShortName() !== $expectedClassName) {
$this->addWarning(
sprintf(
"Test case class not matching filename is deprecated\n in %s\n Class name was '%s', expected '%s'",
$filename,
$class->getShortName(),
$expectedClassName
)
);
}
if (($pos = strpos($expectedClassName, '.')) !== false) {
$expectedClassName = substr(
$expectedClassName,
0,
$pos
);
}

$this->addTestSuite($class);
if ($class->getShortName() !== $expectedClassName) {
$this->addWarning(
sprintf(
"Test case class not matching filename is deprecated\n in %s\n Class name was '%s', expected '%s'",
$filename,
$class->getShortName(),
$expectedClassName
)
);
}

$this->addTestSuite($class);
}
}

Expand Down
26 changes: 2 additions & 24 deletions src/Runner/BaseTestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\TestSuite;
use ReflectionClass;
use ReflectionException;
use SebastianBergmann\FileIterator\Facade as FileIteratorFacade;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
abstract class BaseTestRunner
{
/**
* @var string
*/
public const SUITE_METHOD_NAME = 'suite';

/**
* Returns the Test corresponding to the given suite.
* This is a template method, subclasses override
Expand Down Expand Up @@ -60,30 +54,14 @@ public function getTest(string $suiteClassFile, $suffixes = ''): ?TestSuite
}

try {
$testClass = $this->loadSuiteClass(
$suiteClassFile
);
$testClass = $this->loadSuiteClass($suiteClassFile);
} catch (\PHPUnit\Exception $e) {
$this->runFailed($e->getMessage());

return null;
}

try {
$suiteMethod = $testClass->getMethod(self::SUITE_METHOD_NAME);

if (!$suiteMethod->isStatic()) {
$this->runFailed(
'suite() method must be static.'
);

return null;
}

$test = $suiteMethod->invoke(null, $testClass->getName());
} catch (ReflectionException $e) {
$test = new TestSuite($testClass);
}
$test = new TestSuite($testClass);

$this->clearStatus();

Expand Down
25 changes: 0 additions & 25 deletions tests/_files/StopOnWarningTestSuite.php

This file was deleted.

4 changes: 2 additions & 2 deletions tests/_files/configuration.depends-on-class.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<testsuites>
<testsuite name="dependsOnClassAndFailure">
<file>../../tests/_files/DependencyOnClassTest.php</file>
<file>../../tests/_files/DependencyFailureTest.php</file>
<file>../../tests/_files/dependencies/DependencyFailureTest.php</file>
</testsuite>
<testsuite name="successfulSuite">
<file>../../tests/_files/DependencySuccessTest.php</file>
<file>../../tests/_files/dependencies/DependencySuccessTest.php</file>
</testsuite>
</testsuites>
</phpunit>
File renamed without changes.
File renamed without changes.
23 changes: 0 additions & 23 deletions tests/end-to-end/execution-order/_files/DependencyTestSuite.php

This file was deleted.

4 changes: 2 additions & 2 deletions tests/end-to-end/execution-order/dependencies-isolation.phpt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
--TEST--
phpunit --process-isolation --verbose ../../_files/DependencyTestSuite.php
phpunit --process-isolation --verbose ../../_files/dependencies
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--process-isolation';
$_SERVER['argv'][] = '--verbose';
$_SERVER['argv'][] = \realpath(__DIR__ . '/_files/DependencyTestSuite.php');
$_SERVER['argv'][] = \realpath(__DIR__ . '/../../_files/dependencies');

require __DIR__ . '/../../bootstrap.php';

Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/execution-order/depends-on-class.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ There was 1 failure:

1) DependencyFailureTest::testOne

%s%etests%e_files%eDependencyFailureTest.php:16
%s%etests%e_files%edependencies%eDependencyFailureTest.php:16

--

Expand Down
26 changes: 18 additions & 8 deletions tests/end-to-end/execution-order/stop-on-defect-via-cli.phpt
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
--TEST--
phpunit --stop-on-defect ./tests/_files/StopOnWarningTestSuite.php
phpunit --stop-on-defect ./tests/_files/FailureTest.php
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--stop-on-defect';
$_SERVER['argv'][] = \realpath(__DIR__ . '/../../_files/StopOnWarningTestSuite.php');
$_SERVER['argv'][] = \realpath(__DIR__ . '/../../_files/FailureTest.php');

require __DIR__ . '/../../bootstrap.php';

PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

W
F

Time: %s, Memory: %s

There was 1 warning:
There was 1 failure:

1) Warning
No tests found in class "PHPUnit\TestFixture\NoTestCases".
1) PHPUnit\TestFixture\FailureTest::testAssertArrayEqualsArray
message
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
- 0 => 1
+ 0 => 2
)

WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.
%sFailureTest.php:%d

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
26 changes: 18 additions & 8 deletions tests/end-to-end/execution-order/stop-on-defect-via-config.phpt
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
--TEST--
phpunit -c ../_files/configuration_stop_on_defect.xml ./tests/_files/StopOnWarningTestSuite.php
phpunit -c ../_files/configuration_stop_on_defect.xml ./tests/_files/FailureTest.php
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '-c';
$_SERVER['argv'][] = \realpath(__DIR__ . '/../../_files/configuration_stop_on_defect.xml');
$_SERVER['argv'][] = \realpath(__DIR__ . '/../../_files/StopOnWarningTestSuite.php');
$_SERVER['argv'][] = \realpath(__DIR__ . '/../../_files/FailureTest.php');

require __DIR__ . '/../../bootstrap.php';

PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

W
F

Time: %s, Memory: %s

There was 1 warning:
There was 1 failure:

1) Warning
No tests found in class "PHPUnit\TestFixture\NoTestCases".
1) PHPUnit\TestFixture\FailureTest::testAssertArrayEqualsArray
message
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
- 0 => 1
+ 0 => 2
)

WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.
%sFailureTest.php:%d

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
26 changes: 0 additions & 26 deletions tests/end-to-end/execution-order/stop-on-warning-via-cli.phpt

This file was deleted.

Loading

0 comments on commit 36354a9

Please sign in to comment.