/** * testIteratorUsesNodeNameAsItsIterationKey * * @return void * @covers PHP_Depend_Code_NodeIterator * @group pdepend * @group pdepend::code * @group unittest */ public function testIteratorUsesNodeNameAsItsIterationKey() { $nodes = array(new PHP_Depend_Code_Class('clazz', 0, 'clazz.php'), new PHP_Depend_Code_Function('func', 0), new PHP_Depend_Code_Method('method', 0), new PHP_Depend_Code_Package('pkg')); $iterator = new PHP_Depend_Code_NodeIterator($nodes); $expected = array('clazz', 'func', 'method', 'pkg'); $actual = array(); foreach ($iterator as $codeNode) { $actual[] = $iterator->key(); } $this->assertEquals($expected, $actual); }
/** * Tests that the iterator returns the node name as key. * * @return void */ public function testNodeIteratorLoopWithKey() { $names = array('clazz', 'func', 'method', 'pkg'); $nodes = array(new PHP_Depend_Code_Class('clazz', 0, 'clazz.php'), new PHP_Depend_Code_Function('func', 0), new PHP_Depend_Code_Method('method', 0), new PHP_Depend_Code_Package('pkg')); $it = new PHP_Depend_Code_NodeIterator($nodes); for ($i = 0, $it->rewind(); $it->valid(); ++$i, $it->next()) { $this->assertSame($nodes[$i], $it->current()); $this->assertEquals($names[$i], $it->key()); } }