Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Xerkus committed Jun 11, 2019
2 parents 6e4425e + 700a1f9 commit 93b85f0
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 24 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ matrix:
- php: 7.1
env:
- DEPS=locked
- LEGACY_DEPS="phpunit/phpunit"
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.1
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 3.3.0 - TBD

### Added

- [#76](https://github.com/zendframework/zend-test/pull/76) adds support for PhpUnit 8

### Changed

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.

## 3.2.3 - TBD

### Added
Expand Down
13 changes: 13 additions & 0 deletions autoload/phpunit-class-aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\TestCase;
use PHPUnit\Runner\Version;

if (! class_exists(ExpectationFailedException::class)) {
class_alias(\PHPUnit_Framework_ExpectationFailedException::class, ExpectationFailedException::class);
Expand All @@ -15,3 +16,15 @@ class_alias(\PHPUnit_Framework_ExpectationFailedException::class, ExpectationFai
if (! class_exists(TestCase::class)) {
class_alias(\PHPUnit_Framework_TestCase::class, TestCase::class);
}

// Compatibility with PHPUnit 8.0
// We need to use "magic" trait \Zend\Test\PHPUnit\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(\Zend\Test\PHPUnit\TestCaseTypeHintTrait::class, \Zend\Test\PHPUnit\TestCaseTrait::class);
} else {
class_alias(\Zend\Test\PHPUnit\TestCaseNoTypeHintTrait::class, \Zend\Test\PHPUnit\TestCaseTrait::class);
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"require": {
"php": "^5.6 || ^7.0",
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0",
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0",
"sebastian/version": "^1.0.4 || ^2.0",
"zendframework/zend-console": "^2.6",
"zendframework/zend-dom": "^2.6",
Expand All @@ -30,7 +30,7 @@
"zendframework/zend-view": "^2.6.3"
},
"require-dev": {
"mikey179/vfsStream": "~1.2",
"mikey179/vfsstream": "~1.2",
"symfony/finder": "^2.2",
"zendframework/zend-coding-standard": "~1.0.0",
"zendframework/zend-i18n": "^2.6",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/PHPUnit/Controller/AbstractControllerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
use Zend\Stdlib\Exception\LogicException;
use Zend\Stdlib\Parameters;
use Zend\Stdlib\ResponseInterface;
use Zend\Test\PHPUnit\TestCaseTrait;
use Zend\Uri\Http as HttpUri;

abstract class AbstractControllerTestCase extends TestCase
{
use TestCaseTrait;

/**
* @var \Zend\Mvc\ApplicationInterface
*/
Expand Down Expand Up @@ -52,17 +55,21 @@ abstract class AbstractControllerTestCase extends TestCase

/**
* Reset the application for isolation
*
* @internal
*/
protected function setUp()
protected function setUpCompat()
{
$this->usedConsoleBackup = Console::isConsole();
$this->reset();
}

/**
* Restore params
*
* @internal
*/
protected function tearDown()
protected function tearDownCompat()
{
Console::overrideIsConsole($this->usedConsoleBackup);

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

namespace Zend\Test\PHPUnit;

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

protected function tearDown()
{
if (method_exists($this, 'tearDownCompat')) {
$this->tearDownCompat();
}
}

public static function setUpBeforeClass()
{
if (method_exists(static::class, 'setUpBeforeClassCompat')) {
static::setUpBeforeClassCompat();
}
}

public static function tearDownAfterClass()
{
if (method_exists(static::class, 'tearDownAfterClassCompat')) {
static::tearDownAfterClassCompat();
}
}
}
37 changes: 37 additions & 0 deletions src/PHPUnit/TestCaseTypeHintTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Zend\Test\PHPUnit;

/**
* @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();
}
}

public static function setUpBeforeClass() : void
{
if (method_exists(static::class, 'setUpBeforeClassCompat')) {
static::setUpBeforeClassCompat();
}
}

public static function tearDownAfterClass() : void
{
if (method_exists(static::class, 'tearDownAfterClassCompat')) {
static::tearDownAfterClassCompat();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class AbstractConsoleControllerTestCaseTest extends AbstractConsoleControllerTes
{
use ExpectedExceptionTrait;

protected function setUp()
protected function setUpCompat()
{
$this->setApplicationConfig(
include __DIR__ . '/../../_files/application.config.php'
);
parent::setUp();
parent::setUpCompat();
}

public function testUseOfRouter()
Expand Down
45 changes: 33 additions & 12 deletions test/PHPUnit/Controller/AbstractControllerTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ public static function rmdir($dir)
return rmdir($dir);
}

protected function setUp()
protected function setUpCompat()
{
$this->traceErrorCache = $this->traceError;
$this->tearDownCacheDir();
Console::overrideIsConsole(null);
$this->setApplicationConfig(
include __DIR__ . '/../../_files/application.config.php'
);
parent::setUp();
parent::setUpCompat();
}

protected function tearDown()
protected function tearDownCompat()
{
$this->traceError = $this->traceErrorCache;
$this->tearDownCacheDir();
parent::tearDown();
parent::tearDownCompat();
}

public function testModuleCacheIsDisabled()
Expand Down Expand Up @@ -107,13 +107,13 @@ public function testApplicationClassAndTestRestoredConsoleFlag()
$this->assertTrue(Console::isConsole(), '3. Console::isConsole returned false after tearDown');

Console::overrideIsConsole(false);
parent::setUp();
parent::setUpCompat();

$this->assertFalse(Console::isConsole(), '4. Console::isConsole returned true after parent::setUp');
$this->getApplication();
$this->assertFalse(Console::isConsole(), '5. Console::isConsole returned true after retrieving application');

parent::tearDown();
parent::tearDownCompat();

$this->assertFalse(Console::isConsole(), '6. Console.isConsole returned true after parent::tearDown');
}
Expand Down Expand Up @@ -169,9 +169,9 @@ public function testAssertExceptionDetailsPresentWhenTraceErrorIsEnabled()

$this->assertTrue($caught, 'Did not catch expected exception!');

$this->assertContains('actual module name is "baz"', $message);
$this->assertContains("Exception 'RuntimeException' with message 'Expected exception message'", $message);
$this->assertContains(__FILE__, $message);
$this->assertContainsCompat('actual module name is "baz"', $message);
$this->assertContainsCompat("Exception 'RuntimeException' with message 'Expected exception message'", $message);
$this->assertContainsCompat(__FILE__, $message);
}

public function testAssertExceptionDetailsNotPresentWhenTraceErrorIsDisabled()
Expand All @@ -193,9 +193,12 @@ public function testAssertExceptionDetailsNotPresentWhenTraceErrorIsDisabled()

$this->assertTrue($caught, 'Did not catch expected exception!');

$this->assertContains('actual module name is "baz"', $message);
$this->assertNotContains("Exception 'RuntimeException' with message 'Expected exception message'", $message);
$this->assertNotContains(__FILE__, $message);
$this->assertContainsCompat('actual module name is "baz"', $message);
$this->assertNotContainsCompat(
"Exception 'RuntimeException' with message 'Expected exception message'",
$message
);
$this->assertNotContainsCompat(__FILE__, $message);
}

public function testAssertNotModuleName()
Expand Down Expand Up @@ -535,4 +538,22 @@ public function testRequestWithRouteParam($param)
$this->dispatch(sprintf('/with-param/%s', $param));
$this->assertResponseStatusCode(200);
}

private function assertContainsCompat($needle, $haystack)
{
if (method_exists($this, 'assertStringContainsString')) {
$this->assertStringContainsString($needle, $haystack);
} else {
$this->assertContains($needle, $haystack);
}
}

private function assertNotContainsCompat($needle, $haystack)
{
if (method_exists($this, 'assertStringNotContainsString')) {
$this->assertStringNotContainsString($needle, $haystack);
} else {
$this->assertNotContains($needle, $haystack);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class AbstractHttpControllerTestCaseTest extends AbstractHttpControllerTestCase
{
use ExpectedExceptionTrait;

public function setUp()
protected function setUpCompat()
{
$this->setApplicationConfig(
include __DIR__ . '/../../_files/application.config.php'
);
parent::setUp();
parent::setUpCompat();
}

public function testUseOfRouter()
Expand Down
2 changes: 1 addition & 1 deletion test/PHPUnit/Controller/MemoryLeakTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MemoryLeakTest extends AbstractControllerTestCase
{
public static $memStart;

public static function setUpBeforeClass()
protected static function setUpBeforeClassCompat()
{
self::$memStart = memory_get_usage(true);
}
Expand Down
6 changes: 4 additions & 2 deletions test/PHPUnit/Util/ModuleLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

use PHPUnit\Framework\TestCase;
use Zend\ModuleManager\Exception\RuntimeException;
use Zend\Test\PHPUnit\TestCaseTrait;
use Zend\Test\Util\ModuleLoader;
use ZendTest\Test\ExpectedExceptionTrait;

class ModuleLoaderTest extends TestCase
{
use ExpectedExceptionTrait;
use TestCaseTrait;

public function tearDownCacheDir()
{
Expand All @@ -35,12 +37,12 @@ public static function rmdir($dir)
return rmdir($dir);
}

public function setUp()
protected function setUpCompat()
{
$this->tearDownCacheDir();
}

public function tearDown()
protected function tearDownCompat()
{
$this->tearDownCacheDir();
}
Expand Down

0 comments on commit 93b85f0

Please sign in to comment.