2017-03-24 16:18:02 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
|
|
|
* Ion
|
|
|
|
*
|
|
|
|
* Building blocks for web development
|
|
|
|
*
|
2018-01-17 12:45:58 -05:00
|
|
|
* PHP version 7.1
|
2017-03-24 16:18:02 -04:00
|
|
|
*
|
|
|
|
* @package Ion
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2018-01-17 12:45:58 -05:00
|
|
|
* @copyright 2015 - 2018 Timothy J. Warren
|
2017-03-24 16:18:02 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2018-01-17 16:35:01 -05:00
|
|
|
* @version 2.3.0
|
2017-03-24 16:18:02 -04:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/ion
|
|
|
|
*/
|
2016-08-04 14:55:37 -04:00
|
|
|
|
2016-08-29 11:34:25 -04:00
|
|
|
namespace Aviat\Ion\Tests;
|
|
|
|
|
2016-08-04 14:55:37 -04:00
|
|
|
use Aviat\Ion\Config;
|
|
|
|
|
2016-10-19 13:24:08 -04:00
|
|
|
class ConfigTest extends Ion_TestCase {
|
2016-08-04 14:55:37 -04:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->config = new Config([
|
|
|
|
'foo' => 'bar',
|
|
|
|
'asset_path' => '/assets',
|
|
|
|
'bar' => 'baz'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testConfigGet()
|
|
|
|
{
|
|
|
|
$this->assertEquals('bar', $this->config->get('foo'));
|
|
|
|
$this->assertEquals('baz', $this->config->get('bar'));
|
|
|
|
$this->assertNull($this->config->get('baz'));
|
|
|
|
$this->assertNull($this->config->get(['apple', 'sauce', 'is']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testConfigSet()
|
|
|
|
{
|
|
|
|
$ret = $this->config->set('foo', 'foobar');
|
|
|
|
$this->assertInstanceOf('Aviat\Ion\Config', $ret);
|
|
|
|
$this->assertEquals('foobar', $this->config->get('foo'));
|
|
|
|
|
|
|
|
$this->config->set(['apple', 'sauce', 'is'], 'great');
|
|
|
|
$apple = $this->config->get('apple');
|
|
|
|
$this->assertEquals('great', $apple['sauce']['is'], "Config value not set correctly");
|
2016-08-29 11:34:25 -04:00
|
|
|
|
2016-08-04 14:55:37 -04:00
|
|
|
$this->assertEquals('great', $this->config->get(['apple', 'sauce', 'is']), "Array argument get for config failed.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testConfigBadSet()
|
|
|
|
{
|
2016-08-29 11:34:25 -04:00
|
|
|
$this->expectException('InvalidArgumentException');
|
2016-08-04 14:55:37 -04:00
|
|
|
$this->config->set(NULL, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'mid level delete' => [
|
|
|
|
'key' => ['apple', 'sauce'],
|
|
|
|
'assertKeys' => [
|
|
|
|
[
|
|
|
|
'path' => ['apple', 'sauce', 'is'],
|
|
|
|
'expected' => NULL
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'path' => ['apple', 'sauce'],
|
|
|
|
'expected' => NULL
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'path' => 'apple',
|
|
|
|
'expected' => [
|
|
|
|
'sauce' => NULL
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'deep delete' => [
|
|
|
|
'key' => ['apple', 'sauce', 'is'],
|
|
|
|
'assertKeys' => [
|
|
|
|
[
|
|
|
|
'path' => ['apple', 'sauce', 'is'],
|
|
|
|
'expected' => NULL
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'path' => ['apple', 'sauce'],
|
|
|
|
'expected' => [
|
|
|
|
'is' => NULL
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataConfigDelete
|
|
|
|
*/
|
|
|
|
public function testConfigDelete($key, $assertKeys)
|
|
|
|
{
|
|
|
|
$config = new Config([]);
|
|
|
|
$config->set(['apple', 'sauce', 'is'], 'great');
|
|
|
|
$config->delete($key);
|
|
|
|
|
|
|
|
foreach($assertKeys as $pair)
|
|
|
|
{
|
|
|
|
$this->assertEquals($pair['expected'], $config->get($pair['path']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetNonExistentConfigItem()
|
|
|
|
{
|
|
|
|
$this->assertNull($this->config->get('foobar'));
|
|
|
|
}
|
|
|
|
}
|