Skip to content

Commit 016bd8d

Browse files
committed
Inject ForwardCompatibiliy in TestCase
1 parent f1801a4 commit 016bd8d

File tree

8 files changed

+222
-265
lines changed

8 files changed

+222
-265
lines changed

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
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* @internal
19+
*/
20+
trait PolyfillTestCaseTrait
21+
{
22+
/**
23+
* @param string|string[] $originalClassName
24+
*
25+
* @return MockObject
26+
*/
27+
protected function createMock($originalClassName)
28+
{
29+
$mock = $this->getMockBuilder($originalClassName)
30+
->disableOriginalConstructor()
31+
->disableOriginalClone()
32+
->disableArgumentCloning();
33+
34+
if (method_exists($mock, 'disallowMockingUnknownTypes')) {
35+
$mock = $mock->disallowMockingUnknownTypes();
36+
}
37+
38+
return $mock->getMock();
39+
}
40+
41+
/**
42+
* @param string|string[] $originalClassName
43+
* @param string[] $methods
44+
*
45+
* @return MockObject
46+
*/
47+
protected function createPartialMock($originalClassName, array $methods)
48+
{
49+
$mock = $this->getMockBuilder($originalClassName)
50+
->disableOriginalConstructor()
51+
->disableOriginalClone()
52+
->disableArgumentCloning()
53+
->setMethods(empty($methods) ? null : $methods);
54+
55+
if (method_exists($mock, 'disallowMockingUnknownTypes')) {
56+
$mock = $mock->disallowMockingUnknownTypes();
57+
}
58+
59+
return $mock->getMock();
60+
}
61+
62+
/**
63+
* @param string $exception
64+
*
65+
* @return void
66+
*/
67+
public function expectException($exception)
68+
{
69+
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedException');
70+
$property->setAccessible(true);
71+
$property->setValue($this, $exception);
72+
}
73+
74+
/**
75+
* @param int|string $code
76+
*
77+
* @return void
78+
*/
79+
public function expectExceptionCode($code)
80+
{
81+
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionCode');
82+
$property->setAccessible(true);
83+
$property->setValue($this, $code);
84+
}
85+
86+
/**
87+
* @param string $message
88+
*
89+
* @return void
90+
*/
91+
public function expectExceptionMessage($message)
92+
{
93+
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionMessage');
94+
$property->setAccessible(true);
95+
$property->setValue($this, $message);
96+
}
97+
98+
/**
99+
* @param string $messageRegExp
100+
*
101+
* @return void
102+
*/
103+
public function expectExceptionMessageRegExp($messageRegExp)
104+
{
105+
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionMessageRegExp');
106+
$property->setAccessible(true);
107+
$property->setValue($this, $messageRegExp);
108+
}
109+
}

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