public function testArrayAccessImplementor() { $data = array('1' => 'One', '2' => 'Two', '3' => 'Three'); $collection = new Collection($data); $this->assertTrue($collection->valid()); $this->assertFalse($collection->isEmpty()); $this->assertEquals(3, $collection->count()); $this->assertEquals('One', $collection->current()); $collection->next(); $this->assertEquals('Two', $collection->current()); $this->assertEquals('2', $collection->key()); $collection->rewind(); $this->assertEquals('1', $collection->key()); $this->assertEquals('One', $collection->current()); $collection->ksortDesc(); $this->assertEquals('3', $collection->key()); $collection->ksortAsc(); $this->assertEquals('1', $collection->key()); $this->assertEquals('Three', $collection->last()); $collection->end(); $this->assertEquals('Three', $collection->current()); }
/** * Process arguments from $_SERVER * * @param array Server arguments * @return stream */ public static function processArguments(array $arguments) { array_shift($arguments); if (empty($arguments)) { self::showInfo(); } else { $availableCommands = array('-h', '--help', '-v', '--version', '-a', '--app', '-m', '--module', '-t', '--test'); $commands = new Collection($arguments); while ($commands->valid()) { $command = $commands->current(); if (!in_array($command, $availableCommands)) { self::out(I18n::translate('command_not_implemented', $command)); } else { if ($command == '-h' || $command == '--help') { self::showInfo(); $commands->end(); } elseif ($command == '-v' || $command == '--version') { self::showVersion(); $commands->end(); } elseif ($command == '-a' || $command == '--app') { self::generate(); $commands->end(); } elseif ($command == '-m' || $command == '--module') { $namespace = $commands->next(); if (!$namespace) { self::out(I18n::translate('cannot_register_empty_namespace')); self::out(I18n::translate('command_generate_fail')); } else { self::generate($namespace); } $commands->end(); } elseif ($command == '-t' || $command == '--test') { $target = $commands->next(); self::runTest($target); $commands->end(); } } $commands->next(); } } }