-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor #32882 [PhpUnitBridge] Inject ForwardCompatibiliy in TestCase (…
…jderusse) This PR was merged into the 4.4 branch. Discussion ---------- [PhpUnitBridge] Inject ForwardCompatibiliy in TestCase | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | not yet | Fixed tickets | #32844 | License | MIT | Doc PR | NA This PR replace the previous trait `ForwardCompatTestTrait` by injecting forward compatibility code in phpunit itself which allow to use the polyfill methods in tests without changing the code. when using `simple_phpunit` the env variable `$PHPUNIT_REMOVE_RETURN_TYPEHINT=1` (default 0) removes the `: void` typehint in public and protected methods (allow to use 7.4 8 in 3.4 branch) note: once merged, all tests have to be fixed. see #32889 Commits ------- 016bd8d Inject ForwardCompatibiliy in TestCase
- Loading branch information
Showing
8 changed files
with
222 additions
and
265 deletions.
There are no files selected for viewing
50 changes: 0 additions & 50 deletions
50
src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV7.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/Symfony/Bridge/PhpUnit/Legacy/PolyfillTestCaseTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\PhpUnit\Legacy; | ||
|
||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
trait PolyfillTestCaseTrait | ||
{ | ||
/** | ||
* @param string|string[] $originalClassName | ||
* | ||
* @return MockObject | ||
*/ | ||
protected function createMock($originalClassName) | ||
{ | ||
$mock = $this->getMockBuilder($originalClassName) | ||
->disableOriginalConstructor() | ||
->disableOriginalClone() | ||
->disableArgumentCloning(); | ||
|
||
if (method_exists($mock, 'disallowMockingUnknownTypes')) { | ||
$mock = $mock->disallowMockingUnknownTypes(); | ||
} | ||
|
||
return $mock->getMock(); | ||
} | ||
|
||
/** | ||
* @param string|string[] $originalClassName | ||
* @param string[] $methods | ||
* | ||
* @return MockObject | ||
*/ | ||
protected function createPartialMock($originalClassName, array $methods) | ||
{ | ||
$mock = $this->getMockBuilder($originalClassName) | ||
->disableOriginalConstructor() | ||
->disableOriginalClone() | ||
->disableArgumentCloning() | ||
->setMethods(empty($methods) ? null : $methods); | ||
|
||
if (method_exists($mock, 'disallowMockingUnknownTypes')) { | ||
$mock = $mock->disallowMockingUnknownTypes(); | ||
} | ||
|
||
return $mock->getMock(); | ||
} | ||
|
||
/** | ||
* @param string $exception | ||
* | ||
* @return void | ||
*/ | ||
public function expectException($exception) | ||
{ | ||
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedException'); | ||
$property->setAccessible(true); | ||
$property->setValue($this, $exception); | ||
} | ||
|
||
/** | ||
* @param int|string $code | ||
* | ||
* @return void | ||
*/ | ||
public function expectExceptionCode($code) | ||
{ | ||
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionCode'); | ||
$property->setAccessible(true); | ||
$property->setValue($this, $code); | ||
} | ||
|
||
/** | ||
* @param string $message | ||
* | ||
* @return void | ||
*/ | ||
public function expectExceptionMessage($message) | ||
{ | ||
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionMessage'); | ||
$property->setAccessible(true); | ||
$property->setValue($this, $message); | ||
} | ||
|
||
/** | ||
* @param string $messageRegExp | ||
* | ||
* @return void | ||
*/ | ||
public function expectExceptionMessageRegExp($messageRegExp) | ||
{ | ||
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionMessageRegExp'); | ||
$property->setAccessible(true); | ||
$property->setValue($this, $messageRegExp); | ||
} | ||
} |
Oops, something went wrong.