10000 [RFC][PHPUnitBridge] Cross compatibility between PHPUnit 5 and 6 by peterrehm · Pull Request #21668 · symfony/symfony · GitHub
[go: up one dir, main page]

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 1 commit
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
Prev Previous commit
Next Next commit
Experimental Bridge Refactoring
  • Loading branch information
peterrehm committed Feb 18, 2017
commit 4c616530e647e0d1539271250caa4fd474e9b13c
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\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
{
}
}
18 changes: 10 additions & 8 deletions src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
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.
Expand Down Expand Up @@ -66,7 +68,7 @@ public function __destruct()
}
}

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

Expand All @@ -93,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 @@ -118,7 +120,7 @@ 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 TestCase) {
Expand All @@ -133,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 TestCase) {
$groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName(false));
$groups = Test::getGroups(get_class($test), $test->getName(false));

if (in_array('time-sensitive', $groups, true)) {
ClockMock::register(get_class($test));
Expand All @@ -145,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 TestCase) {
$groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName(false));
$groups = Test::getGroups(get_class($test), $test->getName(false));

if (in_array('time-sensitive', $groups, true)) {
ClockMock::withClockMock(false);
Expand Down
E377
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,34 @@ require_once __DIR__.'/../../bootstrap.php';

@trigger_error('root deprecation', E_USER_DEPRECATED);

class PHPUnit_Util_Test
namespace PHPUnit\Util;

class Test
{
public static function getGroups()
{
return array();
}
}

class FooTestCase
{
public function testLegacyFoo()
{
@trigger_error('silenced foo deprecation', E_USER_DEPRECATED);
trigger_error('unsilenced foo deprecation', E_USER_DEPRECATED);
trigger_error('unsilenced foo deprecation', E_USER_DEPRECATED);
}
namespace {

public function testNonLegacyBar()
class FooTestCase
{
@trigger_error('silenced bar deprecation', E_USER_DEPRECATED);
trigger_error('unsilenced bar deprecation', E_USER_DEPRECATED);
public function testLegacyFoo()
{
@trigger_error('silenced foo deprecation', E_USER_DEPRECATED);
trigger_error('unsilenced foo deprecation', E_USER_DEPRECATED);
trigger_error('unsilenced foo deprecation', E_USER_DEPRECATED);
}

public function testNonLegacyBar()
{
@trigger_error('silenced bar deprecation', E_USER_DEPRECATED);
trigger_error('unsilenced bar deprecation', E_USER_DEPRECATED);
}
}

}

$foo = new FooTestCase();
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Bridge/PhpUnit/TextUI/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

namespace Symfony\Bridge\PhpUnit\TextUI;

use PHPUnit\TextUI\Command as BaseCommand;

/**
* {@inheritdoc}
*/
class Command extends \PHPUnit_TextUI_Command
class Command extends BaseCommand
{
/**
* {@inheritdoc}
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bridge/PhpUnit/TextUI/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

namespace Symfony\Bridge\PhpUnit\TextUI;

use PHPUnit\TextUI\TestRunner as BaseTestRunner;
use Symfony\Bridge\PhpUnit\SymfonyTestsListener;

/**
* {@inheritdoc}
*/
class TestRunner extends \PHPUnit_TextUI_TestRunner
class TestRunner extends BaseTestRunner
{
/**
* {@inheritdoc}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;

// Detect if we're loaded by an actual run of phpunit
if (!defined('PHPUNIT_COMPOSER_INSTALL') && !class_exists('PHPUnit_TextUI_Command', false)) {
if (!defined('PHPUNIT_COMPOSER_INSTALL') && !class_exists('\PHPUnit\TextUI\Command', false)) {
return;
}

Expand Down
9 changes: 7 additions & 2 deletions src/Symfony/Bridge/PhpUnit/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@
"symfony/debug": "For tracking deprecated interfaces usages at runtime with DebugClassLoader"
},
"conflict": {
"phpunit/phpunit": ">=6.0"
"phpunit/phpunit": "<4.8.35|<5.7,>=5.0"
},
"autoload": {
"files": [ "bootstrap.php" ],
"psr-4": { "Symfony\\Bridge\\PhpUnit\\": "" },
"psr-4": {
"Symfony\\Bridge\\PhpUnit\\": "",
"PHPUnit\\Framework": "ForwardCompatibility/Framework/",
"PHPUnit\\TextUI": "ForwardCompatibility/TextUI/",
"PHPUnit\\Util": "ForwardCompatibility/Util/"
},
"exclude-from-classmap": [
"/Tests/"
]
Expand Down
0