2015-06-26 12:03:42 -04:00
|
|
|
<?php
|
|
|
|
|
2016-07-28 10:44:13 -04:00
|
|
|
use Aviat\Ion\Config;
|
2015-06-26 16:39:10 -04:00
|
|
|
|
2015-06-26 12:03:42 -04:00
|
|
|
class ConfigTest extends AnimeClient_TestCase {
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->config = new Config([
|
2015-09-14 10:54:50 -04:00
|
|
|
'foo' => 'bar',
|
2015-09-14 15:49:20 -04:00
|
|
|
'asset_path' => '/assets',
|
2015-09-14 10:54:50 -04:00
|
|
|
'bar' => 'baz'
|
2015-06-26 12:03:42 -04:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2015-10-06 11:38:20 -04:00
|
|
|
public function testConfigGet()
|
2015-06-26 12:03:42 -04:00
|
|
|
{
|
2015-10-06 11:38:20 -04:00
|
|
|
$this->assertEquals('bar', $this->config->get('foo'));
|
|
|
|
$this->assertEquals('baz', $this->config->get('bar'));
|
|
|
|
$this->assertNull($this->config->get('baz'));
|
2015-10-15 22:00:09 -04:00
|
|
|
$this->assertNull($this->config->get(['apple', 'sauce', 'is']));
|
2015-06-26 12:03:42 -04:00
|
|
|
}
|
|
|
|
|
2015-10-15 09:25:30 -04:00
|
|
|
public function testConfigSet()
|
|
|
|
{
|
|
|
|
$this->config->set('foo', 'foobar');
|
|
|
|
$this->assertEquals('foobar', $this->config->get('foo'));
|
|
|
|
|
|
|
|
$this->config->set(['apple', 'sauce', 'is'], 'great');
|
2015-10-15 22:00:09 -04:00
|
|
|
$apple = $this->config->get('apple');
|
|
|
|
$this->assertEquals('great', $apple['sauce']['is'], "Config value not set correctly");
|
|
|
|
|
|
|
|
$this->assertEquals('great', $this->config->get(['apple', 'sauce', 'is']), "Array argument get for config failed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testConfigBadSet()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('InvalidArgumentException');
|
|
|
|
$this->config->set(NULL, FALSE);
|
2015-10-15 09:25:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function dataConfigDelete()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'top level delete' => [
|
|
|
|
'key' => 'apple',
|
|
|
|
'assertKeys' => [
|
|
|
|
[
|
|
|
|
'path' => ['apple', 'sauce', 'is'],
|
|
|
|
'expected' => NULL
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'path' => ['apple', 'sauce'],
|
|
|
|
'expected' => NULL
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'path' => 'apple',
|
|
|
|
'expected' => NULL
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
2015-10-15 22:00:09 -04:00
|
|
|
'mid level delete' => [
|
2015-10-15 09:25:30 -04:00
|
|
|
'key' => ['apple', 'sauce'],
|
|
|
|
'assertKeys' => [
|
|
|
|
[
|
|
|
|
'path' => ['apple', 'sauce', 'is'],
|
|
|
|
'expected' => NULL
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'path' => ['apple', 'sauce'],
|
|
|
|
'expected' => NULL
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'path' => 'apple',
|
2015-10-15 22:00:09 -04:00
|
|
|
'expected' => [
|
|
|
|
'sauce' => NULL
|
|
|
|
]
|
2015-10-15 09:25:30 -04:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'deep delete' => [
|
|
|
|
'key' => ['apple', 'sauce', 'is'],
|
|
|
|
'assertKeys' => [
|
|
|
|
[
|
|
|
|
'path' => ['apple', 'sauce', 'is'],
|
|
|
|
'expected' => NULL
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'path' => ['apple', 'sauce'],
|
2015-10-15 22:00:09 -04:00
|
|
|
'expected' => [
|
|
|
|
'is' => NULL
|
|
|
|
]
|
2015-10-15 09:25:30 -04:00
|
|
|
]
|
|
|
|
]
|
2015-10-15 22:00:09 -04:00
|
|
|
]
|
2015-10-15 09:25:30 -04:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataConfigDelete
|
|
|
|
*/
|
|
|
|
public function testConfigDelete($key, $assertKeys)
|
|
|
|
{
|
2015-10-15 22:00:09 -04:00
|
|
|
$config = new Config([]);
|
|
|
|
$config->set(['apple', 'sauce', 'is'], 'great');
|
|
|
|
$config->delete($key);
|
2015-10-15 09:25:30 -04:00
|
|
|
|
|
|
|
foreach($assertKeys as $pair)
|
|
|
|
{
|
2015-10-15 22:00:09 -04:00
|
|
|
$this->assertEquals($pair['expected'], $config->get($pair['path']));
|
2015-10-15 09:25:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-26 12:03:42 -04:00
|
|
|
public function testGetNonExistentConfigItem()
|
|
|
|
{
|
2015-10-06 11:38:20 -04:00
|
|
|
$this->assertNull($this->config->get('foobar'));
|
2015-06-26 12:03:42 -04:00
|
|
|
}
|
|
|
|
}
|