From d0597d17c0a889d4710e1863aabcc503826e7f7a Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Sat, 7 Apr 2018 20:01:52 +1000 Subject: [PATCH 01/10] Bumped to next dev version (3.3.0) --- CHANGELOG.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f209b3567..bb9fb390ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 + +- Nothing. + +### Changed + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + ## 3.2.1 - TBD ### Added From e4dd57a81677a3b586c82c6f11c4e6d187f3c6df Mon Sep 17 00:00:00 2001 From: webimpress Date: Sat, 2 Feb 2019 00:14:08 +0000 Subject: [PATCH 02/10] Added PHPUnit 8 support --- .travis.yml | 1 + composer.json | 2 +- composer.lock | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 23e5f24b84..da63922976 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,6 +37,7 @@ matrix: - php: 7.1 env: - DEPS=locked + - LEGACY_DEPS="phpunit/phpunit" - CS_CHECK=true - TEST_COVERAGE=true - php: 7.1 diff --git a/composer.json b/composer.json index a2309db8d8..cd0b252e45 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index dd3ae58c87..55a7ed50e3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "bf86eb359734daf37a5f184d6a328b1b", + "content-hash": "55540cf291f52e420c12aeeac8b1e880", "packages": [ { "name": "container-interop/container-interop", From 804515c65117dcb9ef58e211fa202fcc6044d785 Mon Sep 17 00:00:00 2001 From: webimpress Date: Sat, 2 Feb 2019 08:54:34 +0000 Subject: [PATCH 03/10] Added PHPUnit 8 compatibility level Added traits with methods which can be used in tests and in PHPUnit 8 have RTH defined. We load proper trait depends on used PHPUnit version. In our classes to keep compatibility we use method with "Compat" suffix. Fot the end user nothing is changed as long as the user decide to support one PHPUnit version (any <7 or 8+). Depends on the version user can define setUp/tearDown method compatible with the used version of PHPUnit and call the parent method. --- autoload/phpunit-class-aliases.php | 13 +++++++ .../Controller/AbstractControllerTestCase.php | 11 +++++- src/PHPUnit/TestCaseNoTypeHintTrait.php | 37 +++++++++++++++++++ src/PHPUnit/TestCaseTypeHintTrait.php | 37 +++++++++++++++++++ .../AbstractConsoleControllerTestCaseTest.php | 4 +- .../AbstractControllerTestCaseTest.php | 8 ++-- .../AbstractHttpControllerTestCaseTest.php | 4 +- test/PHPUnit/Controller/MemoryLeakTest.php | 2 +- test/PHPUnit/Util/ModuleLoaderTest.php | 6 ++- 9 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 src/PHPUnit/TestCaseNoTypeHintTrait.php create mode 100644 src/PHPUnit/TestCaseTypeHintTrait.php diff --git a/autoload/phpunit-class-aliases.php b/autoload/phpunit-class-aliases.php index d5aa73fe3f..55655269e8 100644 --- a/autoload/phpunit-class-aliases.php +++ b/autoload/phpunit-class-aliases.php @@ -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); @@ -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); +} \ No newline at end of file diff --git a/src/PHPUnit/Controller/AbstractControllerTestCase.php b/src/PHPUnit/Controller/AbstractControllerTestCase.php index 0fe8a0eb2c..354ce6b80c 100644 --- a/src/PHPUnit/Controller/AbstractControllerTestCase.php +++ b/src/PHPUnit/Controller/AbstractControllerTestCase.php @@ -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 */ @@ -52,8 +55,10 @@ abstract class AbstractControllerTestCase extends TestCase /** * Reset the application for isolation + * + * @internal */ - protected function setUp() + protected function setUpCompat() { $this->usedConsoleBackup = Console::isConsole(); $this->reset(); @@ -61,8 +66,10 @@ protected function setUp() /** * Restore params + * + * @internal */ - protected function tearDown() + protected function tearDownCompat() { Console::overrideIsConsole($this->usedConsoleBackup); diff --git a/src/PHPUnit/TestCaseNoTypeHintTrait.php b/src/PHPUnit/TestCaseNoTypeHintTrait.php new file mode 100644 index 0000000000..2f2ae424b6 --- /dev/null +++ b/src/PHPUnit/TestCaseNoTypeHintTrait.php @@ -0,0 +1,37 @@ +setUpCompat(); + } + } + + protected function tearDown() + { + if (method_exists($this, 'tearDownCompat')) { + $this->tearDownCompat(); + } + } + + public static function setUpBeforeClass() + { + if (method_exists(__CLASS__, 'setUpBeforeClassCompat')) { + static::setUpBeforeClassCompat(); + } + } + + public static function tearDownAfterClass() + { + if (method_exists(__CLASS__, 'tearDownAfterClassCompat')) { + static::tearDownAfterClassCompat(); + } + } +} diff --git a/src/PHPUnit/TestCaseTypeHintTrait.php b/src/PHPUnit/TestCaseTypeHintTrait.php new file mode 100644 index 0000000000..e7640d804c --- /dev/null +++ b/src/PHPUnit/TestCaseTypeHintTrait.php @@ -0,0 +1,37 @@ +setUpCompat(); + } + } + + protected function tearDown() : void + { + if (method_exists($this, 'tearDownCompat')) { + $this->tearDownCompat(); + } + } + + public static function setUpBeforeClass() : void + { + if (method_exists(__CLASS__, 'setUpBeforeClassCompat')) { + static::setUpBeforeClassCompat(); + } + } + + public static function tearDownAfterClass() : void + { + if (method_exists(__CLASS__, 'tearDownAfterClassCompat')) { + static::tearDownAfterClassCompat(); + } + } +} diff --git a/test/PHPUnit/Controller/AbstractConsoleControllerTestCaseTest.php b/test/PHPUnit/Controller/AbstractConsoleControllerTestCaseTest.php index 07c16c4b53..3490ad271e 100644 --- a/test/PHPUnit/Controller/AbstractConsoleControllerTestCaseTest.php +++ b/test/PHPUnit/Controller/AbstractConsoleControllerTestCaseTest.php @@ -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() diff --git a/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php b/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php index e36cee4c63..7a72af7bb0 100644 --- a/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php +++ b/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php @@ -50,7 +50,7 @@ public static function rmdir($dir) return rmdir($dir); } - protected function setUp() + protected function setUpCompat() { $this->traceErrorCache = $this->traceError; $this->tearDownCacheDir(); @@ -58,14 +58,14 @@ protected function setUp() $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() diff --git a/test/PHPUnit/Controller/AbstractHttpControllerTestCaseTest.php b/test/PHPUnit/Controller/AbstractHttpControllerTestCaseTest.php index 8290c597ed..5a8aab7408 100644 --- a/test/PHPUnit/Controller/AbstractHttpControllerTestCaseTest.php +++ b/test/PHPUnit/Controller/AbstractHttpControllerTestCaseTest.php @@ -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() diff --git a/test/PHPUnit/Controller/MemoryLeakTest.php b/test/PHPUnit/Controller/MemoryLeakTest.php index 41de9de0ff..c8f11ed570 100644 --- a/test/PHPUnit/Controller/MemoryLeakTest.php +++ b/test/PHPUnit/Controller/MemoryLeakTest.php @@ -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); } diff --git a/test/PHPUnit/Util/ModuleLoaderTest.php b/test/PHPUnit/Util/ModuleLoaderTest.php index 2e89d727c6..726076aa8b 100644 --- a/test/PHPUnit/Util/ModuleLoaderTest.php +++ b/test/PHPUnit/Util/ModuleLoaderTest.php @@ -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() { @@ -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(); } From ea479984c9bac83fa9d5b9fa5cc35ba2fa664324 Mon Sep 17 00:00:00 2001 From: webimpress Date: Sat, 2 Feb 2019 09:04:34 +0000 Subject: [PATCH 04/10] Changes in tests to support PHPUnit 8 --- .../AbstractControllerTestCaseTest.php | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php b/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php index 7a72af7bb0..a9566ae24f 100644 --- a/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php +++ b/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php @@ -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'); } @@ -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() @@ -193,9 +193,9 @@ 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() @@ -535,4 +535,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); + } + } } From ff302d31137a2bfd50b7b2c2b1e3858ac123bfac Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 23 May 2019 15:13:45 +0100 Subject: [PATCH 05/10] Added missing line at the end of the file --- autoload/phpunit-class-aliases.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/phpunit-class-aliases.php b/autoload/phpunit-class-aliases.php index 55655269e8..18100dfdf3 100644 --- a/autoload/phpunit-class-aliases.php +++ b/autoload/phpunit-class-aliases.php @@ -27,4 +27,4 @@ class_alias(\PHPUnit_Framework_TestCase::class, TestCase::class); 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); -} \ No newline at end of file +} From adc0a55116303977225ee66d9bdc60ec0029720c Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 23 May 2019 15:14:26 +0100 Subject: [PATCH 06/10] Fixed compatibility with setUpBeforeClass/tearDownAfterClass methods --- src/PHPUnit/TestCaseNoTypeHintTrait.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PHPUnit/TestCaseNoTypeHintTrait.php b/src/PHPUnit/TestCaseNoTypeHintTrait.php index 2f2ae424b6..63f4a442ef 100644 --- a/src/PHPUnit/TestCaseNoTypeHintTrait.php +++ b/src/PHPUnit/TestCaseNoTypeHintTrait.php @@ -23,14 +23,14 @@ protected function tearDown() public static function setUpBeforeClass() { - if (method_exists(__CLASS__, 'setUpBeforeClassCompat')) { + if (method_exists(static::class, 'setUpBeforeClassCompat')) { static::setUpBeforeClassCompat(); } } public static function tearDownAfterClass() { - if (method_exists(__CLASS__, 'tearDownAfterClassCompat')) { + if (method_exists(static::class, 'tearDownAfterClassCompat')) { static::tearDownAfterClassCompat(); } } From 5da097467385b8dfc44402aedc83ddbc6a13f9df Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 23 May 2019 15:21:09 +0100 Subject: [PATCH 07/10] CS fix: too long line --- test/PHPUnit/Controller/AbstractControllerTestCaseTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php b/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php index a9566ae24f..f793d0bbf1 100644 --- a/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php +++ b/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php @@ -194,7 +194,10 @@ public function testAssertExceptionDetailsNotPresentWhenTraceErrorIsDisabled() $this->assertTrue($caught, 'Did not catch expected exception!'); $this->assertContainsCompat('actual module name is "baz"', $message); - $this->assertNotContainsCompat("Exception 'RuntimeException' with message 'Expected exception message'", $message); + $this->assertNotContainsCompat( + "Exception 'RuntimeException' with message 'Expected exception message'", + $message + ); $this->assertNotContainsCompat(__FILE__, $message); } From a69c3462c53b289e9014641f9a18b3dc70454255 Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 23 May 2019 15:32:27 +0100 Subject: [PATCH 08/10] Updated reference to current class also in PHPUnit 8 compatibility trait --- src/PHPUnit/TestCaseTypeHintTrait.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PHPUnit/TestCaseTypeHintTrait.php b/src/PHPUnit/TestCaseTypeHintTrait.php index e7640d804c..7bd62635ca 100644 --- a/src/PHPUnit/TestCaseTypeHintTrait.php +++ b/src/PHPUnit/TestCaseTypeHintTrait.php @@ -23,14 +23,14 @@ protected function tearDown() : void public static function setUpBeforeClass() : void { - if (method_exists(__CLASS__, 'setUpBeforeClassCompat')) { + if (method_exists(static::class, 'setUpBeforeClassCompat')) { static::setUpBeforeClassCompat(); } } public static function tearDownAfterClass() : void { - if (method_exists(__CLASS__, 'tearDownAfterClassCompat')) { + if (method_exists(static::class, 'tearDownAfterClassCompat')) { static::tearDownAfterClassCompat(); } } From f6040815854b5e229081d648baf7722d0d397482 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Wed, 12 Jun 2019 03:59:09 +1000 Subject: [PATCH 09/10] Add CHANGELOG for #76 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e06c626d30..8ae93d2fad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file, in reverse ### Added -- Nothing. +- [#76](https://github.com/zendframework/zend-test/pull/76) adds support for PhpUnit 8 ### Changed From 700a1f9eacb09f011f2aa747047bbd1df6773644 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Wed, 12 Jun 2019 04:08:51 +1000 Subject: [PATCH 10/10] Update dependency package name to be lowercase --- composer.json | 2 +- composer.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index cd0b252e45..73ce2a7106 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index 55a7ed50e3..559ee77c3b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "55540cf291f52e420c12aeeac8b1e880", + "content-hash": "5d7ec82ed524ab9ac008eeee868ab314", "packages": [ { "name": "container-interop/container-interop",