File tree 7 files changed +142
-1
lines changed
Filter options
src/Symfony/Bridge/PhpUnit
7 files changed +142
-1
lines changed
Original file line number Diff line number Diff line change @@ -23,6 +23,21 @@ trait ExpectDeprecationTraitBeforeV8_4
23
23
*/
24
24
protected function expectDeprecation ($ message )
25
25
{
26
+ // Expected deprecations set by isolated tests need to be written to a file
27
+ // so that the test running process can take account of them.
28
+ if ($ file = getenv ('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE ' )) {
29
+ $ this ->getTestResultObject ()->beStrictAboutTestsThatDoNotTestAnything (false );
30
+ $ expectedDeprecations = file_get_contents ($ file );
31
+ if ($ expectedDeprecations ) {
32
+ $ expectedDeprecations = array_merge (unserialize ($ expectedDeprecations ), [$ message ]);
33
+ } else {
34
+ $ expectedDeprecations = [$ message ];
35
+ }
36
+ file_put_contents ($ file , serialize ($ expectedDeprecations ));
37
+
38
+ return ;
39
+ }
40
+
26
41
if (!SymfonyTestsListenerTrait::$ previousErrorHandler ) {
27
42
SymfonyTestsListenerTrait::$ previousErrorHandler = set_error_handler ([SymfonyTestsListenerTrait::class, 'handleError ' ]);
28
43
}
Original file line number Diff line number Diff line change @@ -25,6 +25,21 @@ public function expectDeprecation(): void
25
25
throw new \InvalidArgumentException (sprintf ('The "%s()" method requires the string $message argument. ' , __FUNCTION__ ));
26
26
}
27
27
28
+ // Expected deprecations set by isolated tests need to be written to a file
29
+ // so that the test running process can take account of them.
30
+ if ($ file = getenv ('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE ' )) {
31
+ $ this ->getTestResultObject ()->beStrictAboutTestsThatDoNotTestAnything (false );
32
+ $ expectedDeprecations = file_get_contents ($ file );
33
+ if ($ expectedDeprecations ) {
34
+ $ expectedDeprecations = array_merge (unserialize ($ expectedDeprecations ), [$ message ]);
35
+ } else {
36
+ $ expectedDeprecations = [$ message ];
37
+ }
38
+ file_put_contents ($ file , serialize ($ expectedDeprecations ));
39
+
40
+ return ;
41
+ }
42
+
28
43
if (!SymfonyTestsListenerTrait::$ previousErrorHandler ) {
29
44
SymfonyTestsListenerTrait::$ previousErrorHandler = set_error_handler ([SymfonyTestsListenerTrait::class, 'handleError ' ]);
30
45
}
Original file line number Diff line number Diff line change @@ -204,6 +204,7 @@ public function startTest($test)
204
204
if ($ this ->willBeIsolated ($ test )) {
205
205
$ this ->runsInSeparateProcess = tempnam (sys_get_temp_dir (), 'deprec ' );
206
206
putenv ('SYMFONY_DEPRECATIONS_SERIALIZE= ' .$ this ->runsInSeparateProcess );
207
+ putenv ('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE= ' .tempnam (sys_get_temp_dir (), 'expectdeprec ' ));
207
208
}
208
209
209
210
$ groups = Test::getGroups (\get_class ($ test ), $ test ->getName (false ));
@@ -245,6 +246,17 @@ public function startTest($test)
245
246
246
247
public function endTest ($ test , $ time )
247
248
{
249
+ if ($ file = getenv ('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE ' )) {
250
+ putenv ('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE ' );
251
+ $ expectedDeprecations = file_get_contents ($ file );
252
+ if ($ expectedDeprecations ) {
253
+ self ::$ expectedDeprecations = array_merge (self ::$ expectedDeprecations , unserialize ($ expectedDeprecations ));
254
+ if (!self ::$ previousErrorHandler ) {
255
+ self ::$ previousErrorHandler = set_error_handler ([self ::class, 'handleError ' ]);
256
+ }
257
+ }
258
+ }
259
+
248
260
if (class_exists (DebugClassLoader::class, false )) {
249
261
DebugClassLoader::checkClasses ();
250
262
}
Original file line number Diff line number Diff line change @@ -29,6 +29,18 @@ public function testOne()
29
29
@trigger_error ('foo ' , E_USER_DEPRECATED );
30
30
}
31
31
32
+ /**
33
+ * Do not remove this test in the next major version.
34
+ *
35
+ * @group legacy
36
+ * @runInSeparateProcess
37
+ */
38
+ public function testOneInIsolation ()
39
+ {
40
+ $ this ->expectDeprecation ('foo ' );
41
+ @trigger_error ('foo ' , E_USER_DEPRECATED );
42
+ }
43
+
32
44
/**
33
45
* Do not remove this test in the next major version.
34
46
*
Original file line number Diff line number Diff line change
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 \Tests \FailTests ;
13
+
14
+ use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Bridge \PhpUnit \ExpectDeprecationTrait ;
16
+
17
+ /**
18
+ * Class ExpectDeprecationTraitTestFail.
19
+ *
20
+ * This class is deliberately suffixed with *TestFail.php so that it is ignored
21
+ * by PHPUnit. This test is designed to fail. See ../expectdeprecationfail.phpt.
22
+ */
23
+ final class ExpectDeprecationTraitTestFail extends TestCase
24
+ {
25
+ use ExpectDeprecationTrait;
26
+
27
+ /**
28
+ * Do not remove this test in the next major version.
29
+ *
30
+ * @group legacy
31
+ */
32
+ public function testOne ()
33
+ {
34
+ $ this ->expectDeprecation ('foo ' );
35
+ @trigger_error ('bar ' , E_USER_DEPRECATED );
36
+ }
37
+
38
+ /**
39
+ * Do not remove this test in the next major version.
40
+ *
41
+ * @group legacy
42
+ * @runInSeparateProcess
43
+ */
44
+ public function testOneInIsolation ()
45
+ {
46
+ $ this ->expectDeprecation ('foo ' );
47
+ @trigger_error ('bar ' , E_USER_DEPRECATED );
48
+ }
49
+ }
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Test ExpectDeprecationTrait failing tests
3
+ --FILE--
4
+ <?php
5
+ $ test = realpath (__DIR__ . '/FailTests/ExpectDeprecationTraitTestFail.php ' );
6
+ passthru (getenv ('SYMFONY_SIMPLE_PHPUNIT_BIN_DIR ' ) . '/simple-phpunit --colors=never ' . $ test );
7
+ ?>
8
+ --EXPECTF--
9
+ PHPUnit %s by Sebastian Bergmann and contributors.
10
+
11
+ Testing Symfony\Bridge\PhpUnit\Tests\FailTests\ExpectDeprecationTraitTestFail
12
+ FF 2 / 2 (100%)
13
+
14
+ Time: %s, Memory: %s
15
+
16
+ There were 2 failures:
17
+
18
+ 1) Symfony\Bridge\PhpUnit\Tests\FailTests\ExpectDeprecationTraitTestFail::testOne
19
+ Failed asserting that string matches format description.
20
+ --- Expected
21
+ +++ Actual
22
+ @@ @@
23
+ @expectedDeprecation:
24
+ -%A foo
25
+ + bar
26
+
27
+ 2) Symfony\Bridge\PhpUnit\Tests\FailTests\ExpectDeprecationTraitTestFail::testOneInIsolation
28
+ Failed asserting that string matches format description.
29
+ --- Expected
30
+ +++ Actual
31
+ @@ @@
32
+ @expectedDeprecation:
33
+ -%A foo
34
+ + bar
35
+
36
+ FAILURES!
37
+ Tests: 2, Assertions: 2, Failures: 2.
Original file line number Diff line number Diff line change 134
134
'COMPOSER ' => 'composer.json ' ,
135
135
'COMPOSER_VENDOR_DIR ' => 'vendor ' ,
136
136
'COMPOSER_BIN_DIR ' => 'bin ' ,
137
+ 'SYMFONY_SIMPLE_PHPUNIT_BIN_DIR ' => __DIR__ ,
137
138
];
138
139
139
140
foreach ($ defaultEnvs as $ envName => $ envValue ) {
193
194
'requires ' => ['php ' => '* ' ],
194
195
];
195
196
196
- if (1 === \ count ($ info ['versions ' ])) {
197
+ if (1 === count ($ info ['versions ' ])) {
197
198
$ passthruOrFail ("$ COMPOSER create-project --ignore-platform-reqs --no-install --prefer-dist --no-scripts --no-plugins --no-progress -s dev phpunit/phpunit $ PHPUNIT_VERSION_DIR \"$ PHPUNIT_VERSION .* \"" );
198
199
} else {
199
200
$ passthruOrFail ("$ COMPOSER create-project --ignore-platform-reqs --no-install --prefer-dist --no-scripts --no-plugins --no-progress phpunit/phpunit $ PHPUNIT_VERSION_DIR \"$ PHPUNIT_VERSION .* \"" );
You can’t perform that action at this time.
0 commit comments