Skip to content

Commit

Permalink
Merge pull request #24 from johnpbloch/fix/update-tests
Browse files Browse the repository at this point in the history
Fix test failures in Travis CI
  • Loading branch information
johnpbloch authored Feb 24, 2019
2 parents 683ef60 + 5dd0e54 commit ec541ae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ composer.lock
vendor
phpunit.xml
clover.xml
.phpunit.result.cache
.idea/
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ php:
- '7.0'
- '7.1'
- '7.2'
- '7.3'
before_script:
- composer update
script: composer test
Expand Down
44 changes: 28 additions & 16 deletions tests/phpunit/WordPressCoreInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() );

Expand Down Expand Up @@ -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' );
Expand All @@ -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' );
Expand All @@ -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() );
Expand All @@ -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 );
}
}

}

0 comments on commit ec541ae

Please sign in to comment.