X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fconfig%2FConfigManagerTest.php;h=65d8ba2c64f70aa58893a9a31f0ae0d08b42c2d5;hb=a5a9cf23acd1248585173aa32757d9720b5f2d62;hp=436e3d673850245ecd16c027716df25e94edc5ca;hpb=278d9ee2836df7d805845077f26f8cecd16f0f4f;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php index 436e3d67..65d8ba2c 100644 --- a/tests/config/ConfigManagerTest.php +++ b/tests/config/ConfigManagerTest.php @@ -1,4 +1,5 @@ conf = new ConfigManager('tests/utils/config/configJson'); } @@ -80,35 +81,58 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase $this->assertEquals('testSetWriteGetNested', $this->conf->get('foo.bar.key.stuff')); } + public function testSetDeleteNested() + { + $this->conf->set('foo.bar.key.stuff', 'testSetDeleteNested'); + $this->assertTrue($this->conf->exists('foo.bar')); + $this->assertTrue($this->conf->exists('foo.bar.key.stuff')); + $this->assertEquals('testSetDeleteNested', $this->conf->get('foo.bar.key.stuff')); + + $this->conf->remove('foo.bar'); + $this->assertFalse($this->conf->exists('foo.bar.key.stuff')); + $this->assertFalse($this->conf->exists('foo.bar')); + } + /** * Set with an empty key. - * - * @expectedException Exception - * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*# */ public function testSetEmptyKey() { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#'); + $this->conf->set('', 'stuff'); } /** * Set with an array key. - * - * @expectedException Exception - * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*# */ public function testSetArrayKey() { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#'); + $this->conf->set(array('foo' => 'bar'), 'stuff'); } + /** + * Remove with an empty key. + */ + public function testRmoveEmptyKey() + { + $this->expectException(\Exception::class); + $this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#'); + + $this->conf->remove(''); + } + /** * Try to write the config without mandatory parameter (e.g. 'login'). - * - * @expectedException MissingFieldConfigException */ public function testWriteMissingParameter() { + $this->expectException(\Shaarli\Config\Exception\MissingFieldConfigException::class); + $this->conf->setConfigFile('tests/utils/config/configTmp'); $this->assertFalse(file_exists($this->conf->getConfigFileExt())); $this->conf->reload();