Skip to content

Commit

Permalink
Add Orchestra\Support\Nesty::is(). Closes #24.
Browse files Browse the repository at this point in the history
Signed-off-by: crynobone <[email protected]>
  • Loading branch information
crynobone committed Sep 9, 2013
1 parent 54541fc commit cec7139
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
11 changes: 11 additions & 0 deletions src/Orchestra/Support/Nesty.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ public function add($id, $location = '#')
return $this->addParent($id);
}

/**
* Retrieve an item by id.
*
* @param string $key
* @return \Illuminate\Support\Fluent
*/
public function is($key)
{
return $this->descendants($key);
}

/**
* Get node from items recursively.
*
Expand Down
57 changes: 31 additions & 26 deletions tests/NestyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,34 @@ public function testNewInstanceReturnEmptyArray()
*/
public function testAddMethod()
{
$foobar = new Fluent(array(
'id' => 'foobar',
'childs' => array(
'hello-foobar' => new Fluent(array(
'id' => 'hello-foobar',
'childs' => array(),
)),
),
));
$foo = new Fluent(array(
'id' => 'foo',
'childs' => array(
'bar' => new Fluent(array(
'id' => 'bar',
'childs' => array(),
)),
'foobar' => $foobar,
'foo-bar' => new Fluent(array(
'id' => 'foo-bar',
'childs' => array(),
)),
'hello-world-foobar' => new Fluent(array(
'id' => 'hello-world-foobar',
'childs' => array(),
)),
)
));

$expected = array(
'crynobone' => new Fluent(array(
'id' => 'crynobone',
Expand All @@ -82,32 +110,7 @@ public function testAddMethod()
'id' => 'world',
'childs' => array(),
)),
'foo' => new Fluent(array(
'id' => 'foo',
'childs' => array(
'bar' => new Fluent(array(
'id' => 'bar',
'childs' => array(),
)),
'foobar' => new Fluent(array(
'id' => 'foobar',
'childs' => array(
'hello-foobar' => new Fluent(array(
'id' => 'hello-foobar',
'childs' => array(),
)),
),
)),
'foo-bar' => new Fluent(array(
'id' => 'foo-bar',
'childs' => array(),
)),
'hello-world-foobar' => new Fluent(array(
'id' => 'hello-world-foobar',
'childs' => array(),
)),
),
)),
'foo' => $foo,
'orchestra' => new Fluent(array(
'id' => 'orchestra',
'childs' => array(),
Expand All @@ -126,6 +129,8 @@ public function testAddMethod()
$this->stub->add('orchestra', '#');

$this->assertEquals($expected, $this->stub->getItems());
$this->assertEquals($foo, $this->stub->is('foo'));
$this->assertEquals($foobar, $this->stub->is('foo.foobar'));
}

/**
Expand Down

0 comments on commit cec7139

Please sign in to comment.