public function add($key, $value) { if (!$this->keyType->isValidType($key)) { $msg = $this->createExceptionMessage('Invalid key type. ', $this->keyType); throw new InvalidKeyTypeException($msg, $key); } if (!$this->valueType->isValidType($value)) { $msg = $this->createExceptionMessage('Invalid value type. ', $this->valueType); throw new InvalidValueTypeException($msg, $value); } parent::add($key, $value); }
public function testIterationWithMapEntries() { $entries = array(array(new \ReflectionClass('Exception'), rand(1, 10)), array(true, rand(1, 10)), array(false, rand(1, 10)), array('string', rand(1, 10)), array(range(1, 10), rand(1, 10))); $this->object = new Map(true); $this->assertTrue($this->object->isUsingMapEntries()); foreach ($entries as $entry) { $this->object->add($entry[0], $entry[1]); } $iterationCount = 0; reset($entries); foreach ($this->object as $key => $entry) { /* @var MapEntry $entry */ $expectedPair = current($entries); $this->assertSame($iterationCount, $key, 'Invalid key'); $this->assertInstanceOf('Wookieb\\Map\\MapEntry', $entry); $this->assertSame($expectedPair[0], $entry->getKey(), 'Invalid entry key'); $this->assertSame($expectedPair[1], $entry->getValue(), 'Invalid entry value'); next($entries); $iterationCount++; } $this->assertSame(5, $iterationCount, 'Map was not iterated'); }