Skip to content

Commit

Permalink
Merge pull request #17 from mercari/v1.0.2
Browse files Browse the repository at this point in the history
V1.0.2 Preparation
  • Loading branch information
sotarok authored Sep 8, 2016
2 parents 2de3320 + 2f3bb2f commit 015fcf5
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
-----------
Expand Down
91 changes: 91 additions & 0 deletions tests/Components/ArrayResourceTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
*
*/

namespace Dietcube\Components;

use Pimple\Container;

/**
* @backupGlobals
*/
class ArrayResourceTraitTest extends \PHPUnit_Framework_TestCase
{
public function testGetAndSet()
{
$data = [
'config1' => 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;
}
}

0 comments on commit 015fcf5

Please sign in to comment.