public function testGetCount() { $collection = new OrderedMap(); $this->assertSame(0, $collection->count()); $collection->add('test'); $this->assertSame(1, $collection->count()); $collection->clear(); $this->assertSame(0, $collection->count()); $collection->addAll(range(0, 99999)); $this->assertSame(100000, $collection->count()); }
/** * Parses the tag argument string and returns a map of all arguments. * * In case there is only a single argument value without a key, the key to access this * argument will be set to "0". * * @param string|null $argumentString The argument string to parse * @return \Ableron\Lib\Collections\Implementations\OrderedMap */ private function parseArgumentString($argumentString) { // prepare return value $arguments = new OrderedMap(); // check whether argument string is given if ($argumentString !== null) { // extract arguments preg_match_all('#(?:^|\\s+)(\\w+)=((?:(?!\\s+\\w+=).)+)#s', $argumentString, $argumentMatches); // in case $argumentMatches[0] is empty, the argument string itself is the only argument (key is set to "0") if (empty($argumentMatches[0])) { $arguments->add($argumentString); } else { for ($argumentIndex = 0, $argumentCount = count($argumentMatches[0]); $argumentIndex < $argumentCount; $argumentIndex++) { // get argument name and value $argumentName = $argumentMatches[1][$argumentIndex]; $argumentValue = $this->argumentValueToPhpValue($argumentMatches[2][$argumentIndex]); // add argument to return value $arguments->set($argumentName, $argumentValue); } } } // return arguments return $arguments; }
/** * Tests whether add() works as expected. * * @return void */ public function testAdd() { $map = new OrderedMap(); $map->add('foo'); $this->assertTrue($map->containsKey(0)); $this->assertTrue($map->containsValue('foo')); $this->assertSame('foo', $map->get(0)); $map->add('bar'); $this->assertTrue($map->containsKey(1)); $this->assertTrue($map->containsValue('bar')); $this->assertSame('bar', $map->get(1)); }