8000 feature #21694 [Bridge/PhpUnit] Add PHPUnit 6 support (nicolas-grekas) · symfony/symfony@6c0d5c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c0d5c9

Browse files
feature #21694 [Bridge/PhpUnit] Add PHPUnit 6 support (nicolas-grekas)
This PR was merged into the 3.3-dev branch. Discussion ---------- [Bridge/PhpUnit] Add PHPUnit 6 support | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21125 | License | MIT | Doc PR | - This PR makes our phpunit bridge compatible with all namespaced versions of phpunit, from 4.8.35 to 6. It takes another approach than #21668 and #21221, thus replaces them. Tested locally : tests pass when using phpunit 5.7, and fails with v6.0 because our own test suite is not yet compatible with it - but at least it runs nice. If this were handled as usual Symfony component, we would consider some changes to be BC breaks. But in this specific case - a phpunit bridge - it makes no sense to me to apply the bc policy here. I added `@final` and `@internal` annotations to make this clearer. Commits ------- 9e0745c [Bridge/PhpUnit] Add PHPUnit 6 support
2 parents a1dbe04 + 9e0745c commit 6c0d5c9

13 files changed

+460
-220
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ script:
100100
- if [[ $deps = high ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --ansi; $PHPUNIT --exclude-group tty,benchmark,intl-data'$LEGACY"$REPORT"; fi
101101
- if [[ $deps = low ]]; then echo "$COMPONENTS" | parallel --gnu -j10% 'cd {}; composer update --no-progress --ansi --prefer-lowest --prefer-stable; $PHPUNIT --exclude-group tty,benchmark,intl-data'"$REPORT"; fi
102102
# Test the PhpUnit bridge using the original phpunit script
103-
- if [[ $deps = low ]]; then (cd src/Symfony/Bridge/PhpUnit && phpenv global 5.3 && php --version && composer update && phpunit); fi
103+
- if [[ $deps = low ]]; then (cd src/Symfony/Bridge/PhpUnit && wget https://phar.phpunit.de/phpunit-4.8.phar); fi
104+
- if [[ $deps = low ]]; then (cd src/Symfony/Bridge/PhpUnit && phpenv global 5.3 && php --version && composer update && php phpunit-4.8.phar); fi

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public static function register($mode = 0)
4141
return;
4242
}
4343

44+
$UtilPrefix = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_' : 'PHPUnit\Util\\';
45+
4446
$getMode = function () use ($mode) {
4547
static $memoizedMode = false;
4648

@@ -67,31 +69,34 @@ public static function register($mode = 0)
6769
'legacy' => array(),
6870
'other' => array(),
6971
);
70-
$deprecationHandler = function ($type, $msg, $file, $line, $context) use (&$deprecations, $getMode) {
72+
$deprecationHandler = function ($type, $msg, $file, $line, $context) use (&$deprecations, $getMode, $UtilPrefix) {
7173
$mode = $getMode();
7274
if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || DeprecationErrorHandler::MODE_DISABLED === $mode) {
73-
return \PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context);
75+
$ErrorHandler = $UtilPrefix.'ErrorHandler';
76+
77+
return $ErrorHandler::handleError($type, $msg, $file, $line, $context);
7478
}
7579

7680
$trace = debug_backtrace(true);
7781
$group = 'other';
7882

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

8488
if (isset($trace[$i]['object']) || isset($trace[$i]['class'])) {
8589
$class = isset($trace[$i]['object']) ? get_class($trace[$i]['object']) : $trace[$i]['class'];
8690
$method = $trace[$i]['function'];
91+
$Test = $UtilPrefix.'Test';
8792

8893
if (0 !== error_reporting()) {
8994
$group = 'unsilenced';
9095
} elseif (0 === strpos($method, 'testLegacy')
9196
|| 0 === strpos($method, 'provideLegacy')
9297
|| 0 === strpos($method, 'getLegacy')
9398
|| strpos($class, '\Legacy')
94-
|| in_array('legacy', \PHPUnit_Util_Test::getGroups($class, $method), true)
99+
|| in_array('legacy', $Test::getGroups($class, $method), true)
95100
) {
96101
$group = 'legacy';
97102
} else {
@@ -128,7 +133,7 @@ public static function register($mode = 0)
128133

129134
if (null !== $oldErrorHandler) {
130135
restore_error_handler();
131-
if (array('PHPUnit_Util_ErrorHandler', 'handleError') === $oldErrorHandler) {
136+
if (array($UtilPrefix.'ErrorHandler', 'handleError') === $oldErrorHandler) {
132137
restore_error_handler();
133138
self::register($mode);
134139
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Legacy;
13+
14+
/**
15+
* {@inheritdoc}
16+
*
17+
* @internal
18+
*/
19+
class Command extends \PHPUnit_TextUI_Command
20+
{
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
protected function createRunner()
25+
{
26+
return new TestRunner($this->arguments['loader']);
27+
}
28+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Legacy;
13+
14+
use Symfony\Bridge\PhpUnit\SymfonyTestsListenerTrait;
15+
16+
/**
17+
* Collects and replays skipped tests.
18+
*
19+
* @author Nicolas Grekas <p@tchwork.com>
20+
*
21+
* @internal
22+
*/
23+
class SymfonyTestsListener extends \PHPUnit_Framework_BaseTestListener
24+
{
25+
use SymfonyTestsListenerTrait;
26+
27+
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
28+
{
29+
return $this->doStartTestSuite($suite);
30+
}
31+
32+
public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
33+
{
34+
return $this->doAddSkippedTest($test, $e, $time);
35+
}
36+
37+
public function startTest(\PHPUnit_Framework_Test $test)
38+
{
39+
return $this->doStartTest($test);
40+
}
41+
42+
public function addWarning(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_Warning $e, $time)
43+
{
44+
return $this->doAddWarning($test, $e, $time);
45+
}
46+
47+
public function endTest(\PHPUnit_Framework_Test $test, $time)
48+
{
49+
return $this->doEndTest($test, $time);
50+
}
51+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Legacy;
13+
14+
/**
15+
* {@inheritdoc}
16+
*
17+
* @internal
18+
*/
19+
class TestRunner extends \PHPUnit_TextUI_TestRunner
20+
{
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
protected function handleConfiguration(array &$arguments)
25+
{
26+
$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
27+
$arguments['listeners'][] = new SymfonyTestsListener();
28+
29+
return parent::handleConfiguration($arguments);
30+
}
31+
}

0 commit comments

Comments
 (0)
0