Skip to content

Commit 5dd0e54

Browse files
committed
Use correct exception expectation for given version of phpunit
1 parent 9a7cb23 commit 5dd0e54

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

tests/phpunit/WordPressCoreInstallerTest.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ public function testCorePackageDefaultDoesNotOverrideRootDirectoryDefinition() {
116116
}
117117

118118
public function testTwoPackagesCannotShareDirectory() {
119-
$this->expectException( '\InvalidArgumentException' );
120-
$this->expectExceptionMessage( 'Two packages (test/bazbat and test/foobar) cannot share the same directory!' );
119+
$this->jpbExpectException(
120+
'\InvalidArgumentException',
121+
'Two packages (test/bazbat and test/foobar) cannot share the same directory!'
122+
);
121123
$composer = $this->createComposer();
122124
$installer = new WordPressCoreInstaller( new NullIO(), $composer );
123125
$package1 = new Package( 'test/foobar', '1.1.1.1', '1.1.1.1' );
@@ -131,8 +133,11 @@ public function testTwoPackagesCannotShareDirectory() {
131133
* @dataProvider dataProviderSensitiveDirectories
132134
*/
133135
public function testSensitiveInstallDirectoriesNotAllowed( $directory ) {
134-
$this->expectException( '\InvalidArgumentException' );
135-
$this->expectExceptionMessageRegExp( '/Warning! .+? is an invalid WordPress install directory \(from test\/package\)!/' );
136+
$this->jpbExpectException(
137+
'\InvalidArgumentException',
138+
'/Warning! .+? is an invalid WordPress install directory \(from test\/package\)!/',
139+
true
140+
);
136141
$composer = $this->createComposer();
137142
$installer = new WordPressCoreInstaller( new NullIO(), $composer );
138143
$package = new Package( 'test/package', '1.1.0.0', '1.1' );
@@ -167,4 +172,17 @@ private function createComposer() {
167172
return $composer;
168173
}
169174

175+
private function jpbExpectException( $class, $message = '', $isRegExp = false ) {
176+
if ( method_exists( $this, 'expectException' ) ) {
177+
$this->expectException($class);
178+
if ( $message ) {
179+
$isRegExp || $this->expectExceptionMessage( $message );
180+
$isRegExp && $this->expectExceptionMessageRegExp( $message );
181+
}
182+
} else {
183+
$isRegExp || $this->setExpectedException( $class, $message );
184+
$isRegExp && $this->setExpectedExceptionRegExp( $class, $message );
185+
}
186+
}
187+
170188
}

0 commit comments

Comments
 (0)