From 3678bc7f68cd5f7e4336877f69684f51e03e5628 Mon Sep 17 00:00:00 2001 From: Sotaro KARASAWA Date: Thu, 8 Sep 2016 16:28:57 +0900 Subject: [PATCH 1/2] Add test for ArrayResourceTrait --- tests/Components/ArrayResourceTraitTest.php | 91 +++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/Components/ArrayResourceTraitTest.php diff --git a/tests/Components/ArrayResourceTraitTest.php b/tests/Components/ArrayResourceTraitTest.php new file mode 100644 index 0000000..c750d98 --- /dev/null +++ b/tests/Components/ArrayResourceTraitTest.php @@ -0,0 +1,91 @@ + 1, + 'db' => [ + 'dsn' => 'mysql:123', + 'user' => 'aoi_miyazaki', + ], + ]; + $obj = new ConcreteResource2($data); + + $this->assertEquals(1, $obj->getResource('config1')); + + $this->assertSame($data, $obj->getResource(), 'get all'); + $this->assertSame($data, $obj->getResourceData(), 'get all'); + + $this->assertEquals('aoi_miyazaki', $obj->getResource('db.user')); + $this->assertSame([ + 'dsn' => 'mysql:123', + 'user' => 'aoi_miyazaki', + ], $obj->getResource('db')); + $this->assertEquals('aoi-no-password', $obj->getResource('db.password', 'aoi-no-password'), 'default'); + + $this->assertEquals(null, $obj->getResource('db.user.name')); + + // set + $obj->setResource('config1', 2); + $this->assertEquals(2, $obj->getResource('config1')); + + $obj->setResource('db.user', 'aya_ueto'); + $this->assertEquals('aya_ueto', $obj->getResource('db.user')); + + // new value + $obj->setResource('hoge.fuga.piyo', 'hogera'); + $this->assertEquals('hogera', $obj->getResource('hoge.fuga.piyo')); + $this->assertSame(['piyo' => 'hogera'], $obj->getResource('hoge.fuga')); + $this->assertSame(['fuga' => ['piyo' => 'hogera']], $obj->getResource('hoge')); + + // non array new value + $obj->setResource('non_array.value', 100); + $this->assertEquals(100, $obj->getResource('non_array.value')); + + // clear + $obj->clearResource(); + $this->assertSame([], $obj->getResourceData()); + $this->assertEquals(null, $obj->getResource('config1')); + } + + public function testSafetyForInvalidUsecase() + { + // the object has non array $_array_resource as default + $obj = new ConcreteResource3(); + + $obj->setResource('non_array.value', 100); + $this->assertEquals(100, $obj->getResource('non_array.value')); + } +} + +class ConcreteResource2 +{ + use ArrayResourceTrait; + + public function __construct(array $array = []) + { + $this->_array_resource = $array; + } +} + +class ConcreteResource3 +{ + use ArrayResourceTrait; + + public function __construct() + { + $this->_array_resource = null; + } +} From 2f3bb2f0431a541b5158bf9e2a2a15edd464236c Mon Sep 17 00:00:00 2001 From: Sotaro KARASAWA Date: Thu, 8 Sep 2016 16:29:06 +0900 Subject: [PATCH 2/2] CHANGES --- CHANGES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 926b01d..f278fe3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,12 @@ CHANGES =========== +1.0.2 +----------- + +* Create logger in Application (not in Dispatcher) +* Create renderer object when it is needed. +* Includes fixes a little bugs and refactors. 1.0.1 -----------