diff --git a/.gitignore b/.gitignore index f2db597..05006ec 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ composer.lock vendor phpunit.xml clover.xml +.phpunit.result.cache +.idea/ 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 diff --git a/tests/phpunit/WordPressCoreInstallerTest.php b/tests/phpunit/WordPressCoreInstallerTest.php index 3cc5593..539bf36 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() ); @@ -123,11 +115,11 @@ 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->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' ); @@ -138,11 +130,14 @@ public function testTwoPackagesCannotShareDirectory() { } /** - * @dataProvider dataProviderSensitiveDirectories - * @expectedException \InvalidArgumentException - * @expectedExceptionMessageRegExp /Warning! .+? is an invalid WordPress install directory \(from test\/package\)!/ + * @dataProvider dataProviderSensitiveDirectories */ public function testSensitiveInstallDirectoriesNotAllowed( $directory ) { + $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' ); @@ -157,7 +152,11 @@ public function dataProviderSensitiveDirectories() { ); } - private function resetInstallPaths() { + /** + * @before + * @afterClass + */ + public static function resetInstallPaths() { $prop = new \ReflectionProperty( '\johnpbloch\Composer\WordPressCoreInstaller', '_installedPaths' ); $prop->setAccessible( true ); $prop->setValue( array() ); @@ -173,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 ); + } + } + }