Skip to content

Commit

Permalink
Fix assertions after minor PHPUnit upgrade
Browse files Browse the repository at this point in the history
PHPUnit 8.5.3 shows deprecation warnings when calling
expectExceptionMessageRegExp. PHPUnit was updated from 8.5.2 to 8.5.2 at
the beginning of this branch.

See sebastianbergmann/phpunit#4133
  • Loading branch information
gbirke committed Apr 6, 2020
1 parent 0b5a0ac commit 5806a98
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function testSandboxedWebContentDoesntExist_exceptionIsThrown(): void {
$factory->setContentProvider( $provider );

$this->expectException( Twig_Error_Runtime::class );
$this->expectExceptionMessageRegExp( '/An exception occured rendering \'lorem\'/' );
$this->expectExceptionMessageMatches( '/An exception occured rendering \'lorem\'/' );

$factory->getLayoutTemplate( 'template_with_content.twig' )->render( [] );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testGivenNonexistentFiles_exceptionIsThrown() {
$fileFetcher = new StubFileFetcher( self::VALID_CONFIGURATION );
$loader = new CampaignConfigurationLoader( $filesystem, $fileFetcher, new VoidCache() );

$this->expectExceptionMessageRegExp( '/No campaign configuration files found/' );
$this->expectExceptionMessageMatches( '/No campaign configuration files found/' );
$loader->loadCampaignConfiguration( 'campaigns.yml' );
}

Expand Down
15 changes: 8 additions & 7 deletions tests/Unit/Infrastructure/ConfigReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use FileFetcher\SimpleFileFetcher;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use WMDE\Fundraising\Frontend\Infrastructure\ConfigReader;

Expand All @@ -16,7 +17,7 @@
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class ConfigReaderTest extends \PHPUnit\Framework\TestCase {
class ConfigReaderTest extends TestCase {

/**
* @var vfsStreamDirectory
Expand Down Expand Up @@ -104,15 +105,15 @@ public function testWhenDistFileDoesNotExist_exceptionIsThrown(): void {
$reader = new ConfigReader( new SimpleFileFetcher(), $this->distPath . 'foo', $this->emptyPath );

$this->expectException( RuntimeException::class );
$this->expectExceptionMessageRegExp( '/Cannot read config file at path.*/' );
$this->expectExceptionMessageMatches( '/Cannot read config file at path.*/' );
$reader->getConfig();
}

public function testWhenInstanceFileDoesNotExist_exceptionIsThrown(): void {
$reader = new \WMDE\Fundraising\Frontend\Infrastructure\ConfigReader( new SimpleFileFetcher(), $this->distPath, $this->emptyPath . 'foo' );
$reader = new ConfigReader( new SimpleFileFetcher(), $this->distPath, $this->emptyPath . 'foo' );

$this->expectException( RuntimeException::class );
$this->expectExceptionMessageRegExp( '/Cannot read config file at path.*/' );
$this->expectExceptionMessageMatches( '/Cannot read config file at path.*/' );
$reader->getConfig();
}

Expand All @@ -122,17 +123,17 @@ public function testWhenConfigIsNotJson_exceptionIsThrown(): void {
$reader = new ConfigReader( new SimpleFileFetcher(), $notJsonPath );

$this->expectException( RuntimeException::class );
$this->expectExceptionMessageRegExp( '/No valid config data found in config file at path.*/' );
$this->expectExceptionMessageMatches( '/No valid config data found in config file at path.*/' );
$reader->getConfig();
}

public function testWhenConfigJsonIsNotArray_exceptionIsThrown(): void {
$notArrayPath = vfsStream::newFile( 'not-array.json' )->at( $this->dir )->withContent( '42' )->url();

$reader = new \WMDE\Fundraising\Frontend\Infrastructure\ConfigReader( new SimpleFileFetcher(), $notArrayPath );
$reader = new ConfigReader( new SimpleFileFetcher(), $notArrayPath );

$this->expectException( RuntimeException::class );
$this->expectExceptionMessageRegExp( '/No valid config data found in config file at path.*/' );
$this->expectExceptionMessageMatches( '/No valid config data found in config file at path.*/' );
$reader->getConfig();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Infrastructure/EnvironmentBootstrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public function testGivenMissingDistFile_exceptionIsThrown() {
$path = vfsStream::setup( self::CONFIGDIR, null, [
'config.dev.json' => '{}'
] );
$this->expectExceptionMessageRegExp( '/dist/' );
$this->expectExceptionMessageMatches( '/dist/' );
( new EnvironmentBootstrapper( 'dev' ) )->getConfigurationPathsForEnvironment( $path->url() );
}

public function testGivenMissingEnvironmentFile_exceptionIsThrown() {
$path = vfsStream::setup( self::CONFIGDIR, null, [
'config.dist.json' => '{}'
] );
$this->expectExceptionMessageRegExp( '/dev/' );
$this->expectExceptionMessageMatches( '/dev/' );
( new EnvironmentBootstrapper( 'dev' ) )->getConfigurationPathsForEnvironment( $path->url() );
}

Expand Down

0 comments on commit 5806a98

Please sign in to comment.