Skip to content

Commit 003d585

Browse files
committedFeb 8, 2020
Merge branch 'feature/phpunit-9'
2 parents 5a0d7d7 + 6a3ba03 commit 003d585

9 files changed

+105
-21
lines changed
 

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.phpunit.result.cache
2+
/composer.lock
3+
/vendor/

‎.travis.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
language: php
22

3-
sudo: false
4-
53
cache:
64
directories:
75
- $HOME/.composer/cache
86

97
php:
8+
- 7.4
9+
- 7.3
10+
- 7.2
1011
- 7.1
1112
- 7.0
1213
- 5.6
13-
- hhvm
1414

1515
matrix:
1616
fast_finish: true
17-
allow_failures:
18-
- php: hhvm
1917

2018
install:
2119
- composer require squizlabs/php_codesniffer
@@ -25,4 +23,3 @@ script:
2523
- vendor/bin/phpunit
2624
- vendor/bin/phpcs --standard=PSR2 classes/ tests/
2725
- vendor/bin/phpmd classes/ text cleancode,codesize,controversial,design,naming,unusedcode
28-

‎classes/MockDelegateFunctionBuilder.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace phpmock\integration;
44

55
use phpmock\generator\ParameterBuilder;
6+
use SebastianBergmann\Template\Template;
67

78
/**
89
* Defines a MockDelegateFunction.
@@ -26,7 +27,7 @@ class MockDelegateFunctionBuilder
2627
private $namespace;
2728

2829
/**
29-
* @var \Text_Template The MockDelegateFunction template.
30+
* @var Template The MockDelegateFunction template.
3031
*/
3132
private $template;
3233

@@ -35,7 +36,7 @@ class MockDelegateFunctionBuilder
3536
*/
3637
public function __construct()
3738
{
38-
$this->template = new \Text_Template(__DIR__ . "/MockDelegateFunction.tpl");
39+
$this->template = new Template(__DIR__ . '/MockDelegateFunction.tpl');
3940
}
4041

4142
/**
@@ -56,7 +57,7 @@ public function build($functionName = null)
5657
* to the generated class.
5758
*/
5859
$hash = md5($signatureParameters);
59-
$this->namespace = __NAMESPACE__.$hash;
60+
$this->namespace = __NAMESPACE__ . $hash;
6061
if (class_exists($this->getFullyQualifiedClassName())) {
6162
return;
6263
}

‎composer.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616
"autoload": {
1717
"psr-4": {"phpmock\\integration\\": "classes/"}
1818
},
19+
"autoload-dev": {
20+
"files": ["tests/autoload.php"],
21+
"psr-4": {"phpmock\\integration\\": "tests/"}
22+
},
1923
"require": {
2024
"php": ">=5.6",
21-
"php-mock/php-mock": "^2",
22-
"phpunit/php-text-template": "^1"
25+
"php-mock/php-mock": "^2.2",
26+
"phpunit/php-text-template": "^1 || ^2"
2327
},
2428
"require-dev": {
25-
"phpunit/phpunit": "^4|^5"
29+
"phpunit/phpunit": "^5.7.27 || ^6 || ^7 || ^8 || ^9"
2630
},
2731
"archive": {
2832
"exclude": ["/tests"]

‎tests/MockDelegateFunctionBuilderTest.php

+12-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace phpmock\integration;
44

5+
use PHPUnit\Framework\TestCase;
6+
57
/**
68
* Tests MockDelegateFunctionBuilder.
79
*
@@ -10,7 +12,7 @@
1012
* @license http://www.wtfpl.net/txt/copying/ WTFPL
1113
* @see MockDelegateFunctionBuilder
1214
*/
13-
class MockDelegateFunctionBuilderTest extends \PHPUnit_Framework_TestCase
15+
class MockDelegateFunctionBuilderTest extends TestCase
1416
{
1517

1618
/**
@@ -34,14 +36,14 @@ public function testDiverseSignaturesProduceDifferentClasses()
3436
{
3537
$builder = new MockDelegateFunctionBuilder();
3638

37-
$builder->build(create_function('', ''));
39+
$builder->build('f0');
3840
$class1 = $builder->getFullyQualifiedClassName();
3941

40-
$builder->build(create_function('$a', ''));
42+
$builder->build('f1');
4143
$class2 = $builder->getFullyQualifiedClassName();
4244

4345
$builder2 = new MockDelegateFunctionBuilder();
44-
$builder2->build(create_function('$a, $b', ''));
46+
$builder2->build('f2');
4547
$class3 = $builder2->getFullyQualifiedClassName();
4648

4749
$this->assertNotEquals($class1, $class2);
@@ -56,13 +58,12 @@ public function testDiverseSignaturesProduceDifferentClasses()
5658
*/
5759
public function testSameSignaturesProduceSameClass()
5860
{
59-
$signature = '$a';
6061
$builder = new MockDelegateFunctionBuilder();
6162

62-
$builder->build(create_function($signature, ''));
63+
$builder->build('f1');
6364
$class1 = $builder->getFullyQualifiedClassName();
6465

65-
$builder->build(create_function($signature, ''));
66+
$builder->build('f1');
6667
$class2 = $builder->getFullyQualifiedClassName();
6768

6869
$this->assertEquals($class1, $class2);
@@ -74,6 +75,8 @@ public function testSameSignaturesProduceSameClass()
7475
* @test
7576
* @backupStaticAttributes enabled
7677
* @dataProvider provideTestBackupStaticAttributes
78+
*
79+
* @doesNotPerformAssertions
7780
*/
7881
public function testBackupStaticAttributes()
7982
{
@@ -100,6 +103,8 @@ public function provideTestBackupStaticAttributes()
100103
* @test
101104
* @runInSeparateProcess
102105
* @dataProvider provideTestDeserializationInNewProcess
106+
*
107+
* @doesNotPerformAssertions
103108
*/
104109
public function testDeserializationInNewProcess($data)
105110
{

‎tests/MockDelegateFunctionTest.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace phpmock\integration;
44

5+
use PHPUnit\Framework\TestCase;
6+
57
/**
68
* Tests MockDelegateFunction.
79
*
@@ -10,15 +12,16 @@
1012
* @license http://www.wtfpl.net/txt/copying/ WTFPL
1113
* @see MockDelegateFunction
1214
*/
13-
class MockDelegateFunctionTest extends \PHPUnit_Framework_TestCase
15+
class MockDelegateFunctionTest extends TestCase
1416
{
17+
use TestCaseTrait;
1518

1619
/**
1720
* @var string The class name of a generated class.
1821
*/
1922
private $className;
2023

21-
protected function setUp()
24+
protected function setUpCompat()
2225
{
2326
parent::setUp();
2427

‎tests/TestCaseNoTypeHintTrait.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace phpmock\integration;
4+
5+
/**
6+
* @internal
7+
*/
8+
trait TestCaseNoTypeHintTrait
9+
{
10+
protected function setUp()
11+
{
12+
if (method_exists($this, 'setUpCompat')) {
13+
$this->setUpCompat();
14+
}
15+
}
16+
17+
protected function tearDown()
18+
{
19+
if (method_exists($this, 'tearDownCompat')) {
20+
$this->tearDownCompat();
21+
}
22+
}
23+
}

‎tests/TestCaseTypeHintTrait.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace phpmock\integration;
4+
5+
/**
6+
* @internal
7+
*/
8+
trait TestCaseTypeHintTrait
9+
{
10+
protected function setUp(): void
11+
{
12+
if (method_exists($this, 'setUpCompat')) {
13+
$this->setUpCompat();
14+
}
15+
}
16+
17+
protected function tearDown(): void
18+
{
19+
if (method_exists($this, 'tearDownCompat')) {
20+
$this->tearDownCompat();
21+
}
22+
}
23+
}

‎tests/autoload.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php // phpcs:ignore
2+
3+
use PHPUnit\Runner\Version;
4+
5+
// Compatibility with PHPUnit 8.0+
6+
// We need to use "magic" trait \phpmock\integration\TestCaseTrait
7+
// and instead of setUp/tearDown method in test case
8+
// we should have setUpCompat/tearDownCompat.
9+
if (class_exists(Version::class)
10+
&& version_compare(Version::id(), '8.0.0') >= 0
11+
) {
12+
class_alias(\phpmock\integration\TestCaseTypeHintTrait::class, \phpmock\integration\TestCaseTrait::class);
13+
} else {
14+
class_alias(\phpmock\integration\TestCaseNoTypeHintTrait::class, \phpmock\integration\TestCaseTrait::class);
15+
}
16+
17+
function f0()
18+
{
19+
}
20+
function f1($a)
21+
{
22+
}
23+
function f2($a, $b)
24+
{
25+
}

0 commit comments

Comments
 (0)
Please sign in to comment.