8000 Merge branch '3.4' into 4.3 · symfony/symfony@9bfc12a · GitHub
[go: up one dir, main page]

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

Appearance settings

Commit 9bfc12a

Browse files
Merge branch '3.4' into 4.3
* 3.4: [Yaml] fix test for PHP 7.4 Add polyfill for TestCase::createMock() Skip tests that fatal-error on PHP 7.4 because of missing parent classes
2 parents 1938a54 + 9f40b10 commit 9bfc12a

File tree

12 files changed

+123
-14
lines changed

12 files changed

+123
-14
lines changed

src/Symfony/Bridge/PhpUnit/ForwardCompatTestTrait.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@
1515

1616
// A trait to provide forward compatibility with newest PHPUnit versions
1717

18-
if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) {
18+
$r = new \ReflectionClass(TestCase::class);
19+
20+
if (\PHP_VERSION_ID < 70000 || !$r->hasMethod('createMock') || !$r->getMethod('createMock')->hasReturnType()) {
21+
trait ForwardCompatTestTrait
22+
{
23+
use Legacy\ForwardCompatTestTraitForV5;
24+
}
25+
} elseif ($r->getMethod('tearDown')->hasReturnType()) {
1926
trait ForwardCompatTestTrait
2027
{
2128
use Legacy\ForwardCompatTestTraitForV8;
2229
}
2330
} else {
2431
trait ForwardCompatTestTrait
2532
{
26-
use Legacy\ForwardCompatTestTraitForV5;
33+
use Legacy\ForwardCompatTestTraitForV7;
2734
}
2835
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Bridge\PhpUnit\Legacy;
1313

14+
use PHPUnit\Framework\MockObject\MockObject;
15+
1416
/**
1517
* @internal
1618
*/
@@ -80,6 +82,25 @@ private function doTearDown()
8082
parent::tearDown();
8183
}
8284

85+
/**
86+
* @param string $originalClassName
87+
*
88+
* @return MockObject
89+
*/
90+
protected function createMock($originalClassName)
91+
{
92+
$mock = $this->getMockBuilder($originalClassName)
93+
->disableOriginalConstructor()
94+
->disableOriginalClone()
95+
->disableArgumentCloning();
96+
97+
if (method_exists($mock, 'disallowMockingUnknownTypes')) {
98+
$mock = $mock->disallowMockingUnknownTypes();
99+
}
100+
101+
return $mock->getMock();
102+
}
103+
83104
/**
84105
* @param string $message
85106
*
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 PHPUnit\Framework\MockObject\MockObject;
15+
16+
/**
17+
* @internal
18+
*/
19+
trait ForwardCompatTestTraitForV7
20+
{
21+
use ForwardCompatTestTraitForV5;
22+
23+
/**
24+
* @param string|string[] $originalClassName
25+
*/
26+
protected function createMock($originalClassName): MockObject
27+
{
28+
return $this->getMockBuilder($originalClassName)
29+
->disableOriginalConstructor()
30+
->disableOriginalClone()
31+
->disableArgumentCloning()
32+
->disallowMockingUnknownTypes()
33+
->getMock();
34+
}
35+
}

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer;
1313

14+
use PHPUnit\Framework\Warning;
1415
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Bundle\FrameworkBundle\CacheWarmer\ValidatorCacheWarmer;
1617
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
@@ -25,6 +26,10 @@ class ValidatorCacheWarmerTest extends TestCase
2526

2627
public function testWarmUp()
2728
{
29+
if (\PHP_VERSION_ID >= 70400) {
30+
throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.');
31+
}
32+
2833
$validatorBuilder = new ValidatorBuilder();
2934
$validatorBuilder->addXmlMapping(__DIR__.'/../Fixtures/Validation/Resources/person.xml');
3035
$validatorBuilder->addYamlMapping(__DIR__.'/../Fixtures/Validation/Resources/author.yml');

src/Symfony/Component/Config/Tests/Resource/ClassExistenceResourceTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Config\Tests\Resource;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use PHPUnit\Framework\Warning;
1516
use Symfony\Component\Config\Resource\ClassExistenceResource;
1617
use Symfony\Component\Config\Tests\Fixtures\BadParent;
1718
use Symfony\Component\Config\Tests\Fixtures\Resource\ConditionalClass;
@@ -77,6 +78,10 @@ public function testExistsKo()
7778

7879
public function testBadParentWithTimestamp()
7980
{
81+
if (\PHP_VERSION_ID >= 70400) {
82+
throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.');
83+
}
84+
8085
$res = new ClassExistenceResource(BadParent::class, false);
8186
$this->assertTrue($res->isFresh(time()));
8287
}
@@ -87,6 +92,10 @@ public function testBadParentWithTimestamp()
8792
*/
8893
public function testBadParentWithNoTimestamp()
8994
{
95+
if (\PHP_VERSION_ID >= 70400) {
96+
throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.');
97+
}
98+
9099
$res = new ClassExistenceResource(BadParent::class, false);
91100
$res->isFresh(0);
92101
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use PHPUnit\Framework\Warning;
1516
use Psr\Log\LoggerInterface;
1617
use Psr\Log\NullLogger;
1718
use Symfony\Component\Config\FileLocator;
@@ -353,6 +354,10 @@ public function testClassNotFoundThrowsException()
353354
*/
354355
public function testParentClassNotFoundThrowsException()
355356
{
357+
if (\PHP_VERSION_ID >= 70400) {
358+
throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.');
359+
}
360+
356361
$container = new ContainerBuilder();
357362

358363
$aDefinition = $container->register('a', __NAMESPACE__.'\BadParentTypeHintedArgument');
@@ -618,6 +623,10 @@ public function getCreateResourceTests()
618623

619624
public function testIgnoreServiceWithClassNotExisting()
620625
{
626+
if (\PHP_VERSION_ID >= 70400) {
627+
throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.');
628+
}
629+
621630
$container = new ContainerBuilder();
622631

623632
$container->register('class_not_exist', __NAMESPACE__.'\OptionalServiceClass');
@@ -823,6 +832,10 @@ public function testExceptionWhenAliasExists()
823832
*/
824833
public function testExceptionWhenAliasDoesNotExist()
825834
{
835+
if (\PHP_VERSION_ID >= 70400) {
836+
throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.');
837+
}
838+
826839
$container = new ContainerBuilder();
827840

828841
// multiple I instances... but no IInterface alias

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use PHPUnit\Framework\Warning;
1516
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
1617
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
1718
use Symfony\Component\DependencyInjection\Compiler\ResolveBindingsPass;
@@ -69,6 +70,10 @@ public function testUnusedBinding()
6970
*/
7071
public function testMissingParent()
7172
{
73+
if (\PHP_VERSION_ID >= 70400) {
74+
throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.');
75+
}
76+
7277
$container = new ContainerBuilder();
7378

7479
$definition = $container->register(ParentNotExists::class, ParentNotExists::class);

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Dumper;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use PHPUnit\Framework\Warning;
1516
use Psr\Container\ContainerInterface;
1617
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1718
use Symfony\Component\Config\FileLocator;
@@ -1060,6 +1061,10 @@ public function testInlineSelfRef()
10601061

10611062
public function testHotPathOptimizations()
10621063
{
1064+
if (\PHP_VERSION_ID >= 70400) {
1065+
throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.');
1066+
}
1067+
10631068
$container = include self::$fixturesPath.'/containers/container_inline_requires.php';
10641069
$container->setParameter('inline_requires', true);
10651070
$container->compile();

src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Loader;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use PHPUnit\Framework\Warning;
1516
use Psr\Container\ContainerInterface as PsrContainerInterface;
1617
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1718
use Symfony\Component\Config\FileLocator;
@@ -111,6 +112,10 @@ public function testRegisterClasses()
111112

112113
public function testRegisterClassesWithExclude()
113114
{
115+
if (\PHP_VERSION_ID >= 70400) {
116+
throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.');
117+
}
118+
114119
$container = new ContainerBuilder();
115120
$container->setParameter('other_dir', 'OtherDir');
116121
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));
@@ -159,6 +164,10 @@ public function testRegisterClassesWithExcludeAsArray()
159164

160165
public function testNestedRegisterClasses()
161166
{
167+
if (\PHP_VERSION_ID >= 70400) {
168+
throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.');
169+
}
170+
162171
$container = new ContainerBuilder();
163172
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));
164173

@@ -187,6 +196,10 @@ public function testNestedRegisterClasses()
187196

188197
public function testMissingParentClass()
189198
{
199+
if (\PHP_VERSION_ID >= 70400) {
200+
throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.');
201+
}
202+
190203
$container = new ContainerBuilder();
191204
$container->setParameter('bad_classes_dir', 'BadClasses');
192205
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));

src/Symfony/Component/Validator/Tests/DataCollector/ValidatorDataCollectorTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Validator\Tests\DataCollector;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Validator\ConstraintViolation;
1617
use Symfony\Component\Validator\ConstraintViolationList;
1718
use Symfony\Component\Validator\DataCollector\ValidatorDataCollector;
@@ -20,6 +21,8 @@
2021

2122
class ValidatorDataCollectorTest extends TestCase
2223
{
24+
use ForwardCompatTestTrait;
25+
2326
public function testCollectsValidatorCalls()
2427
{
2528
$originalValidator = $this->createMock(ValidatorInterface::class);
@@ -71,9 +74,4 @@ public function testReset()
7174
$this->assertCount(0, $collector->getCalls());
7275
$this->assertSame(0, $collector->getViolationsCount());
7376
}
74-
75-
protected function createMock($classname)
76-
{
77-
return $this->getMockBuilder($classname)->disableOriginalConstructor()->getMock();
78-
}
7977
}

src/Symfony/Component/Validator/Tests/Validator/TraceableValidatorTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Validator\Tests\Validator;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Validator\Constraint;
1617
use Symfony\Component\Validator\ConstraintViolation;
1718
use Symfony\Component\Validator\ConstraintViolationList;
@@ -23,6 +24,8 @@
2324

2425
class TraceableValidatorTest extends TestCase
2526
{
27+
use ForwardCompatTestTrait;
28+
2629
public function testValidate()
2730
{
2831
$originalValidator = $this->createMock(ValidatorInterface::class);
@@ -95,9 +98,4 @@ public function testForwardsToOriginalValidator()
9598
$expects('validatePropertyValue')->willReturn($expected = new ConstraintViolationList());
9699
$this->assertSame($expected, $validator->validatePropertyValue(new \stdClass(), 'property', 'value'), 'returns original validator validatePropertyValue() result');
97100
}
98-
99-
protected function createMock($classname)
100-
{
101-
return $this->getMockBuilder($classname)->disableOriginalConstructor()->getMock();
102-
}
103101
}

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ class ParserTest extends TestCase
2525
/** @var Parser */
2626
protected $parser;
2727

28-
protected function setUp(): void
28+
private function doSetUp()
2929
{
3030
$this->parser = new Parser();
3131
}
3232

33-
protected function tearDown(): void
33+
private function doTearDown()
3434
{
3535
$this->parser = null;
3636

0 commit comments

Comments
 (0)
0