Skip to content

Commit f15d762

Browse files
committed
Inject ForwardCompatibiliy in TestCase
1 parent f1801a4 commit f15d762

9 files changed

+242
-264
lines changed

src/Symfony/Bridge/PhpUnit/ForwardCompatTestTrait.php

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,7 @@
1111

1212
namespace Symfony\Bridge\PhpUnit;
1313

14-
use PHPUnit\Framework\TestCase;
15-
16-
// A trait to provide forward compatibility with newest PHPUnit versions
17-
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()) {
26-
trait ForwardCompatTestTrait
27-
{
28-
use Legacy\ForwardCompatTestTraitForV8;
29-
}
30-
} else {
31-
trait ForwardCompatTestTrait
32-
{
33-
use Legacy\ForwardCompatTestTraitForV7;
34-
}
14+
trait ForwardCompatTestTrait
15+
{
16+
use SetUpTearDownTrait;
3517
}

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

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

src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV5.php renamed to src/Symfony/Bridge/PhpUnit/Legacy/PolyfillAssertTrait.php

Lines changed: 1 addition & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -15,106 +15,12 @@
1515
use PHPUnit\Framework\Constraint\LogicalNot;
1616
use PHPUnit\Framework\Constraint\StringContains;
1717
use PHPUnit\Framework\Constraint\TraversableContains;
18-
use PHPUnit\Framework\MockObject\MockObject;
19-
use PHPUnit\Framework\TestCase;
2018

2119
/**
2220
* @internal
2321
*/
24-
trait ForwardCompatTestTraitForV5
22+
trait PolyfillAssertTrait
2523
{
26-
/**
27-
* @return void
28-
*/
29-
public static function setUpBeforeClass()
30-
{
31-
self::doSetUpBeforeClass();
32-
}
33-
34-
/**
35-
* @return void
36-
*/
37-
public static function tearDownAfterClass()
38-
{
39-
self::doTearDownAfterClass();
40-
}
41-
42-
/**
43-
* @return void
44-
*/
45-
protected function setUp()
46-
{
47-
self::doSetUp();
48-
}
49-
50-
/**
51-
* @return void
52-
*/
53-
protected function tearDown()
54-
{
55-
self::doTearDown();
56-
}
57-
58-
private static function doSetUpBeforeClass()
59-
{
60-
parent::setUpBeforeClass();
61-
}
62-
63-
private static function doTearDownAfterClass()
64-
{
65-
parent::tearDownAfterClass();
66-
}
67-
68-
private function doSetUp()
69-
{
70-
parent::setUp();
71-
}
72-
73-
private function doTearDown()
74-
{
75-
parent::tearDown();
76-
}
77-
78-
/**
79-
* @param string|string[] $originalClassName
80-
*
81-
* @return MockObject
82-
*/
83-
protected function createMock($originalClassName)
84-
{
85-
$mock = $this->getMockBuilder($originalClassName)
86-
->disableOriginalConstructor()
87-
->disableOriginalClone()
88-
->disableArgumentCloning();
89-
90-
if (method_exists($mock, 'disallowMockingUnknownTypes')) {
91-
$mock = $mock->disallowMockingUnknownTypes();
92-
}
93-
94-
return $mock->getMock();
95-
}
96-
97-
/**
98-
* @param string|string[] $originalClassName
99-
* @param string[] $methods
100-
*
101-
* @return MockObject
102-
*/
103-
protected function createPartialMock($originalClassName, array $methods)
104-
{
105-
$mock = $this->getMockBuilder($originalClassName)
106-
->disableOriginalConstructor()
107-
->disableOriginalClone()
108-
->disableArgumentCloning()
109-
->setMethods(empty($methods) ? null : $methods);
110-
111-
if (method_exists($mock, 'disallowMockingUnknownTypes')) {
112-
$mock = $mock->disallowMockingUnknownTypes();
113-
}
114-
115-
return $mock->getMock();
116-
}
117-
11824
/**
11925
* @param float $delta
12026
* @param string $message
@@ -320,12 +226,6 @@ public static function assertStringNotContainsStringIgnoringCase($needle, $hayst
320226
*/
321227
public static function assertFinite($actual, $message = '')
322228
{
323-
if (method_exists(TestCase::class, 'assertFinite')) {
324-
parent::assertFinite($actual, $message);
325-
326-
return;
327-
}
328-
329229
static::assertInternalType('float', $actual, $message);
330230
static::assertTrue(is_finite($actual), $message ? $message : "Failed asserting that $actual is finite.");
331231
}
@@ -337,12 +237,6 @@ public static function assertFinite($actual, $message = '')
337237
*/
338238
public static function assertInfinite($actual, $message = '')
339239
{
340-
if (method_exists(TestCase::class, 'assertInfinite')) {
341-
parent::assertInfinite($actual, $message);
342-
343-
return;
344-
}
345-
346240
static::assertInternalType('float', $actual, $message);
347241
static::assertTrue(is_infinite($actual), $message ? $message : "Failed asserting that $actual is infinite.");
348242
}
@@ -354,85 +248,7 @@ public static function assertInfinite($actual, $message = '')
354248
*/
355249
public static function assertNan($actual, $message = '')
356250
{
357-
if (method_exists(TestCase::class, 'assertNan')) {
358-
parent::assertNan($actual, $message);
359-
360-
return;
361-
}
362-
363251
static::assertInternalType('float', $actual, $message);
364252
static::assertTrue(is_nan($actual), $message ? $message : "Failed asserting that $actual is nan.");
365253
}
366-
367-
/**
368-
* @param string $exception
369-
*
370-
* @return void
371-
*/
372-
public function expectException($exception)
373-
{
374-
if (method_exists(TestCase::class, 'expectException')) {
375-
parent::expectException($exception);
376-
377-
return;
378-
}
379-
380-
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedException');
381-
$property->setAccessible(true);
382-
$property->setValue($this, $exception);
383-
}
384-
385-
/**
386-
* @param int|string $code
387-
*
388-
* @return void
389-
*/
390-
public function expectExceptionCode($code)
391-
{
392-
if (method_exists(TestCase::class, 'expectExceptionCode')) {
393-
parent::expectExceptionCode($code);
394-
395-
return;
396-
}
397-
398-
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionCode');
399-
$property->setAccessible(true);
400-
$property->setValue($this, $code);
401-
}
402-
403-
/**
404-
* @param string $message
405-
*
406-
* @return void
407-
*/
408-
public function expectExceptionMessage($message)
409-
{
410-
if (method_exists(TestCase::class, 'expectExceptionMessage')) {
411-
parent::expectExceptionMessage($message);
412-
413-
return;
414-
}
415-
416-
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionMessage');
417-
$property->setAccessible(true);
418-
$property->setValue($this, $message);
419-
}
420-
421-
/**
422-
* @param string $messageRegExp
423-
*
424-
* @return void
425-
*/
426-
public function expectExceptionMessageRegExp($messageRegExp)
427-
{
428-
if (method_exists(TestCase::class, 'expectExceptionMessageRegExp')) {
429-
parent::expectExceptionMessageRegExp($messageRegExp);
430-
431-
return;
432-
}
433-
434-
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionMessageRegExp');
435-
$property->setAccessible(true);
436-
$property->setValue($this, $messageRegExp);
437-
}
438254
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy