public function testToList() { $data = ['a' => 'b', 'c' => [1, ['x' => 'y'], 4], 'd' => ['x' => 'y', 'z' => 'zz']]; $list = CollectionUtils::toList($data); $this->assertTrue($list instanceof ArrayList); $this->assertEquals('b', $list->get(0)); $this->assertTrue($list->get(2) instanceof Map); $list = new ArrayList($data); $this->assertEquals('b', $list->get(0)); $this->assertFalse($list->get(2) instanceof Map); }
public function testIndex() { $item1 = 'item 1'; $item2 = 'item 2'; $item3 = 'item 3'; $items = [$item1, $item2]; $list = new ArrayList($items); $index1 = $list->indexOf($item1); $this->assertEquals(0, $index1); $this->assertEquals(1, $list->indexOf($item2)); $this->assertFalse($list->indexOf($item3)); $list->removeAll($items); $list->addAll($items); $this->assertEquals(2, $list->size()); $this->assertEquals($index1, $list->indexOf($item1)); $list->add($item3, 1); $this->assertEquals($item3, $list->get(1)); $this->assertEquals($item2, $list->get(2)); }
public function testBlockPositionsOnAbstractClass() { $blocks = new ArrayList(); $listener = function (BlockEvent $event) use($blocks) { $blocks->add($event->getBlock()); }; $parser = new Parser(); $parser->getContext()->addListener(Context::EVENT_BLOCK_LEAVE, $listener); $parser->parse($this->getRawContent('abstract-class')); $tokens = $parser->getTokens(); // test: class $class = $blocks->get(3); $this->assertEquals(Block::TYPE_CLASS, $class->type); $this->assertEquals($tokens->get(8), $class->start); $this->assertEquals($tokens->get(59), $class->end); // test: static method $static = $blocks->get(1); $this->assertEquals(Block::TYPE_METHOD, $static->type); $this->assertEquals($tokens->get(34), $static->start); $this->assertEquals($tokens->get(46), $static->end); }
/** * Retrieves a token at the given index * * @param int $index the given index * @return Token */ public function get($index) { return parent::get($index); }