From a42f43d5cd73b5ef52e82e8cd2b235b8a334e46a Mon Sep 17 00:00:00 2001 From: "John P. Bloch" Date: Sun, 24 Feb 2019 13:59:46 -0600 Subject: [PATCH 1/8] Use annotations to reset installer paths This replaces the setUp/tearDown methods which have changed their signature in PhpUnit 8.0 --- tests/phpunit/WordPressCoreInstallerTest.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/phpunit/WordPressCoreInstallerTest.php b/tests/phpunit/WordPressCoreInstallerTest.php index 3cc5593..b2f6a26 100644 --- a/tests/phpunit/WordPressCoreInstallerTest.php +++ b/tests/phpunit/WordPressCoreInstallerTest.php @@ -31,14 +31,6 @@ class WordPressCoreInstallerTest extends TestCase { - protected function setUp() { - $this->resetInstallPaths(); - } - - protected function tearDown() { - $this->resetInstallPaths(); - } - public function testSupports() { $installer = new WordPressCoreInstaller( new NullIO(), $this->createComposer() ); @@ -157,7 +149,11 @@ public function dataProviderSensitiveDirectories() { ); } - private function resetInstallPaths() { + /** + * @beforeClass + * @afterClass + */ + public static function resetInstallPaths() { $prop = new \ReflectionProperty( '\johnpbloch\Composer\WordPressCoreInstaller', '_installedPaths' ); $prop->setAccessible( true ); $prop->setValue( array() ); From b08cdc11d7d14b4281fa1a93c069fbe5dc7a03a1 Mon Sep 17 00:00:00 2001 From: John P Bloch Date: Sun, 24 Feb 2019 14:27:39 -0600 Subject: [PATCH 2/8] Ignore phpunit result cache --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f2db597..a4d8063 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.lock vendor phpunit.xml clover.xml +.phpunit.result.cache From eea99921484bde64a415ce577aa3fa3de658f178 Mon Sep 17 00:00:00 2001 From: John P Bloch Date: Sun, 24 Feb 2019 14:28:32 -0600 Subject: [PATCH 3/8] Ignore phpstorm config --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a4d8063..05006ec 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ vendor phpunit.xml clover.xml .phpunit.result.cache +.idea/ From b2ae675e45b3bf965efd6c15bfe6bf04dc2848c0 Mon Sep 17 00:00:00 2001 From: John P Bloch Date: Sun, 24 Feb 2019 14:32:16 -0600 Subject: [PATCH 4/8] Stop using exception annotations --- tests/phpunit/WordPressCoreInstallerTest.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/WordPressCoreInstallerTest.php b/tests/phpunit/WordPressCoreInstallerTest.php index b2f6a26..8f7dbf7 100644 --- a/tests/phpunit/WordPressCoreInstallerTest.php +++ b/tests/phpunit/WordPressCoreInstallerTest.php @@ -115,11 +115,9 @@ public function testCorePackageDefaultDoesNotOverrideRootDirectoryDefinition() { $this->assertEquals( 'wp', $installer->getInstallPath( $package ) ); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Two packages (test/bazbat and test/foobar) cannot share the same directory! - */ public function testTwoPackagesCannotShareDirectory() { + $this->expectException( '\InvalidArgumentException' ); + $this->expectExceptionMessage( 'Two packages (test/bazbat and test/foobar) cannot share the same directory!' ); $composer = $this->createComposer(); $installer = new WordPressCoreInstaller( new NullIO(), $composer ); $package1 = new Package( 'test/foobar', '1.1.1.1', '1.1.1.1' ); @@ -131,10 +129,10 @@ public function testTwoPackagesCannotShareDirectory() { /** * @dataProvider dataProviderSensitiveDirectories - * @expectedException \InvalidArgumentException - * @expectedExceptionMessageRegExp /Warning! .+? is an invalid WordPress install directory \(from test\/package\)!/ */ public function testSensitiveInstallDirectoriesNotAllowed( $directory ) { + $this->expectException( '\InvalidArgumentException' ); + $this->expectExceptionMessageRegExp( '/Warning! .+? is an invalid WordPress install directory \(from test\/package\)!/' ); $composer = $this->createComposer(); $installer = new WordPressCoreInstaller( new NullIO(), $composer ); $package = new Package( 'test/package', '1.1.0.0', '1.1' ); From 78c0e1adc4454b9033d2541e4d74f8f6c3a9c386 Mon Sep 17 00:00:00 2001 From: John P Bloch Date: Sun, 24 Feb 2019 14:36:54 -0600 Subject: [PATCH 5/8] Fix annotation beforeClass only runs once before the test suite, whereas before runs before each test. Now the install paths get reset before each test and they get reset after the whole suite. --- tests/phpunit/WordPressCoreInstallerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/WordPressCoreInstallerTest.php b/tests/phpunit/WordPressCoreInstallerTest.php index 8f7dbf7..d5e3b4e 100644 --- a/tests/phpunit/WordPressCoreInstallerTest.php +++ b/tests/phpunit/WordPressCoreInstallerTest.php @@ -148,7 +148,7 @@ public function dataProviderSensitiveDirectories() { } /** - * @beforeClass + * @before * @afterClass */ public static function resetInstallPaths() { From 3590928fad140808e49d4f01966574e8976021e8 Mon Sep 17 00:00:00 2001 From: John P Bloch Date: Sun, 24 Feb 2019 14:37:32 -0600 Subject: [PATCH 6/8] Add php 7.3 to the list of PHP versions to test against --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 329b5b9..6284a3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ php: - '7.0' - '7.1' - '7.2' + - '7.3' before_script: - composer update script: composer test From 9a7cb238fb24d8e53481bd480434a84d450c421f Mon Sep 17 00:00:00 2001 From: John P Bloch Date: Sun, 24 Feb 2019 15:22:01 -0600 Subject: [PATCH 7/8] Whitespace --- tests/phpunit/WordPressCoreInstallerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/WordPressCoreInstallerTest.php b/tests/phpunit/WordPressCoreInstallerTest.php index d5e3b4e..051119d 100644 --- a/tests/phpunit/WordPressCoreInstallerTest.php +++ b/tests/phpunit/WordPressCoreInstallerTest.php @@ -128,7 +128,7 @@ public function testTwoPackagesCannotShareDirectory() { } /** - * @dataProvider dataProviderSensitiveDirectories + * @dataProvider dataProviderSensitiveDirectories */ public function testSensitiveInstallDirectoriesNotAllowed( $directory ) { $this->expectException( '\InvalidArgumentException' ); From 5dd0e54bb3948d59baa36580697230a6590c8440 Mon Sep 17 00:00:00 2001 From: John P Bloch Date: Sun, 24 Feb 2019 15:23:05 -0600 Subject: [PATCH 8/8] Use correct exception expectation for given version of phpunit --- tests/phpunit/WordPressCoreInstallerTest.php | 26 +++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/WordPressCoreInstallerTest.php b/tests/phpunit/WordPressCoreInstallerTest.php index 051119d..539bf36 100644 --- a/tests/phpunit/WordPressCoreInstallerTest.php +++ b/tests/phpunit/WordPressCoreInstallerTest.php @@ -116,8 +116,10 @@ public function testCorePackageDefaultDoesNotOverrideRootDirectoryDefinition() { } public function testTwoPackagesCannotShareDirectory() { - $this->expectException( '\InvalidArgumentException' ); - $this->expectExceptionMessage( 'Two packages (test/bazbat and test/foobar) cannot share the same directory!' ); + $this->jpbExpectException( + '\InvalidArgumentException', + 'Two packages (test/bazbat and test/foobar) cannot share the same directory!' + ); $composer = $this->createComposer(); $installer = new WordPressCoreInstaller( new NullIO(), $composer ); $package1 = new Package( 'test/foobar', '1.1.1.1', '1.1.1.1' ); @@ -131,8 +133,11 @@ public function testTwoPackagesCannotShareDirectory() { * @dataProvider dataProviderSensitiveDirectories */ public function testSensitiveInstallDirectoriesNotAllowed( $directory ) { - $this->expectException( '\InvalidArgumentException' ); - $this->expectExceptionMessageRegExp( '/Warning! .+? is an invalid WordPress install directory \(from test\/package\)!/' ); + $this->jpbExpectException( + '\InvalidArgumentException', + '/Warning! .+? is an invalid WordPress install directory \(from test\/package\)!/', + true + ); $composer = $this->createComposer(); $installer = new WordPressCoreInstaller( new NullIO(), $composer ); $package = new Package( 'test/package', '1.1.0.0', '1.1' ); @@ -167,4 +172,17 @@ private function createComposer() { return $composer; } + private function jpbExpectException( $class, $message = '', $isRegExp = false ) { + if ( method_exists( $this, 'expectException' ) ) { + $this->expectException($class); + if ( $message ) { + $isRegExp || $this->expectExceptionMessage( $message ); + $isRegExp && $this->expectExceptionMessageRegExp( $message ); + } + } else { + $isRegExp || $this->setExpectedException( $class, $message ); + $isRegExp && $this->setExpectedExceptionRegExp( $class, $message ); + } + } + }