Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0a0627a

Browse files
Added support for PHPUnit 6.5 and 7.0
1 parent b42fc41 commit 0a0627a

File tree

10 files changed

+154
-39
lines changed

10 files changed

+154
-39
lines changed

‎.travis.yml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ env:
1313
- PHPUNIT_VERSION=~6.2.0
1414
- PHPUNIT_VERSION=~6.3.0
1515
- PHPUNIT_VERSION=~6.4.0
16+
- PHPUNIT_VERSION=~6.5.0
17+
- PHPUNIT_VERSION=~7.0.0
1618

1719
php:
1820
- 7.2
@@ -22,6 +24,11 @@ php:
2224

2325
matrix:
2426
fast_finish: true
27+
exclude:
28+
- php: 7.0
29+
env: PHPUNIT_VERSION=dev-master
30+
- php: 7.0
31+
env: PHPUNIT_VERSION=~7.0.0
2532
allow_failures:
2633
- php: hhvm
2734
- env: PHPUNIT_VERSION=dev-master

‎autoload.php‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
if (! interface_exists(\PHPUnit\Framework\MockObject\Matcher\Invocation::class)) {
4+
class_alias(
5+
\PHPUnit_Framework_MockObject_Matcher_Invocation::class,
6+
\PHPUnit\Framework\MockObject\Matcher\Invocation::class
7+
);
8+
}
9+
10+
if (! interface_exists(\PHPUnit\Framework\MockObject\Invocation::class)) {
11+
class_alias(
12+
\PHPUnit_Framework_MockObject_Invocation::class,
13+
\PHPUnit\Framework\MockObject\Invocation::class
14+
);
15+
}
16+
17+
if (! interface_exists(\PHPUnit\Framework\MockObject\MockObject::class)) {
18+
class_alias(
19+
\PHPUnit_Framework_MockObject_MockObject::class,
20+
\PHPUnit\Framework\MockObject\MockObject::class
21+
);
22+
}
23+
24+
if (! class_exists(\PHPUnit\Framework\MockObject\Builder\InvocationMocker::class)) {
25+
class_alias(
26+
\PHPUnit_Framework_MockObject_Builder_InvocationMocker::class,
27+
\PHPUnit\Framework\MockObject\Builder\InvocationMocker::class
28+
);
29+
}
30+
31+
if (! class_exists(\PHPUnit\Framework\BaseTestListener::class)) {
32+
include __DIR__ . '/compatibility/BaseTestListener.php';
33+
class_alias(
34+
phpmock\phpunit\MockDisablerPHPUnit7::class,
35+
phpmock\phpunit\MockDisabler::class
36+
);
37+
} else {
38+
class_alias(
39+
phpmock\phpunit\MockDisablerPHPUnit6::class,
40+
phpmock\phpunit\MockDisabler::class
41+
);
42+
}

‎classes/DefaultArgumentRemover.php‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace phpmock\phpunit;
44

55
use phpmock\generator\MockFunctionGenerator;
6+
use PHPUnit\Framework\MockObject\Invocation;
7+
use PHPUnit\Framework\MockObject\Matcher\Invocation as InvocationInterface;
68

79
/**
810
* Removes default arguments from the invocation.
@@ -12,22 +14,27 @@
1214
* @license http://www.wtfpl.net/txt/copying/ WTFPL
1315
* @internal
1416
*/
15-
class DefaultArgumentRemover implements \PHPUnit_Framework_MockObject_Matcher_Invocation
17+
class DefaultArgumentRemover implements InvocationInterface
1618
{
1719

1820
/**
1921
* @SuppressWarnings(PHPMD)
2022
*/
21-
public function invoked(\PHPUnit_Framework_MockObject_Invocation $invocation)
23+
public function invoked(Invocation $invocation)
2224
{
2325
}
2426

2527
/**
2628
* @SuppressWarnings(PHPMD)
2729
*/
28-
public function matches(\PHPUnit_Framework_MockObject_Invocation $invocation)
30+
public function matches(Invocation $invocation)
2931
{
30-
MockFunctionGenerator::removeDefaultArguments($invocation->parameters);
32+
if ($invocation instanceof Invocation\StaticInvocation) {
33+
$this->removeDefaultArguments($invocation);
34+
} else {
35+
MockFunctionGenerator::removeDefaultArguments($invocation->parameters);
36+
}
37+
3138
return false;
3239
}
3340

@@ -47,8 +54,22 @@ public function hasMatchers()
4754
return false;
4855
}
4956

50-
public function toString()
57+
public function toString() : string
5158
{
5259
return __CLASS__;
5360
}
61+
62+
/**
63+
* Remove default arguments from StaticInvocation or its children (hack)
64+
*
65+
* @SuppressWarnings(PHPMD)
66+
*/
67+
private function removeDefaultArguments(Invocation\StaticInvocation $invocation): void
68+
{
69+
$remover = function () {
70+
MockFunctionGenerator::removeDefaultArguments($this->parameters);
71+
};
72+
73+
$remover->bindTo($invocation, Invocation\StaticInvocation::class)();
74+
}
5475
}

‎classes/MockDisabler.php‎ renamed to ‎classes/MockDisablerPHPUnit6.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @license http://www.wtfpl.net/txt/copying/ WTFPL
1717
* @internal
1818
*/
19-
class MockDisabler extends BaseTestListener
19+
class MockDisablerPHPUnit6 extends BaseTestListener
2020
{
2121

2222
/**

‎classes/MockDisablerPHPUnit7.php‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace phpmock\phpunit;
4+
5+
use phpmock\Deactivatable;
6+
use PHPUnit\Framework\BaseTestListener;
7+
use PHPUnit\Framework\Test;
8+
9+
/**
10+
* Test listener for PHPUnit integration.
11+
*
12+
* This class disables mock functions after a test was run.
13+
*
14+
* @author Markus Malkusch <markus@malkusch.de>
15+
* @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations
16+
* @license http://www.wtfpl.net/txt/copying/ WTFPL
17+
* @internal
18+
*/
19+
class MockDisablerPHPUnit7 extends BaseTestListener
20+
{
21+
22+
/**
23+
* @var Deactivatable The function mocks.
24+
*/
25+
private $deactivatable;
26+
27+
/**
28+
* Sets the function mocks.
29+
*
30+
* @param Deactivatable $deactivatable The function mocks.
31+
*/
32+
public function __construct(Deactivatable $deactivatable)
33+
{
34+
$this->deactivatable = $deactivatable;
35+
}
36+
37+
/**
38+
* Disables the function mocks.
39+
*
40+
* @param Test $test The test.
41+
* @param int $time The test duration.
42+
*
43+
* @see Mock::disable()
44+
*/
45+
public function endTest(Test $test, float $time) : void
46+
{
47+
parent::endTest($test, $time);
48+
49+
$this->deactivatable->disable();
50+
}
51+
}

‎classes/MockObjectProxy.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace phpmock\phpunit;
44

5-
use PHPUnit_Framework_MockObject_MockObject as MockObject;
5+
use PHPUnit\Framework\MockObject\Matcher\Invocation;
6+
use PHPUnit\Framework\MockObject\MockObject;
67
use phpmock\integration\MockDelegateFunctionBuilder;
78

89
/**
@@ -61,7 +62,7 @@ public function __phpunit_verify()
6162
return $this->mockObject->__phpunit_verify();
6263
}
6364

64-
public function expects(\PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
65+
public function expects(Invocation $matcher)
6566
{
6667
return $this->mockObject->expects($matcher)->method(MockDelegateFunctionBuilder::METHOD);
6768
}

‎classes/PHPMock.php‎

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use phpmock\integration\MockDelegateFunctionBuilder;
66
use phpmock\MockBuilder;
77
use phpmock\Deactivatable;
8+
use PHPUnit\Framework\MockObject\MockObject;
89

910
/**
1011
* Adds building a function mock functionality into \PHPUnit\Framework\TestCase.
@@ -35,30 +36,6 @@
3536
*/
3637
trait PHPMock
3738
{
38-
39-
/**
40-
* Returns a builder object to create mock objects using a fluent interface.
41-
*
42-
* This method exists in \PHPUnit\Framework\TestCase.
43-
*
44-
* @param string $className Name of the class to mock.
45-
* @return \PHPUnit_Framework_MockObject_MockBuilder
46-
* @see \PHPUnit\Framework\TestCase::getMockBuilder()
47-
* @internal
48-
*/
49-
abstract protected function getMockBuilder($className);
50-
51-
/**
52-
* Returns the test result.
53-
*
54-
* This method exists in \PHPUnit\Framework\TestCase.
55-
*
56-
* @return \PHPUnit\Framework\TestResult The test result.
57-
* @see \PHPUnit\Framework\TestCase::getTestResultObject()
58-
* @internal
59-
*/
60-
abstract protected function getTestResultObject();
61-
6239
/**
6340
* Returns the enabled function mock.
6441
*
@@ -67,7 +44,7 @@ abstract protected function getTestResultObject();
6744
* @param string $namespace The function namespace.
6845
* @param string $name The function name.
6946
*
70-
* @return \PHPUnit_Framework_MockObject_MockObject The PHPUnit mock.
47+
* @return MockObject The PHPUnit mock.
7148
*/
7249
public function getFunctionMock($namespace, $name)
7350
{

‎compatibility/BaseTestListener.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace PHPUnit\Framework;
4+
5+
/**
6+
* Compatibility class to work with PHPUnit 7
7+
*
8+
* @internal
9+
*/
10+
abstract class BaseTestListener implements TestListener
11+
{
12+
use TestListenerDefaultImplementation;
13+
}

‎composer.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
}
1515
],
1616
"autoload": {
17+
"files": ["autoload.php"],
1718
"psr-4": {"phpmock\\phpunit\\": "classes/"}
1819
},
1920
"require": {
2021
"php": ">=7",
21-
"phpunit/phpunit": "^6 <6.5",
22+
"phpunit/phpunit": "^6 || ^7",
2223
"php-mock/php-mock-integration": "^2"
2324
},
2425
"archive": {

‎tests/MockObjectProxyTest.php‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace phpmock\phpunit;
44

5-
use \PHPUnit_Framework_MockObject_Builder_InvocationMocker as InvocationMocker;
65
use PHPUnit\Framework\TestCase;
76
use phpmock\integration\MockDelegateFunctionBuilder;
7+
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
8+
use PHPUnit\Framework\MockObject\Matcher\Invocation;
9+
use PHPUnit\Framework\MockObject\MockObject;
810

911
/**
1012
* Tests MockObjectProxyTest.
@@ -25,13 +27,13 @@ class MockObjectProxyTest extends TestCase
2527
*/
2628
public function testExpects()
2729
{
28-
$matcher = $this->getMockBuilder(\PHPUnit_Framework_MockObject_Matcher_Invocation::class)->getMock();
30+
$matcher = $this->getMockBuilder(Invocation::class)->getMock();
2931

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

34-
$prophecy = $this->prophesize(\PHPUnit_Framework_MockObject_MockObject::class);
36+
$prophecy = $this->prophesize(MockObject::class);
3537
$prophecy->expects($matcher)->willReturn($invocationMocker);
3638
$mock = $prophecy->reveal();
3739

@@ -53,7 +55,7 @@ public function testExpects()
5355
*/
5456
public function testHasMatcher()
5557
{
56-
$prophecy = $this->prophesize(\PHPUnit_Framework_MockObject_MockObject::class);
58+
$prophecy = $this->prophesize(MockObject::class);
5759
$prophecy->__phpunit_hasMatchers()->willReturn("foo");
5860
$mock = $prophecy->reveal();
5961

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /