Skip to content

Added PHPUnit 6.5 to Travis CI config #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ env:
- PHPUNIT_VERSION=~6.2.0
- PHPUNIT_VERSION=~6.3.0
- PHPUNIT_VERSION=~6.4.0
- PHPUNIT_VERSION=~6.5.0

php:
- 7.2
- 7.1
- 7.0
- hhvm
Expand Down
29 changes: 29 additions & 0 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

if (! interface_exists(\PHPUnit\Framework\MockObject\Matcher\Invocation::class)) {
class_alias(
\PHPUnit_Framework_MockObject_Matcher_Invocation::class,
\PHPUnit\Framework\MockObject\Matcher\Invocation::class
);
}

if (! interface_exists(\PHPUnit\Framework\MockObject\Invocation::class)) {
class_alias(
\PHPUnit_Framework_MockObject_Invocation::class,
\PHPUnit\Framework\MockObject\Invocation::class
);
}

if (! interface_exists(\PHPUnit\Framework\MockObject\MockObject::class)) {
class_alias(
\PHPUnit_Framework_MockObject_MockObject::class,
\PHPUnit\Framework\MockObject\MockObject::class
);
}

if (! class_exists(\PHPUnit\Framework\MockObject\Builder\InvocationMocker::class)) {
class_alias(
\PHPUnit_Framework_MockObject_Builder_InvocationMocker::class,
\PHPUnit\Framework\MockObject\Builder\InvocationMocker::class
);
}
29 changes: 25 additions & 4 deletions classes/DefaultArgumentRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace phpmock\phpunit;

use phpmock\generator\MockFunctionGenerator;
use PHPUnit\Framework\MockObject\Invocation;
use PHPUnit\Framework\MockObject\Matcher\Invocation as InvocationInterface;

/**
* Removes default arguments from the invocation.
Expand All @@ -12,22 +14,41 @@
* @license http://www.wtfpl.net/txt/copying/ WTFPL
* @internal
*/
class DefaultArgumentRemover implements \PHPUnit_Framework_MockObject_Matcher_Invocation
class DefaultArgumentRemover implements InvocationInterface
{

/**
* @SuppressWarnings(PHPMD)
*/
public function invoked(\PHPUnit_Framework_MockObject_Invocation $invocation)
public function invoked(Invocation $invocation)
{
}

/**
* @SuppressWarnings(PHPMD)
*/
public function matches(\PHPUnit_Framework_MockObject_Invocation $invocation)
public function matches(Invocation $invocation)
{
MockFunctionGenerator::removeDefaultArguments($invocation->parameters);
$r = new \ReflectionObject($invocation);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's nice as a work around but not sustainable. Relying on implementation details can break at any upstream patch release. I try to get a public interface for that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was the only possible solution in current situation. If the public interface change then we can improve this part.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. I just wanted to give you some context why I closed this PR so that you won't get frustrated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's your library, you can do whatever you want ! :)

I would consider release v2.1 with support PHPUnit 6.5+ only and everyone will be happy 😄
Of course, still there will be the same issue, and only reflection will be the way to that...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider release v2.1 with support PHPUnit 6.5+ only

Ah that's still a little fuck up. Unfortunaltey I have to make a further 2.0 release which supports 6.5 otherwise 2.0 is broken.

$method = $r->hasMethod('getParameters');

if ($method) {
$params = $invocation->getParameters();
} else {
$params = &$invocation->parameters;
}

MockFunctionGenerator::removeDefaultArguments($params);

if ($method) {
while (! $r->hasProperty('parameters')) {
$r = $r->getParentClass();
}
$p = $r->getProperty('parameters');
$p->setAccessible(true);
$p->setValue($invocation, $params);
}

return false;
}

Expand Down
5 changes: 3 additions & 2 deletions classes/MockObjectProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace phpmock\phpunit;

use PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit\Framework\MockObject\Matcher\Invocation;
use PHPUnit\Framework\MockObject\MockObject;
use phpmock\integration\MockDelegateFunctionBuilder;

/**
Expand Down Expand Up @@ -61,7 +62,7 @@ public function __phpunit_verify()
return $this->mockObject->__phpunit_verify();
}

public function expects(\PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
public function expects(Invocation $matcher)
{
return $this->mockObject->expects($matcher)->method(MockDelegateFunctionBuilder::METHOD);
}
Expand Down
5 changes: 3 additions & 2 deletions classes/PHPMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use phpmock\integration\MockDelegateFunctionBuilder;
use phpmock\MockBuilder;
use phpmock\Deactivatable;
use PHPUnit\Framework\MockObject\MockObject;

/**
* Adds building a function mock functionality into \PHPUnit\Framework\TestCase.
Expand Down Expand Up @@ -42,7 +43,7 @@ trait PHPMock
* This method exists in \PHPUnit\Framework\TestCase.
*
* @param string $className Name of the class to mock.
* @return \PHPUnit_Framework_MockObject_MockBuilder
* @return \PHPUnit\Framework\MockObject\MockBuilder
* @see \PHPUnit\Framework\TestCase::getMockBuilder()
* @internal
*/
Expand All @@ -67,7 +68,7 @@ abstract protected function getTestResultObject();
* @param string $namespace The function namespace.
* @param string $name The function name.
*
* @return \PHPUnit_Framework_MockObject_MockObject The PHPUnit mock.
* @return MockObject The PHPUnit mock.
*/
public function getFunctionMock($namespace, $name)
{
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
}
],
"autoload": {
"files": ["autoload.php"],
"psr-4": {"phpmock\\phpunit\\": "classes/"}
},
"require": {
Expand Down
12 changes: 7 additions & 5 deletions tests/MockObjectProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace phpmock\phpunit;

use \PHPUnit_Framework_MockObject_Builder_InvocationMocker as InvocationMocker;
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
use PHPUnit\Framework\MockObject\Matcher\Invocation;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use phpmock\integration\MockDelegateFunctionBuilder;

Expand All @@ -25,13 +27,13 @@ class MockObjectProxyTest extends TestCase
*/
public function testExpects()
{
$matcher = $this->getMockBuilder(\PHPUnit_Framework_MockObject_Matcher_Invocation::class)->getMock();
$matcher = $this->getMockBuilder(Invocation::class)->getMock();

$invocationMocker = $this->getMockBuilder(InvocationMocker::class)->disableOriginalConstructor()->getMock();
$invocationMocker->expects($this->once())->method("method")
->with(MockDelegateFunctionBuilder::METHOD)->willReturn($invocationMocker);

$prophecy = $this->prophesize(\PHPUnit_Framework_MockObject_MockObject::class);
$prophecy = $this->prophesize(MockObject::class);
$prophecy->expects($matcher)->willReturn($invocationMocker);
$mock = $prophecy->reveal();

Expand All @@ -53,7 +55,7 @@ public function testExpects()
*/
public function testHasMatcher()
{
$prophecy = $this->prophesize(\PHPUnit_Framework_MockObject_MockObject::class);
$prophecy = $this->prophesize(MockObject::class);
$prophecy->__phpunit_hasMatchers()->willReturn("foo");
$mock = $prophecy->reveal();

Expand All @@ -74,7 +76,7 @@ public function testHasMatcher()
*/
public function testProxiedMethods($method, array $arguments = [], $expected = "foo")
{
$prophecy = $this->prophesize(\PHPUnit_Framework_MockObject_MockObject::class);
$prophecy = $this->prophesize(MockObject::class);
call_user_func_array([$prophecy, $method], $arguments)->willReturn($expected);
$mock = $prophecy->reveal();

Expand Down