Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff8253e

Browse files
committed
Inject ForwardCompatibiliy in TestCase
1 parent8173daf commitff8253e

File tree

7 files changed

+50
-138
lines changed

7 files changed

+50
-138
lines changed

‎.travis.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ env:
1717
global:
1818
-MIN_PHP=5.5.9
1919
-SYMFONY_PROCESS_PHP_TEST_BINARY=~/.phpenv/versions/5.6/bin/php
20+
-PHPUNIT_INJECT_FORWARD_COMPAT=1
2021

2122
matrix:
2223
include:
2324
-php:5.5
24-
env:php_extra="5.6 7.0 7.1"
25+
env:php_extra="5.6 7.0 7.1" PHPUNIT_REMOVE_RETURN_TYPEHINT=1
2526
-php:7.2
2627
env:deps=high
2728
-php:7.3

‎src/Symfony/Bridge/PhpUnit/ForwardCompatTestTrait.php‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ trait ForwardCompatTestTrait
2222
{
2323
useLegacy\ForwardCompatTestTraitForV5;
2424
}
25-
}elseif ($r->getMethod('tearDown')->hasReturnType()) {
26-
trait ForwardCompatTestTrait
27-
{
28-
useLegacy\ForwardCompatTestTraitForV8;
29-
}
30-
}else {
25+
}elseif (!$r->getMethod('tearDown')->hasReturnType()) {
3126
trait ForwardCompatTestTrait
3227
{
3328
useLegacy\ForwardCompatTestTraitForV7;

‎src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV5.php‎

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -22,70 +22,6 @@ trait ForwardCompatTestTraitForV5
2222
private$forwardCompatExpectedExceptionMessage ='';
2323
private$forwardCompatExpectedExceptionCode =null;
2424

25-
/**
26-
* @return void
27-
*/
28-
publicstaticfunctionsetUpBeforeClass()
29-
{
30-
self::doSetUpBeforeClass();
31-
}
32-
33-
/**
34-
* @return void
35-
*/
36-
publicstaticfunctiontearDownAfterClass()
37-
{
38-
self::doTearDownAfterClass();
39-
}
40-
41-
/**
42-
* @return void
43-
*/
44-
protectedfunctionsetUp()
45-
{
46-
self::doSetUp();
47-
}
48-
49-
/**
50-
* @return void
51-
*/
52-
protectedfunctiontearDown()
53-
{
54-
self::doTearDown();
55-
}
56-
57-
/**
58-
* @return void
59-
*/
60-
privatestaticfunctiondoSetUpBeforeClass()
61-
{
62-
parent::setUpBeforeClass();
63-
}
64-
65-
/**
66-
* @return void
67-
*/
68-
privatestaticfunctiondoTearDownAfterClass()
69-
{
70-
parent::tearDownAfterClass();
71-
}
72-
73-
/**
74-
* @return void
75-
*/
76-
privatefunctiondoSetUp()
77-
{
78-
parent::setUp();
79-
}
80-
81-
/**
82-
* @return void
83-
*/
84-
privatefunctiondoTearDown()
85-
{
86-
parent::tearDown();
87-
}
88-
8925
/**
9026
* @param string $originalClassName
9127
*

‎src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV7.php‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919
trait ForwardCompatTestTraitForV7
2020
{
21-
use ForwardCompatTestTraitForV5;
22-
2321
/**
2422
* @param string|string[] $originalClassName
2523
*/

‎src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV8.php‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎src/Symfony/Bridge/PhpUnit/bin/simple-phpunit‎

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env php
21
<?php
32

43
/*
@@ -26,6 +25,9 @@ if (PHP_VERSION_ID >= 70200) {
2625
$PHPUNIT_VERSION = '4.8';
2726
}
2827

28+
$PHPUNIT_INJECT_FORWARD_COMPAT = getenv('SYMFONY_PHPUNIT_INJECT_FORWARD_COMPAT', '1') === '1';
29+
$PHPUNIT_REMOVE_RETURN_TYPEHINT = getenv('SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT', '0') === '1';
30+
2931
$COMPOSER_JSON = getenv('COMPOSER') ?: 'composer.json';
3032

3133
$root = __DIR__;
@@ -65,7 +67,9 @@ if (false === $SYMFONY_PHPUNIT_REMOVE = getenv('SYMFONY_PHPUNIT_REMOVE')) {
6567
$SYMFONY_PHPUNIT_REMOVE = 'phpspec/prophecy symfony/yaml';
6668
}
6769

68-
if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") ||md5_file(__FILE__)."\n".$SYMFONY_PHPUNIT_REMOVE !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION.md5")) {
70+
$configurationHash = implode(PHP_EOL, [md5_file(__FILE__), $SYMFONY_PHPUNIT_REMOVE, (int) $PHPUNIT_INJECT_FORWARD_COMPAT, (int) $PHPUNIT_REMOVE_RETURN_TYPEHINT]);
71+
72+
if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || $configurationHash !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION.md5")) {
6973
// Build a standalone phpunit without symfony/yaml nor prophecy by default
7074

7175
@mkdir($PHPUNIT_DIR, 0777, true);
@@ -103,6 +107,45 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
103107
if ($exit) {
104108
exit($exit);
105109
}
110+
111+
// Mutate TestsCase code
112+
if ($PHPUNIT_INJECT_FORWARD_COMPAT || $PHPUNIT_REMOVE_RETURN_TYPEHINT) {
113+
$testCaseFile = implode(DIRECTORY_SEPARATOR, ['src', 'Framework', 'TestCase.php']);
114+
$testCaseCode = file_get_contents($testCaseFile);
115+
if ($PHPUNIT_REMOVE_RETURN_TYPEHINT) {
116+
$testCaseCode = preg_replace('/^ ((?:protected|public)(?: static)? function \w+\(\)): void/m', ' $1', $testCaseCode);
117+
}
118+
119+
if ($PHPUNIT_INJECT_FORWARD_COMPAT) {
120+
$injectedTrait = '';
121+
if ($PHPUNIT_VERSION <= 5) {
122+
$injectedTrait = '\Symfony\Bridge\PhpUnit\Legacy\ForwardCompatTestTraitForV5';
123+
} elseif ($PHPUNIT_VERSION <= 7) {
124+
$injectedTrait = '\Symfony\Bridge\PhpUnit\Legacy\ForwardCompatTestTraitForV7';
125+
}
126+
}
127+
128+
if ($injectedTrait) {
129+
$originalClassName = '';
130+
$testCaseCode = preg_replace_callback('/^abstract class ([^\s]+)/m', function($match) use (&$originalClassName) {
131+
$originalClassName = $match[1];
132+
return 'abstract class SymfonyAlteredTestCase';
133+
}, $testCaseCode, 1);
134+
if (!$originalClassName) {
135+
throw new \RuntimeException('Unexpected class name in PhpUnit TestCase');
136+
}
137+
138+
$testCaseCode .= "
139+
140+
abstract class $originalClassName extends SymfonyAlteredTestCase {
141+
use $injectedTrait;
142+
}
143+
";
144+
}
145+
146+
file_put_contents($testCaseFile, $testCaseCode);
147+
}
148+
106149
file_put_contents('phpunit', <<<'EOPHP'
107150
<?php
108151

@@ -125,7 +168,7 @@ Symfony\Bridge\PhpUnit\TextUI\Command::main();
125168
EOPHP
126169
);
127170
chdir('..');
128-
file_put_contents(".$PHPUNIT_VERSION.md5",md5_file(__FILE__)."\n".$SYMFONY_PHPUNIT_REMOVE);
171+
file_put_contents(".$PHPUNIT_VERSION.md5",$configurationHash);
129172
chdir($oldPwd);
130173

131174
}

‎src/Symfony/Bridge/Twig/Tests/AppVariableTest.php‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33
namespaceSymfony\Bridge\Twig\Tests;
44

55
usePHPUnit\Framework\TestCase;
6-
useSymfony\Bridge\PhpUnit\ForwardCompatTestTrait;
76
useSymfony\Bridge\Twig\AppVariable;
87
useSymfony\Component\HttpFoundation\Request;
98
useSymfony\Component\HttpFoundation\Session\Flash\FlashBag;
109
useSymfony\Component\HttpFoundation\Session\Session;
1110

1211
class AppVariableTestextends TestCase
1312
{
14-
use ForwardCompatTestTrait;
15-
1613
/**
1714
* @var AppVariable
1815
*/
1916
protected$appVariable;
2017

21-
privatefunctiondoSetUp()
18+
protectedfunctionsetUp()
2219
{
2320
$this->appVariable =newAppVariable();
2421
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp