summaryrefslogtreecommitdiff
path: root/tests/Unit/Config
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Unit/Config')
-rw-r--r--tests/Unit/Config/ConfigServiceProviderTest.php45
-rw-r--r--tests/Unit/Config/ConfigTest.php115
2 files changed, 160 insertions, 0 deletions
diff --git a/tests/Unit/Config/ConfigServiceProviderTest.php b/tests/Unit/Config/ConfigServiceProviderTest.php
new file mode 100644
index 00000000..c8be4b7d
--- /dev/null
+++ b/tests/Unit/Config/ConfigServiceProviderTest.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Config;
+
+use Engelsystem\Application;
+use Engelsystem\Config\Config;
+use Engelsystem\Config\ConfigServiceProvider;
+use Engelsystem\Test\Unit\ServiceProviderTest;
+use PHPUnit_Framework_MockObject_MockObject;
+
+class ConfigServiceProviderTest extends ServiceProviderTest
+{
+ /**
+ * @covers \Engelsystem\Config\ConfigServiceProvider::register()
+ */
+ public function testRegister()
+ {
+ /** @var PHPUnit_Framework_MockObject_MockObject|Config $config */
+ $config = $this->getMockBuilder(Config::class)
+ ->getMock();
+
+ $app = $this->getApp(['make', 'instance', 'get']);
+ Application::setInstance($app);
+
+ $this->setExpects($app, 'make', [Config::class], $config);
+ $this->setExpects($app, 'instance', ['config', $config]);
+ $this->setExpects($app, 'get', ['path.config'], __DIR__ . '/../../../config', $this->atLeastOnce());
+
+ $this->setExpects($config, 'set', null, null, $this->exactly(2));
+ $this->setExpects($config, 'get', [null], []);
+
+ $configFile = __DIR__ . '/../../../config/config.php';
+ $configExists = file_exists($configFile);
+ if (!$configExists) {
+ file_put_contents($configFile, '<?php return [];');
+ }
+
+ $serviceProvider = new ConfigServiceProvider($app);
+ $serviceProvider->register();
+
+ if (!$configExists) {
+ unlink($configFile);
+ }
+ }
+}
diff --git a/tests/Unit/Config/ConfigTest.php b/tests/Unit/Config/ConfigTest.php
new file mode 100644
index 00000000..043599fd
--- /dev/null
+++ b/tests/Unit/Config/ConfigTest.php
@@ -0,0 +1,115 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Config;
+
+use Engelsystem\Config\Config;
+use PHPUnit\Framework\TestCase;
+
+class ConfigTest extends TestCase
+{
+ /**
+ * @covers \Engelsystem\Config\Config::get
+ */
+ public function testGet()
+ {
+ $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
+ */
+ public function testSet()
+ {
+ $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
+ */
+ public function testHas()
+ {
+ $config = new Config();
+
+ $this->assertFalse($config->has('test'));
+
+ $config->set('test', 'FooBar');
+ $this->assertTrue($config->has('test'));
+ }
+
+ /**
+ * @covers \Engelsystem\Config\Config::remove
+ */
+ public function testRemove()
+ {
+ $config = new Config();
+ $config->set(['foo' => 'bar', 'test' => '123']);
+
+ $config->remove('foo');
+ $this->assertEquals(['test' => '123'], $config->get(null));
+ }
+
+ /**
+ * @covers \Engelsystem\Config\Config::__get
+ */
+ public function testMagicGet()
+ {
+ $config = new Config();
+
+ $config->set('test', 'FooBar');
+ $this->assertEquals('FooBar', $config->test);
+ }
+
+ /**
+ * @covers \Engelsystem\Config\Config::__set
+ */
+ public function testMagicSet()
+ {
+ $config = new Config();
+
+ $config->test = 'FooBar';
+ $this->assertEquals('FooBar', $config->get('test'));
+ }
+
+ /**
+ * @covers \Engelsystem\Config\Config::__isset
+ */
+ public function testMagicIsset()
+ {
+ $config = new Config();
+
+ $this->assertFalse(isset($config->test));
+
+ $config->set('test', 'FooBar');
+ $this->assertTrue(isset($config->test));
+ }
+
+ /**
+ * @covers \Engelsystem\Config\Config::__unset
+ */
+ public function testMagicUnset()
+ {
+ $config = new Config();
+ $config->set(['foo' => 'bar', 'test' => '123']);
+
+ unset($config->foo);
+ $this->assertEquals(['test' => '123'], $config->get(null));
+ }
+}