when($result = new SUT()) ->then ->object($result) ->isInstanceOf('ArrayAccess') ->isInstanceOf('IteratorAggregate'); } public function case_empty_constructor() { $this ->when($result = new SUT()) ->then ->variable($result->getName()) ->isNull() ->array(iterator_to_array($result->getIterator())) ->isEmpty(); } public function case_constructor_with_a_name() { $this ->given($name = 'foo') ->when($result = new SUT($name)) ->then ->string($result->getName()) ->isEqualTo($name) ->array(iterator_to_array($result->getIterator())) ->isEmpty(); } public function case_constructor_with_a_name_and_children() { $this ->given( $name = 'foo', $children = [new SUT('bar'), new SUT('baz')] ) ->when($result = new SUT($name, '', $children)) ->then ->string($result->getName()) ->isEqualTo($name) ->array(iterator_to_array($result->getIterator())) ->hasSize(2); } public function case_offset_set() { $this ->given( $root = new SUT(), $name = 'foo', $node = new SUT(), $oldCountChildren = count(iterator_to_array($root->getIterator())) ) ->when($result = $root->offsetSet($name, $node)) ->then ->integer(count(iterator_to_array($root->getIterator()))) ->isEqualTo($oldCountChildren + 1) ->object($root[$name]) ->isIdenticalTo($node); } public function case_offset_set_not_a_node() { $this ->given($root = new SUT()) ->exception(function () use ($root) { $root->offsetSet('foo', null); }) ->isInstanceOf('Hoa\Protocol\Exception'); } public function case_offset_set_no_name() { $this ->given($root = new SUT()) ->exception(function () use ($root) { $root->offsetSet(null, new SUT()); }) ->isInstanceOf('Hoa\Protocol\Exception'); } public function case_offset_get() { $this ->given( $root = new SUT(), $child = new SUT(), $root['foo'] = $child ) ->when($result = $root->offsetGet('foo')) ->then ->object($result) ->isIdenticalTo($child); } public function case_offset_get_an_unknown_name() { $this ->given($root = new SUT()) ->exception(function () use ($root) { $root->offsetGet('foo'); }) ->isInstanceOf('Hoa\Protocol\Exception'); } public function case_offset_exists() { $this ->given( $root = new SUT(), $child = new SUT(), $root['foo'] = $child ) ->when($result = $root->offsetExists('foo')) ->then ->boolean($result) ->isTrue(); } public function case_offset_not_exists() { $this ->given($root = new SUT()) ->when($result = $root->offsetExists('foo')) ->then ->boolean($result) ->isFalse(); } public function case_offset_unset() { $this ->given( $root = new SUT(), $child = new SUT(), $root['foo'] = $child ) ->when($result = $root->offsetUnset('foo')) ->then ->boolean($root->offsetExists('foo')) ->isFalse(); } public function case_reach() { $this ->given( $reach = 'bar', $node = new SUT('foo', $reach) ) ->when($result = $node->reach()) ->then ->string($result) ->isEqualTo($reach); } public function case_reach_with_a_queue() { $this ->given( $queue = 'baz', $node = new SUT('foo', 'bar') ) ->when($result = $node->reach('baz')) ->then ->string($result) ->isEqualTo($queue); } public function case_reach_id() { $this ->given($node = new SUT()) ->exception(function () use ($node) { $node->reachId('foo'); }) ->isInstanceOf('Hoa\Protocol\Exception'); } public function case_set_reach() { $this ->given( $reach = 'bar', $node = new SUT('foo', $reach) ) ->when($result = $node->setReach('baz')) ->then ->string($result) ->isEqualTo($reach) ->string($node->reach()) ->isEqualTo('baz'); } public function case_get_name() { $this ->given( $name = 'foo', $node = new SUT($name) ) ->when($result = $node->getName()) ->then ->string($result) ->isEqualTo($name); } public function case_get_iterator() { $this ->given( $childA = new SUT('bar'), $childB = new SUT('baz'), $children = [$childA, $childB] ) ->when($result = new SUT('foo', '', $children)) ->then ->object($result->getIterator()) ->isInstanceOf('ArrayIterator') ->array(iterator_to_array($result->getIterator())) ->isEqualTo([ 'bar' => $childA, 'baz' => $childB ]); } public function case_get_root() { $this ->when($result = SUT::getRoot()) ->then ->object($result) ->isIdenticalTo(LUT::getInstance()); } public function case_to_string_as_leaf() { $this ->given($node = new SUT('foo')) ->when($result = $node->__toString()) ->then ->string($result) ->isEqualTo('foo' . "\n"); } public function case_to_string_as_node() { $this ->given( $node = new SUT('foo'), $node[] = new SUT('bar'), $node[] = new SUT('baz') ) ->when($result = $node->__toString()) ->then ->string($result) ->isEqualTo( 'foo' . "\n" . ' bar' . "\n" . ' baz' . "\n" ); } }