Skip to content

Commit 98f6f0b

Browse files
Merge branch '4.4'
* 4.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 762104b + 2583f32 commit 98f6f0b

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

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
}

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 <[email protected]>
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+
}

0 commit comments

Comments
 (0)