wiki.techinc.nl/tests/phpunit/unit/includes/Settings/Source/FileSourceTest.php
Tim Starling be3018b268 Just another 80 or so PHPStorm inspection fixes (#4)
* Unnecessary regex modifier. I agree with this inspection which flags
  /s modifiers on regexes that don't use a dot.
* Property declared dynamically.
* Unused local variable. But it's acceptable for an unused local
  variable to take the return value of a method under test, when it is
  being tested for its side-effects. And it's acceptable for an unused
  local variable to document unused list expansion elements, or the
  nature of array keys in a foreach.

Change-Id: I067b5b45dd1138c00e7269b66d3d1385f202fe7f
2023-03-25 00:39:06 +00:00

68 lines
1.8 KiB
PHP

<?php
namespace MediaWiki\Tests\Unit\Settings\Source;
use MediaWiki\Settings\SettingsBuilderException;
use MediaWiki\Settings\Source\FileSource;
use MediaWiki\Settings\Source\Format\JsonFormat;
use PHPUnit\Framework\TestCase;
/**
* @covers \MediaWiki\Settings\Source\FileSource
*/
class FileSourceTest extends TestCase {
public function testAllowsStaleLoad() {
$source = new FileSource( __DIR__ . 'foo.json' );
$this->assertFalse( $source->allowsStaleLoad() );
}
public function testLoad() {
$source = new FileSource( __DIR__ . '/fixtures/settings.json' );
$this->assertSame(
[ 'config' => [ 'MySetting' => 'BlaBla' ] ],
$source->load()
);
}
public function testLoadFormat() {
$source = new FileSource( __DIR__ . '/fixtures/settings.json', new JsonFormat() );
$this->assertSame(
[ 'config' => [ 'MySetting' => 'BlaBla' ] ],
$source->load()
);
}
public function testLoadBadFormat() {
$source = new FileSource( __DIR__ . '/fixtures/bad.txt', new JsonFormat() );
$this->expectException( SettingsBuilderException::class );
$settings = $source->load();
}
public function testLoadDirectory() {
$source = new FileSource( __DIR__ . '/fixtures/dir.json' );
$this->expectException( SettingsBuilderException::class );
$settings = $source->load();
}
public function testLoadNoSuitableFormats() {
$source = new FileSource( __DIR__ . '/fixtures/settings.toml', new JsonFormat() );
$this->expectException( SettingsBuilderException::class );
$settings = $source->load();
}
public function testGetHashKey() {
$source = new FileSource( __DIR__ . '/fixtures/settings.json' );
// We can't reliably mock the filesystem stat so simply ensure the
// method returns and is non-zero in length
$this->assertNotEmpty( $source->getHashKey() );
}
}