Skip to content

[RFC][PHPUnitBridge] Cross compatibility between PHPUnit 5 and 6 #21668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Setup;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor;
use Symfony\Component\PropertyInfo\Type;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class DoctrineExtractorTest extends \PHPUnit_Framework_TestCase
class DoctrineExtractorTest extends TestCase
{
/**
* @var DoctrineExtractor
Expand Down
11 changes: 7 additions & 4 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace Symfony\Bridge\PhpUnit;

use PHPUnit\Util\ErrorHandler;
use PHPUnit\Util\Test;

/**
* Catch deprecation notices and print a summary report at the end of the test suite.
*
Expand Down Expand Up @@ -68,15 +71,15 @@ public static function register($mode = 0)
);
$deprecationHandler = function ($type, $msg, $file, $line, $context) use (&$deprecations, $getMode) {
if (E_USER_DEPRECATED !== $type) {
return \PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context);
return ErrorHandler::handleError($type, $msg, $file, $line, $context);
}

$mode = $getMode();
$trace = debug_backtrace(true);
$group = 'other';

$i = count($trace);
while (1 < $i && (!isset($trace[--$i]['class']) || ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_')))) {
while (1 < $i && (!isset($trace[--$i]['class']) || ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_') || 0 === strpos($trace[$i]['class'], 'PHPUnit\\')))) {
// No-op
}

Expand All @@ -90,7 +93,7 @@ public static function register($mode = 0)
|| 0 === strpos($method, 'provideLegacy')
|| 0 === strpos($method, 'getLegacy')
|| strpos($class, '\Legacy')
|| in_array('legacy', \PHPUnit_Util_Test::getGroups($class, $method), true)
|| in_array('legacy', Test::getGroups($class, $method), true)
) {
$group = 'legacy';
} else {
Expand Down Expand Up @@ -127,7 +130,7 @@ public static function register($mode = 0)

if (null !== $oldErrorHandler) {
restore_error_handler();
if (array('PHPUnit_Util_ErrorHandler', 'handleError') === $oldErrorHandler) {
if (array('\PHPUnit\Util\ErrorHandler', 'handleError') === $oldErrorHandler) {
restore_error_handler();
self::register($mode);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PHPUnit\Framework\Error;

if (class_exists('\PHPUnit_Framework_Error_Notice')) {
class Notice extends \PHPUnit_Framework_Error_Notice
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PHPUnit\Framework\Error;

if (class_exists('\PHPUnit_Framework_Error_Warning')) {
class Warning extends \PHPUnit_Framework_Error_Warning
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PHPUnit\TextUI;

if (class_exists('\PHPUnit_Framework_Exception')) {
class Exception extends \PHPUnit_Framework_Exception
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PHPUnit\TextUI;

if (class_exists('\PHPUnit_Framework_ExpectationFailedException')) {
class ExpectationFailedException extends \PHPUnit_Framework_ExpectationFailedException
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PHPUnit\TextUI;

if (class_exists('\PHPUnit_Framework_SkippedTestError')) {
class SkippedTestError extends \PHPUnit_Framework_SkippedTestError
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PHPUnit\TextUI;

if (class_exists('\PHPUnit_Framework_TestSuite')) {
class TestSuite extends \PHPUnit_Framework_TestSuite
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PHPUnit\Runner;

if (class_exists('\PHPUnit_Runner_Version')) {
class Version extends \PHPUnit_Runner_Version
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PHPUnit\TextUI;

if (class_exists('\PHPUnit_TextUI_Command')) {
class Command extends \PHPUnit_TextUI_Command
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PHPUnit\TextUI;

if (class_exists('\PHPUnit_TextUI_TestRunner')) {
class TestRunner extends \PHPUnit_TextUI_TestRunner
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PHPUnit\Util;

if (class_exists('\PHPUnit_Util_ErrorHandler')) {
class ErrorHandler extends \PHPUnit_Util_ErrorHandler
{
}
}
9 changes: 9 additions & 0 deletions src/Symfony/Bridge/PhpUnit/ForwardCompatibility/Util/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PHPUnit\Util;

if (class_exists('\PHPUnit_Util_Test')) {
class Test extends \PHPUnit_Util_Test
{
}
}
9 changes: 9 additions & 0 deletions src/Symfony/Bridge/PhpUnit/ForwardCompatibility/Util/XML.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace PHPUnit\Util;

if (class_exists('\PHPUnit_Util_XML')) {
class XML extends \PHPUnit_Util_XML
{
}
}
30 changes: 17 additions & 13 deletions src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
namespace Symfony\Bridge\PhpUnit;

use Doctrine\Common\Annotations\AnnotationRegistry;
use PHPUnit\Framework\BaseTestListener;
use PHPUnit\Framework\TestCase;
use PHPUnit\TextUI\TestSuite;
use PHPUnit\Util\Test;

/**
* Collects and replays skipped tests.
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class SymfonyTestsListener extends \PHPUnit_Framework_BaseTestListener
class SymfonyTestsListener extends BaseTestListener
{
private static $globallyEnabled = false;
private $state = -1;
Expand Down Expand Up @@ -64,7 +68,7 @@ public function __destruct()
}
}

public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
public function startTestSuite(TestSuite $suite)
{
$suiteName = $suite->getName();

Expand All @@ -91,12 +95,12 @@ public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
$testSuites = array($suite);
for ($i = 0; isset($testSuites[$i]); ++$i) {
foreach ($testSuites[$i]->tests() as $test) {
if ($test instanceof \PHPUnit_Framework_TestSuite) {
if ($test instanceof TestSuite) {
if (!class_exists($test->getName(), false)) {
$testSuites[] = $test;
continue;
}
$groups = \PHPUnit_Util_Test::getGroups($test->getName());
$groups = Test::getGroups($test->getName());
if (in_array('time-sensitive', $groups, true)) {
ClockMock::register($test->getName());
}
Expand All @@ -106,7 +110,7 @@ public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
} elseif (2 === $this->state) {
$skipped = array();
foreach ($suite->tests() as $test) {
if (!$test instanceof \PHPUnit_Framework_TestCase
if (!$test instanceof TestCase
|| isset($this->wasSkipped[$suiteName]['*'])
|| isset($this->wasSkipped[$suiteName][$test->getName()])) {
$skipped[] = $test;
Expand All @@ -116,10 +120,10 @@ public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
}
}

public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
public function addSkippedTest(Test $test, \Exception $e, $time)
{
if (0 < $this->state) {
if ($test instanceof \PHPUnit_Framework_TestCase) {
if ($test instanceof TestCase) {
$class = get_class($test);
$method = $test->getName();
} else {
Expand All @@ -131,10 +135,10 @@ public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $ti
}
}

public function startTest(\PHPUnit_Framework_Test $test)
public function startTest(Test $test)
{
if (-2 < $this->state && $test instanceof \PHPUnit_Framework_TestCase) {
$groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName(false));
if (-2 < $this->state && $test instanceof TestCase) {
$groups = Test::getGroups(get_class($test), $test->getName(false));

if (in_array('time-sensitive', $groups, true)) {
ClockMock::register(get_class($test));
Expand All @@ -143,10 +147,10 @@ public function startTest(\PHPUnit_Framework_Test $test)
}
}

public function endTest(\PHPUnit_Framework_Test $test, $time)
public function endTest(Test $test, $time)
{
if (-2 < $this->state && $test instanceof \PHPUnit_Framework_TestCase) {
$groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName(false));
if (-2 < $this->state && $test instanceof TestCase) {
$groups = Test::getGroups(get_class($test), $test->getName(false));

if (in_array('time-sensitive', $groups, true)) {
ClockMock::withClockMock(false);
Expand Down
Loading