Skip to content

Commit ec541ae

Browse files
authored
Merge pull request johnpbloch#24 from johnpbloch/fix/update-tests
Fix test failures in Travis CI
2 parents 683ef60 + 5dd0e54 commit ec541ae

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ composer.lock
22
vendor
33
phpunit.xml
44
clover.xml
5+
.phpunit.result.cache
6+
.idea/

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ php:
1010
- '7.0'
1111
- '7.1'
1212
- '7.2'
13+
- '7.3'
1314
before_script:
1415
- composer update
1516
script: composer test

tests/phpunit/WordPressCoreInstallerTest.php

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@
3131

3232
class WordPressCoreInstallerTest extends TestCase {
3333

34-
protected function setUp() {
35-
$this->resetInstallPaths();
36-
}
37-
38-
protected function tearDown() {
39-
$this->resetInstallPaths();
40-
}
41-
4234
public function testSupports() {
4335
$installer = new WordPressCoreInstaller( new NullIO(), $this->createComposer() );
4436

@@ -123,11 +115,11 @@ public function testCorePackageDefaultDoesNotOverrideRootDirectoryDefinition() {
123115
$this->assertEquals( 'wp', $installer->getInstallPath( $package ) );
124116
}
125117

126-
/**
127-
* @expectedException \InvalidArgumentException
128-
* @expectedExceptionMessage Two packages (test/bazbat and test/foobar) cannot share the same directory!
129-
*/
130118
public function testTwoPackagesCannotShareDirectory() {
119+
$this->jpbExpectException(
120+
'\InvalidArgumentException',
121+
'Two packages (test/bazbat and test/foobar) cannot share the same directory!'
122+
);
131123
$composer = $this->createComposer();
132124
$installer = new WordPressCoreInstaller( new NullIO(), $composer );
133125
$package1 = new Package( 'test/foobar', '1.1.1.1', '1.1.1.1' );
@@ -138,11 +130,14 @@ public function testTwoPackagesCannotShareDirectory() {
138130
}
139131

140132
/**
141-
* @dataProvider dataProviderSensitiveDirectories
142-
* @expectedException \InvalidArgumentException
143-
* @expectedExceptionMessageRegExp /Warning! .+? is an invalid WordPress install directory \(from test\/package\)!/
133+
* @dataProvider dataProviderSensitiveDirectories
144134
*/
145135
public function testSensitiveInstallDirectoriesNotAllowed( $directory ) {
136+
$this->jpbExpectException(
137+
'\InvalidArgumentException',
138+
'/Warning! .+? is an invalid WordPress install directory \(from test\/package\)!/',
139+
true
140+
);
146141
$composer = $this->createComposer();
147142
$installer = new WordPressCoreInstaller( new NullIO(), $composer );
148143
$package = new Package( 'test/package', '1.1.0.0', '1.1' );
@@ -157,7 +152,11 @@ public function dataProviderSensitiveDirectories() {
157152
);
158153
}
159154

160-
private function resetInstallPaths() {
155+
/**
156+
* @before
157+
* @afterClass
158+
*/
159+
public static function resetInstallPaths() {
161160
$prop = new \ReflectionProperty( '\johnpbloch\Composer\WordPressCoreInstaller', '_installedPaths' );
162161
$prop->setAccessible( true );
163162
$prop->setValue( array() );
@@ -173,4 +172,17 @@ private function createComposer() {
173172
return $composer;
174173
}
175174

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+
176188
}

0 commit comments

Comments
 (0)