Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge branch '4.4'
* 4.4: Inject ForwardCompatibiliy in TestCase
- Loading branch information
Showing
8 changed files
with
222 additions
and
265 deletions.
There are no files selected for viewing
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
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.