2017-09-19 21:19:56 +02:00
|
|
|
<?php
|
|
|
|
|
2017-10-31 14:23:23 +01:00
|
|
|
namespace Engelsystem\Test\Unit\Config;
|
2017-09-19 21:19:56 +02:00
|
|
|
|
|
|
|
use Engelsystem\Config\Config;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class ConfigTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Config\Config::get
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testGet(): void
|
2017-09-19 21:19:56 +02:00
|
|
|
{
|
|
|
|
$config = new Config();
|
|
|
|
|
|
|
|
$config->set('test', 'FooBar');
|
|
|
|
$this->assertEquals(['test' => 'FooBar'], $config->get(null));
|
|
|
|
$this->assertEquals('FooBar', $config->get('test'));
|
|
|
|
|
|
|
|
$this->assertEquals('defaultValue', $config->get('notExisting', 'defaultValue'));
|
|
|
|
|
|
|
|
$this->assertNull($config->get('notExisting'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Config\Config::set
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testSet(): void
|
2017-09-19 21:19:56 +02:00
|
|
|
{
|
|
|
|
$config = new Config();
|
|
|
|
|
|
|
|
$config->set('test', 'FooBar');
|
|
|
|
$this->assertEquals('FooBar', $config->get('test'));
|
|
|
|
|
|
|
|
$config->set([
|
|
|
|
'name' => 'Engelsystem',
|
|
|
|
'mail' => ['user' => 'test'],
|
|
|
|
]);
|
|
|
|
$this->assertEquals('Engelsystem', $config->get('name'));
|
|
|
|
$this->assertEquals(['user' => 'test'], $config->get('mail'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Config\Config::has
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testHas(): void
|
2017-09-19 21:19:56 +02:00
|
|
|
{
|
|
|
|
$config = new Config();
|
|
|
|
|
|
|
|
$this->assertFalse($config->has('test'));
|
|
|
|
|
|
|
|
$config->set('test', 'FooBar');
|
|
|
|
$this->assertTrue($config->has('test'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Config\Config::remove
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testRemove(): void
|
2017-09-19 21:19:56 +02:00
|
|
|
{
|
|
|
|
$config = new Config();
|
|
|
|
$config->set(['foo' => 'bar', 'test' => '123']);
|
|
|
|
|
|
|
|
$config->remove('foo');
|
|
|
|
$this->assertEquals(['test' => '123'], $config->get(null));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Config\Config::__get
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testMagicGet(): void
|
2017-09-19 21:19:56 +02:00
|
|
|
{
|
|
|
|
$config = new Config();
|
|
|
|
|
|
|
|
$config->set('test', 'FooBar');
|
|
|
|
$this->assertEquals('FooBar', $config->test);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Config\Config::__set
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testMagicSet(): void
|
2017-09-19 21:19:56 +02:00
|
|
|
{
|
|
|
|
$config = new Config();
|
|
|
|
|
|
|
|
$config->test = 'FooBar';
|
|
|
|
$this->assertEquals('FooBar', $config->get('test'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Config\Config::__isset
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testMagicIsset(): void
|
2017-09-19 21:19:56 +02:00
|
|
|
{
|
|
|
|
$config = new Config();
|
|
|
|
|
|
|
|
$this->assertFalse(isset($config->test));
|
|
|
|
|
|
|
|
$config->set('test', 'FooBar');
|
|
|
|
$this->assertTrue(isset($config->test));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Config\Config::__unset
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
public function testMagicUnset(): void
|
2017-09-19 21:19:56 +02:00
|
|
|
{
|
|
|
|
$config = new Config();
|
|
|
|
$config->set(['foo' => 'bar', 'test' => '123']);
|
|
|
|
|
|
|
|
unset($config->foo);
|
|
|
|
$this->assertEquals(['test' => '123'], $config->get(null));
|
|
|
|
}
|
|
|
|
}
|