Skip to content

Feature: PHPUnit 9 support #1

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

Merged
merged 1 commit into from
Feb 8, 2020
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.phpunit.result.cache
/composer.lock
/vendor/
9 changes: 3 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
language: php

sudo: false

cache:
directories:
- $HOME/.composer/cache

php:
- 7.4
- 7.3
- 7.2
- 7.1
- 7.0
- 5.6
- hhvm

matrix:
fast_finish: true
allow_failures:
- php: hhvm

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

7 changes: 4 additions & 3 deletions classes/MockDelegateFunctionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace phpmock\integration;

use phpmock\generator\ParameterBuilder;
use SebastianBergmann\Template\Template;

/**
* Defines a MockDelegateFunction.
Expand All @@ -26,7 +27,7 @@ class MockDelegateFunctionBuilder
private $namespace;

/**
* @var \Text_Template The MockDelegateFunction template.
* @var Template The MockDelegateFunction template.
*/
private $template;

Expand All @@ -35,7 +36,7 @@ class MockDelegateFunctionBuilder
*/
public function __construct()
{
$this->template = new \Text_Template(__DIR__ . "/MockDelegateFunction.tpl");
$this->template = new Template(__DIR__ . '/MockDelegateFunction.tpl');
}

/**
Expand All @@ -56,7 +57,7 @@ public function build($functionName = null)
* to the generated class.
*/
$hash = md5($signatureParameters);
$this->namespace = __NAMESPACE__.$hash;
$this->namespace = __NAMESPACE__ . $hash;
if (class_exists($this->getFullyQualifiedClassName())) {
return;
}
Expand Down
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
"autoload": {
"psr-4": {"phpmock\\integration\\": "classes/"}
},
"autoload-dev": {
"files": ["tests/autoload.php"],
"psr-4": {"phpmock\\integration\\": "tests/"}
},
"require": {
"php": ">=5.6",
"php-mock/php-mock": "^2",
"phpunit/php-text-template": "^1"
"php-mock/php-mock": "^2.2",
"phpunit/php-text-template": "^1 || ^2"
},
"require-dev": {
"phpunit/phpunit": "^4|^5"
"phpunit/phpunit": "^5.7.27 || ^6 || ^7 || ^8 || ^9"
},
"archive": {
"exclude": ["/tests"]
Expand Down
19 changes: 12 additions & 7 deletions tests/MockDelegateFunctionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace phpmock\integration;

use PHPUnit\Framework\TestCase;

/**
* Tests MockDelegateFunctionBuilder.
*
Expand All @@ -10,7 +12,7 @@
* @license http://www.wtfpl.net/txt/copying/ WTFPL
* @see MockDelegateFunctionBuilder
*/
class MockDelegateFunctionBuilderTest extends \PHPUnit_Framework_TestCase
class MockDelegateFunctionBuilderTest extends TestCase
{

/**
Expand All @@ -34,14 +36,14 @@ public function testDiverseSignaturesProduceDifferentClasses()
{
$builder = new MockDelegateFunctionBuilder();

$builder->build(create_function('', ''));
$builder->build('f0');
$class1 = $builder->getFullyQualifiedClassName();

$builder->build(create_function('$a', ''));
$builder->build('f1');
$class2 = $builder->getFullyQualifiedClassName();

$builder2 = new MockDelegateFunctionBuilder();
$builder2->build(create_function('$a, $b', ''));
$builder2->build('f2');
$class3 = $builder2->getFullyQualifiedClassName();

$this->assertNotEquals($class1, $class2);
Expand All @@ -56,13 +58,12 @@ public function testDiverseSignaturesProduceDifferentClasses()
*/
public function testSameSignaturesProduceSameClass()
{
$signature = '$a';
$builder = new MockDelegateFunctionBuilder();

$builder->build(create_function($signature, ''));
$builder->build('f1');
$class1 = $builder->getFullyQualifiedClassName();

$builder->build(create_function($signature, ''));
$builder->build('f1');
$class2 = $builder->getFullyQualifiedClassName();

$this->assertEquals($class1, $class2);
Expand All @@ -74,6 +75,8 @@ public function testSameSignaturesProduceSameClass()
* @test
* @backupStaticAttributes enabled
* @dataProvider provideTestBackupStaticAttributes
*
* @doesNotPerformAssertions
*/
public function testBackupStaticAttributes()
{
Expand All @@ -100,6 +103,8 @@ public function provideTestBackupStaticAttributes()
* @test
* @runInSeparateProcess
* @dataProvider provideTestDeserializationInNewProcess
*
* @doesNotPerformAssertions
*/
public function testDeserializationInNewProcess($data)
{
Expand Down
7 changes: 5 additions & 2 deletions tests/MockDelegateFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace phpmock\integration;

use PHPUnit\Framework\TestCase;

/**
* Tests MockDelegateFunction.
*
Expand All @@ -10,15 +12,16 @@
* @license http://www.wtfpl.net/txt/copying/ WTFPL
* @see MockDelegateFunction
*/
class MockDelegateFunctionTest extends \PHPUnit_Framework_TestCase
class MockDelegateFunctionTest extends TestCase
{
use TestCaseTrait;

/**
* @var string The class name of a generated class.
*/
private $className;

protected function setUp()
protected function setUpCompat()
{
parent::setUp();

Expand Down
23 changes: 23 additions & 0 deletions tests/TestCaseNoTypeHintTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace phpmock\integration;

/**
* @internal
*/
trait TestCaseNoTypeHintTrait
{
protected function setUp()
{
if (method_exists($this, 'setUpCompat')) {
$this->setUpCompat();
}
}

protected function tearDown()
{
if (method_exists($this, 'tearDownCompat')) {
$this->tearDownCompat();
}
}
}
23 changes: 23 additions & 0 deletions tests/TestCaseTypeHintTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace phpmock\integration;

/**
* @internal
*/
trait TestCaseTypeHintTrait
{
protected function setUp(): void
{
if (method_exists($this, 'setUpCompat')) {
$this->setUpCompat();
}
}

protected function tearDown(): void
{
if (method_exists($this, 'tearDownCompat')) {
$this->tearDownCompat();
}
}
}
25 changes: 25 additions & 0 deletions tests/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php // phpcs:ignore

use PHPUnit\Runner\Version;

// Compatibility with PHPUnit 8.0+
// We need to use "magic" trait \phpmock\integration\TestCaseTrait
// and instead of setUp/tearDown method in test case
// we should have setUpCompat/tearDownCompat.
if (class_exists(Version::class)
&& version_compare(Version::id(), '8.0.0') >= 0
) {
class_alias(\phpmock\integration\TestCaseTypeHintTrait::class, \phpmock\integration\TestCaseTrait::class);
} else {
class_alias(\phpmock\integration\TestCaseNoTypeHintTrait::class, \phpmock\integration\TestCaseTrait::class);
}

function f0()
{
}
function f1($a)
{
}
function f2($a, $b)
{
}