Skip to content

Commit

Permalink
Merge branch 'feature/40-phpunit-8.4'
Browse files Browse the repository at this point in the history
Close #40
Fix #39
  • Loading branch information
michalbundyra committed Oct 5, 2019
2 parents 04f78fe + dc012f0 commit 7df4bd1
Show file tree
Hide file tree
Showing 14 changed files with 290 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.phpunit.result.cache
vendor/
composer.lock
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ cache:

env:
- PHPUNIT_VERSION=dev-master
- PHPUNIT_VERSION=~8.4.0
- PHPUNIT_VERSION=~8.3.0
- PHPUNIT_VERSION=~8.2.0
- PHPUNIT_VERSION=~8.1.0
- PHPUNIT_VERSION=~8.0.0
Expand Down Expand Up @@ -36,6 +38,10 @@ matrix:
exclude:
- php: 7.1
env: PHPUNIT_VERSION=dev-master
- php: 7.1
env: PHPUNIT_VERSION=~8.4.0
- php: 7.1
env: PHPUNIT_VERSION=~8.3.0
- php: 7.1
env: PHPUNIT_VERSION=~8.2.0
- php: 7.1
Expand All @@ -44,6 +50,10 @@ matrix:
env: PHPUNIT_VERSION=~8.0.0
- php: 7
env: PHPUNIT_VERSION=dev-master
- php: 7
env: PHPUNIT_VERSION=~8.4.0
- php: 7
env: PHPUNIT_VERSION=~8.3.0
- php: 7
env: PHPUNIT_VERSION=~8.2.0
- php: 7
Expand Down
27 changes: 24 additions & 3 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php

if (! interface_exists(\PHPUnit\Framework\MockObject\Matcher\Invocation::class)) {
if (class_exists(\PHPUnit\Framework\MockObject\Rule\InvocationOrder::class)) {
class_alias(
\PHPUnit\Framework\MockObject\Rule\InvocationOrder::class,
\PHPUnit\Framework\MockObject\Matcher\Invocation::class
);
} elseif (! interface_exists(\PHPUnit\Framework\MockObject\Matcher\Invocation::class)) {
class_alias(
\PHPUnit_Framework_MockObject_Matcher_Invocation::class,
\PHPUnit\Framework\MockObject\Matcher\Invocation::class
Expand Down Expand Up @@ -30,21 +35,32 @@ class_alias(
);
}

if (class_exists(\PHPUnit\Framework\MockObject\Rule\MethodName::class)) {
class_alias(
\PHPUnit\Framework\MockObject\Rule\MethodName::class,
\PHPUnit\Framework\MockObject\Matcher\MethodName::class
);
}

if (! class_exists(\PHPUnit\Framework\MockObject\Matcher\MethodName::class)) {
class_alias(
\PHPUnit_Framework_MockObject_Matcher_MethodName::class,
\PHPUnit\Framework\MockObject\Matcher\MethodName::class
);
}

if (! interface_exists(\PHPUnit\Framework\MockObject\Stub\MatcherCollection::class)) {
if (!class_exists(\PHPUnit\Framework\MockObject\InvocationHandler::class)
&& !interface_exists(\PHPUnit\Framework\MockObject\Stub\MatcherCollection::class)
) {
class_alias(
\PHPUnit_Framework_MockObject_Stub_MatcherCollection::class,
\PHPUnit\Framework\MockObject\Stub\MatcherCollection::class
);
}

if (! class_exists(\PHPUnit\Framework\MockObject\InvocationMocker::class)) {
if (!class_exists(\PHPUnit\Framework\MockObject\InvocationHandler::class)
&& !class_exists(\PHPUnit\Framework\MockObject\InvocationMocker::class)
) {
class_alias(
\PHPUnit_Framework_MockObject_InvocationMocker::class,
\PHPUnit\Framework\MockObject\InvocationMocker::class
Expand All @@ -65,6 +81,11 @@ class_alias(
}

if (class_exists(\PHPUnit\Runner\Version::class)
&& version_compare(\PHPUnit\Runner\Version::id(), '8.4.0') >= 0
) {
class_alias(\phpmock\phpunit\DefaultArgumentRemoverReturnTypes84::class, \phpmock\phpunit\DefaultArgumentRemover::class);
class_alias(\phpmock\phpunit\MockObjectProxyReturnTypes84::class, \phpmock\phpunit\MockObjectProxy::class);
} elseif (class_exists(\PHPUnit\Runner\Version::class)
&& version_compare(\PHPUnit\Runner\Version::id(), '8.1.0') >= 0
) {
class_alias(\phpmock\phpunit\DefaultArgumentRemoverReturnTypes::class, \phpmock\phpunit\DefaultArgumentRemover::class);
Expand Down
1 change: 0 additions & 1 deletion classes/DefaultArgumentRemoverNoReturnTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
class DefaultArgumentRemoverNoReturnTypes implements InvocationInterface
{

/**
* @SuppressWarnings(PHPMD)
*/
Expand Down
5 changes: 2 additions & 3 deletions classes/DefaultArgumentRemoverReturnTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
class DefaultArgumentRemoverReturnTypes implements InvocationInterface
{

/**
* @SuppressWarnings(PHPMD)
*/
Expand All @@ -31,8 +30,8 @@ public function matches(Invocation $invocation) : bool
{
$iClass = class_exists(Invocation::class);

if ($invocation instanceof Invocation\StaticInvocation
|| $iClass
if ($iClass
|| $invocation instanceof Invocation\StaticInvocation
) {
$this->removeDefaultArguments(
$invocation,
Expand Down
81 changes: 81 additions & 0 deletions classes/DefaultArgumentRemoverReturnTypes84.php
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 DefaultArgumentRemoverReturnTypes84 extends InvocationOrder
{
/**
* @SuppressWarnings(PHPMD)
*/
public function invokedDo(Invocation $invocation)
{
}

/**
* @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)();
}
}
1 change: 0 additions & 1 deletion classes/MockDisablerPHPUnit6.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
class MockDisablerPHPUnit6 extends BaseTestListener
{

/**
* @var Deactivatable The function mocks.
*/
Expand Down
1 change: 0 additions & 1 deletion classes/MockDisablerPHPUnit7.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
class MockDisablerPHPUnit7 extends BaseTestListener
{

/**
* @var Deactivatable The function mocks.
*/
Expand Down
1 change: 0 additions & 1 deletion classes/MockObjectProxyNoReturnTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
class MockObjectProxyNoReturnTypes implements MockObject
{

/**
* @var MockObject $mockObject The mock object.
*/
Expand Down
5 changes: 2 additions & 3 deletions classes/MockObjectProxyReturnTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
*/
class MockObjectProxyReturnTypes implements MockObject
{

/**
* @var MockObject $mockObject The mock object.
*/
private $mockObject;

/**
* Inject the subject.
*
Expand All @@ -33,7 +32,7 @@ public function __construct(MockObject $mockObject)
{
$this->mockObject = $mockObject;
}

/**
* @SuppressWarnings(PHPMD)
*/
Expand Down
92 changes: 92 additions & 0 deletions classes/MockObjectProxyReturnTypes84.php
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 MockObjectProxyReturnTypes84 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($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);
}
}
Loading

0 comments on commit 7df4bd1

Please sign in to comment.