-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9ba2db
commit 97b3278
Showing
9 changed files
with
355 additions
and
27 deletions.
There are no files selected for viewing
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
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,81 @@ | ||
<?php | ||
|
||
namespace phpmock\phpunit; | ||
|
||
use phpmock\generator\MockFunctionGenerator; | ||
use PHPUnit\Framework\MockObject\Invocation; | ||
use PHPUnit\Framework\MockObject\Rule\InvocationOrder; | ||
|
||
/** | ||
* Removes default arguments from the invocation. | ||
* | ||
* @author Markus Malkusch <[email protected]> | ||
* @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations | ||
* @license http://www.wtfpl.net/txt/copying/ WTFPL | ||
* @internal | ||
*/ | ||
class DefaultArgumentRemoverReturnTypes100 extends InvocationOrder | ||
{ | ||
/** | ||
* @SuppressWarnings(PHPMD) | ||
*/ | ||
public function invokedDo(Invocation $invocation): void | ||
{ | ||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD) | ||
*/ | ||
public function matches(Invocation $invocation) : bool | ||
{ | ||
$iClass = class_exists(Invocation::class); | ||
|
||
if ($iClass | ||
|| $invocation instanceof Invocation\StaticInvocation | ||
) { | ||
$this->removeDefaultArguments( | ||
$invocation, | ||
$iClass ? Invocation::class : Invocation\StaticInvocation::class | ||
); | ||
} else { | ||
MockFunctionGenerator::removeDefaultArguments($invocation->parameters); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function verify() : void | ||
{ | ||
} | ||
|
||
/** | ||
* This method is not defined in the interface, but used in | ||
* PHPUnit_Framework_MockObject_InvocationMocker::hasMatchers(). | ||
* | ||
* @return boolean | ||
* @see \PHPUnit_Framework_MockObject_InvocationMocker::hasMatchers() | ||
*/ | ||
public function hasMatchers() | ||
{ | ||
return false; | ||
} | ||
|
||
public function toString() : string | ||
{ | ||
return __CLASS__; | ||
} | ||
|
||
/** | ||
* Remove default arguments from StaticInvocation or its children (hack) | ||
* | ||
* @SuppressWarnings(PHPMD) | ||
*/ | ||
private function removeDefaultArguments(Invocation $invocation, string $class) | ||
{ | ||
$remover = function () { | ||
MockFunctionGenerator::removeDefaultArguments($this->parameters); | ||
}; | ||
|
||
$remover->bindTo($invocation, $class)(); | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
|
||
namespace phpmock\phpunit; | ||
|
||
use phpmock\Deactivatable; | ||
use PHPUnit\Event\Test\Finished; | ||
use PHPUnit\Event\Test\FinishedSubscriber; | ||
|
||
/** | ||
* Test listener for PHPUnit integration. | ||
* | ||
* This class disables mock functions after a test was run. | ||
* | ||
* @author Markus Malkusch <[email protected]> | ||
* @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations | ||
* @license http://www.wtfpl.net/txt/copying/ WTFPL | ||
* @internal | ||
*/ | ||
class MockDisablerPHPUnit10 implements FinishedSubscriber | ||
{ | ||
/** | ||
* @var Deactivatable The function mocks. | ||
*/ | ||
private $deactivatable; | ||
|
||
/** | ||
* Sets the function mocks. | ||
* | ||
* @param Deactivatable $deactivatable The function mocks. | ||
*/ | ||
public function __construct(Deactivatable $deactivatable) | ||
{ | ||
$this->deactivatable = $deactivatable; | ||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD) | ||
*/ | ||
public function notify(Finished $event) : void | ||
{ | ||
$this->deactivatable->disable(); | ||
} | ||
|
||
public function endTest(): void | ||
{ | ||
$this->deactivatable->disable(); | ||
} | ||
} |
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,92 @@ | ||
<?php | ||
|
||
namespace phpmock\phpunit; | ||
|
||
use PHPUnit\Framework\MockObject\Builder\InvocationMocker as BuilderInvocationMocker; | ||
use PHPUnit\Framework\MockObject\InvocationHandler; | ||
use PHPUnit\Framework\MockObject\Rule\InvocationOrder; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use phpmock\integration\MockDelegateFunctionBuilder; | ||
|
||
/** | ||
* Proxy for PHPUnit's PHPUnit_Framework_MockObject_MockObject. | ||
* | ||
* @author Markus Malkusch <[email protected]> | ||
* @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations | ||
* @license http://www.wtfpl.net/txt/copying/ WTFPL | ||
* @internal | ||
*/ | ||
class MockObjectProxyReturnTypes100 implements MockObject | ||
{ | ||
/** | ||
* @var MockObject $mockObject The mock object. | ||
*/ | ||
private $mockObject; | ||
|
||
/** | ||
* Inject the subject. | ||
* | ||
* @param MockObject $mockObject The subject. | ||
*/ | ||
public function __construct(MockObject $mockObject) | ||
{ | ||
$this->mockObject = $mockObject; | ||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD) | ||
*/ | ||
// @codingStandardsIgnoreStart | ||
public function __phpunit_getInvocationHandler(): InvocationHandler | ||
{ | ||
return $this->mockObject->__phpunit_getInvocationHandler(); | ||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD) | ||
*/ | ||
// @codingStandardsIgnoreStart | ||
public function __phpunit_setOriginalObject(object $originalObject) : void | ||
{ | ||
// @codingStandardsIgnoreEnd | ||
$this->mockObject->__phpunit_setOriginalObject($originalObject); | ||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD) | ||
*/ | ||
// @codingStandardsIgnoreStart | ||
public function __phpunit_verify(bool $unsetInvocationMocker = true) : void | ||
{ | ||
// @codingStandardsIgnoreEnd | ||
$this->mockObject->__phpunit_verify($unsetInvocationMocker); | ||
} | ||
|
||
public function expects(InvocationOrder $matcher) : BuilderInvocationMocker | ||
{ | ||
return $this->mockObject->expects($matcher)->method(MockDelegateFunctionBuilder::METHOD); | ||
} | ||
|
||
/** | ||
* This method is not part of the contract but was found in | ||
* PHPUnit's mocked_class.tpl.dist. | ||
* | ||
* @SuppressWarnings(PHPMD) | ||
*/ | ||
// @codingStandardsIgnoreStart | ||
public function __phpunit_hasMatchers() : bool | ||
{ | ||
// @codingStandardsIgnoreEnd | ||
return $this->mockObject->__phpunit_hasMatchers(); | ||
} | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD) | ||
*/ | ||
// @codingStandardsIgnoreStart | ||
public function __phpunit_setReturnValueGeneration(bool $returnValueGeneration) : void | ||
{ | ||
// @codingStandardsIgnoreEnd | ||
$this->mockObject->__phpunit_setReturnValueGeneration($returnValueGeneration); | ||
} | ||
} |
Oops, something went wrong.