/**
  * @covers       CollectionType\Map\MapAbstract::getKeyOfValue
  * @covers       CollectionType\Map\MapAbstract::__construct
  * @covers       CollectionType\Common\KeyTypeTrait::validateValueForKeyType
  */
 public function testGetKeyOfValueForExistsKey()
 {
     $key = 'exists';
     $this->dummyKeyType->isValid($key)->willReturn(true);
     $value = 'value';
     $this->dummyValueType->isValid($value)->willReturn(true);
     $this->map->put($key, $value);
     $result = $this->map->getKeyOfValue($value);
     $this->assertEquals($key, $result);
 }
 /**
  * @covers       CollectionType\Map\MapAbstract::containsKey
  * @covers       CollectionType\Map\MapAbstract::put
  * @covers       CollectionType\Map\MapAbstract::__construct
  * @covers       CollectionType\Common\KeyTypeTrait::validateValueForKeyType
  */
 public function testContainsKeyForCorrectKeyTypeAndNotAvailableKey()
 {
     $key = new \stdClass();
     $key->param = 'key';
     $value = new \stdClass();
     $value->param = 'value';
     $this->dummyKeyType->isValid($key)->willReturn(true);
     $this->dummyValueType->isValid($value)->willReturn(true);
     $this->map->put($key, $value);
     $notExists = new \stdClass();
     $notExists->param = 'notExists';
     $this->dummyKeyType->isValid($notExists)->willReturn(true);
     $result = $this->map->containsKey($notExists);
     $this->assertFalse($result);
 }
예제 #3
0
 /**
  * @covers       CollectionType\Map\MapAbstract::isEmpty
  * @covers       CollectionType\Map\MapAbstract::__construct
  * @covers       CollectionType\Map\MapAbstract::isSynchronizedIndex
  */
 public function testIsEmptyForFilledMap()
 {
     $key1 = '1';
     $value1 = '1';
     $this->dummyKeyType->isValid($key1)->willReturn(true);
     $this->dummyValueType->isValid($value1)->willReturn(true);
     $this->map->put($key1, $value1);
     $key2 = '2';
     $value2 = '2';
     $this->dummyKeyType->isValid($key2)->willReturn(true);
     $this->dummyValueType->isValid($value2)->willReturn(true);
     $this->map->put($key2, $value2);
     $result = $this->map->isEmpty();
     $this->assertFalse($result);
 }
예제 #4
0
 /**
  * @covers       CollectionType\Map\MapAbstract::count
  * @covers       CollectionType\Map\MapAbstract::__construct
  * @covers       CollectionType\Map\MapAbstract::isSynchronizedIndex
  */
 public function testCountForFilledMap()
 {
     $key1 = '1';
     $value1 = '1';
     $this->dummyKeyType->isValid($key1)->willReturn(true);
     $this->dummyValueType->isValid($value1)->willReturn(true);
     $this->map->put($key1, $value1);
     $key2 = '2';
     $value2 = '2';
     $this->dummyKeyType->isValid($key2)->willReturn(true);
     $this->dummyValueType->isValid($value2)->willReturn(true);
     $this->map->put($key2, $value2);
     $result = $this->map->count();
     $this->assertEquals(2, $result);
 }
 /**
  * @covers       CollectionType\Map\MapAbstract::containsAll
  * @covers       CollectionType\Map\MapAbstract::__construct
  * @covers       CollectionType\Common\KeyTypeTrait::validateKeyType
  * @covers       CollectionType\Common\ValueTypeTrait::validateValueType
  * @covers       CollectionType\Common\Util\UtilTrait::diffArrays
  */
 public function testContainsAllWhenMapContainsAllElements()
 {
     $otherMap = new MapAbstractFake($this->dummyKeyType->reveal(), $this->dummyValueType->reveal());
     $key1 = new \stdClass();
     $key1->param = 'key';
     $value1 = new \stdClass();
     $value1->param = 'value';
     $this->dummyKeyType->isValid($key1)->willReturn(true);
     $this->dummyValueType->isValid($value1)->willReturn(true);
     $this->map->put($key1, $value1);
     $otherMap->put($key1, $value1);
     $key2 = new \stdClass();
     $key2->param = 'key';
     $value2 = new \stdClass();
     $value2->param = 'value';
     $this->dummyKeyType->isValid($key2)->willReturn(true);
     $this->dummyValueType->isValid($value2)->willReturn(true);
     $this->map->put($key2, $value2);
     $otherMap->put($key2, $value2);
     $key3 = new \stdClass();
     $key3->param = 'key';
     $value3 = new \stdClass();
     $value3->param = 'value';
     $this->dummyKeyType->isValid($key3)->willReturn(true);
     $this->dummyValueType->isValid($value3)->willReturn(true);
     $this->map->put($key3, $value3);
     $otherMap->put($key3, $value3);
     $result = $this->map->containsAll($otherMap);
     $this->assertTrue($result);
 }
 /**
  * @covers       CollectionType\Map\MapAbstract::removeValueAll
  * @covers       CollectionType\Map\MapAbstract::containsAll
  * @covers       CollectionType\Map\MapAbstract::validateKeyType
  * @covers       CollectionType\Map\MapAbstract::validateValueType
  * @covers       CollectionType\Map\MapAbstract::__construct
  */
 public function testRemoveValueAllWhenMapContainsAllElementsForReturnedValues()
 {
     $otherMap = new MapAbstractFake($this->dummyKeyType->reveal(), $this->dummyValueType->reveal());
     $key1 = new \stdClass();
     $key1->param = 'key1';
     $value1 = new \stdClass();
     $value1->param = 'value1';
     $this->dummyKeyType->isValid($key1)->willReturn(true);
     $this->dummyValueType->isValid($value1)->willReturn(true);
     $this->map->put($key1, $value1);
     $otherMap->put($key1, $value1);
     $key2 = new \stdClass();
     $key2->param = 'key2';
     $value2 = new \stdClass();
     $value2->param = 'value2';
     $this->dummyKeyType->isValid($key2)->willReturn(true);
     $this->dummyValueType->isValid($value2)->willReturn(true);
     $this->map->put($key2, $value2);
     $otherMap->put($key2, $value2);
     $key3 = new \stdClass();
     $key3->param = 'key3';
     $value3 = new \stdClass();
     $value3->param = 'value3';
     $this->dummyKeyType->isValid($key3)->willReturn(true);
     $this->dummyValueType->isValid($value3)->willReturn(true);
     $this->map->put($key3, $value3);
     $this->map->removeValueAll($otherMap);
     $result = $this->map->values();
     $this->assertEquals([$value3], $result);
 }
 /**
  * @covers       CollectionType\Map\MapAbstract::containsKeyAll
  * @covers       CollectionType\Map\MapAbstract::__construct
  * @covers       CollectionType\Common\KeyTypeTrait::validateKeyType
  * @covers       CollectionType\Common\ValueTypeTrait::validateValueType
  * @covers       CollectionType\Common\Util\UtilTrait::diffArrays
  */
 public function testContainsKeyAllWhenMapContainsKeyAllWithDifferentValuesElements()
 {
     $otherMap = new MapAbstractFake($this->dummyKeyType->reveal(), $this->dummyValueType->reveal());
     $key1 = '1';
     $valueA = 'A';
     $valueB = 'B';
     $this->dummyKeyType->isValid($key1)->willReturn(true);
     $this->dummyValueType->isValid($valueA)->willReturn(true);
     $this->dummyValueType->isValid($valueB)->willReturn(true);
     $this->map->put($key1, $valueA);
     $otherMap->put($key1, $valueB);
     $key2 = '2';
     $value2 = '2';
     $this->dummyKeyType->isValid($key2)->willReturn(true);
     $this->dummyValueType->isValid($value2)->willReturn(true);
     $this->map->put($key2, $value2);
     $otherMap->put($key2, $value2);
     $key3 = '3';
     $value3 = '3';
     $this->dummyKeyType->isValid($key3)->willReturn(true);
     $this->dummyValueType->isValid($value3)->willReturn(true);
     $this->map->put($key3, $value3);
     $otherMap->put($key3, $value3);
     $result = $this->map->containsKeyAll($otherMap);
     $this->assertTrue($result);
 }
 /**
  * @covers       CollectionType\Map\MapAbstract::removeValue
  * @covers       CollectionType\Map\MapAbstract::validateValueForValueType
  * @covers       CollectionType\Map\MapAbstract::containsValue
  * @covers       CollectionType\Map\MapAbstract::__construct
  */
 public function testRemoveForReturnValues()
 {
     $key1 = new \stdClass();
     $key1->param = 'key1';
     $value1 = new \stdClass();
     $value1->param = 'value1';
     $this->dummyKeyType->isValid($key1)->willReturn(true);
     $this->dummyValueType->isValid($value1)->willReturn(true);
     $this->map->put($key1, $value1);
     $key2 = new \stdClass();
     $key2->param = 'key2';
     $value2 = new \stdClass();
     $value2->param = 'value2';
     $this->dummyKeyType->isValid($key2)->willReturn(true);
     $this->dummyValueType->isValid($value2)->willReturn(true);
     $this->map->put($key2, $value2);
     $key3 = new \stdClass();
     $key3->param = 'key3';
     $value3 = new \stdClass();
     $value3->param = 'value3';
     $this->dummyKeyType->isValid($key3)->willReturn(true);
     $this->dummyValueType->isValid($value3)->willReturn(true);
     $this->map->put($key3, $value3);
     $this->map->removeValue($value2);
     $result = $this->map->values();
     $this->assertEquals([$value1, $value3], $result);
 }
예제 #9
0
 /**
  * @covers       CollectionType\Map\MapAbstract::putAll
  * @covers       CollectionType\Map\MapAbstract::isSynchronizedKeyAndValue
  * @covers       CollectionType\Map\MapAbstract::__construct
  * @covers       CollectionType\Common\KeyTypeTrait::validateValueForKeyType
  * @covers       CollectionType\Common\KeyTypeTrait::getKeyType
  * @covers       CollectionType\Common\ValueTypeTrait::validateValueForValueType
  */
 public function testPutAllToFilledMapForValidateValues()
 {
     $otherMap = new MapAbstractFake($this->dummyKeyType->reveal(), $this->dummyValueType->reveal());
     $key1 = 'base';
     $value1 = 'new';
     $this->dummyKeyType->isValid($key1)->willReturn(true);
     $this->dummyValueType->isValid($value1)->willReturn(true);
     $otherMap->put($key1, $value1);
     $key2 = '2';
     $value2 = '2';
     $this->dummyKeyType->isValid($key2)->willReturn(true);
     $this->dummyValueType->isValid($value2)->willReturn(true);
     $otherMap->put($key2, $value2);
     $key3 = '3';
     $value3 = '3';
     $this->dummyKeyType->isValid($key3)->willReturn(true);
     $this->dummyValueType->isValid($value3)->willReturn(true);
     $otherMap->put($key3, $value3);
     $key0 = '0';
     $value0 = '0';
     $this->dummyKeyType->isValid($key0)->willReturn(true);
     $this->dummyValueType->isValid($value0)->willReturn(true);
     $this->map->put($key0, $value0);
     $key1 = 'base';
     $value1 = 'old';
     $this->dummyKeyType->isValid($key1)->willReturn(true);
     $this->dummyValueType->isValid($value1)->willReturn(true);
     $this->map->put($key1, $value1);
     $this->map->putAll($otherMap);
     $result = $this->map->values();
     $this->assertEquals(['0', 'new', '2', '3'], $result);
 }
 /**
  * @covers       CollectionType\Map\MapAbstract::put
  * @covers       CollectionType\Map\MapAbstract::isSynchronizedKeyAndValue
  * @covers       CollectionType\Map\MapAbstract::__construct
  * @covers       CollectionType\Common\KeyTypeTrait::validateValueForKeyType
  * @covers       CollectionType\Common\ValueTypeTrait::validateValueForValueType
  */
 public function testPutForOverrideValue()
 {
     $key = new \stdClass();
     $key->param = 'key';
     $oldValue = new \stdClass();
     $oldValue->param = 'oldValue';
     $this->dummyKeyType->isValid($key)->willReturn(true);
     $this->dummyValueType->isValid($oldValue)->willReturn(true);
     $this->map->put($key, $oldValue);
     $newValue = new \stdClass();
     $newValue->param = 'newValue';
     $this->dummyValueType->isValid($newValue)->willReturn(true);
     $this->map->put($key, $newValue);
     $result = $this->map->get($key);
     $this->assertEquals($newValue, $result);
 }
예제 #11
0
 /**
  * @expectedException \CollectionType\Exception\SynchronizeException
  *
  * @covers       CollectionType\Map\MapAbstract::put
  * @covers       CollectionType\Map\MapAbstract::isSynchronizedKeyAndValue
  * @covers       CollectionType\Map\MapAbstract::__construct
  * @covers       CollectionType\Common\KeyTypeTrait::validateValueForKeyType
  * @covers       CollectionType\Common\ValueTypeTrait::validateValueForValueType
  */
 public function testNotSynchronizedMapForValue()
 {
     $this->map->putValue('1');
     $key = '2';
     $value = '2';
     $this->dummyKeyType->isValid($key)->willReturn(true);
     $this->dummyValueType->isValid($value)->willReturn(true);
     $this->map->put($key, $value);
 }
예제 #12
0
 /**
  * @covers       CollectionType\Map\MapAbstract::values
  * @covers       CollectionType\Map\MapAbstract::__construct
  * @covers       CollectionType\Common\KeyTypeTrait::validateValueForKeyType
  */
 public function testValuesForFilledMap()
 {
     $key1 = '1';
     $this->dummyKeyType->isValid($key1)->willReturn(true);
     $value1 = '1';
     $this->dummyValueType->isValid($value1)->willReturn(true);
     $this->map->put($key1, $value1);
     $key2 = '2';
     $this->dummyKeyType->isValid($key2)->willReturn(true);
     $value2 = '2';
     $this->dummyValueType->isValid($value2)->willReturn(true);
     $this->map->put($key2, $value2);
     $key3 = '3';
     $this->dummyKeyType->isValid($key3)->willReturn(true);
     $value3 = '3';
     $this->dummyValueType->isValid($value3)->willReturn(true);
     $this->map->put($key3, $value3);
     $result = $this->map->values();
     $this->assertEquals(['1', '2', '3'], $result);
 }
예제 #13
0
 /**
  * @expectedException \CollectionType\Exception\InvalidTypeException
  *
  * @covers       CollectionType\Map\MapAbstract::containsKey
  * @covers       CollectionType\Map\MapAbstract::put
  * @covers       CollectionType\Map\MapAbstract::__construct
  * @covers       CollectionType\Common\KeyTypeTrait::validateValueForKeyType
  */
 public function testContainsKeyForIncorrectKeyType()
 {
     $key = 'key';
     $value = 'value';
     $this->dummyKeyType->isValid($key)->willReturn(true);
     $this->dummyValueType->isValid($value)->willReturn(true);
     $this->map->put($key, $value);
     $incorrect = 1;
     $this->dummyKeyType->isValid($incorrect)->willReturn(false);
     $this->map->containsKey($incorrect);
 }
예제 #14
0
 /**
  * @expectedException \CollectionType\Exception\SynchronizeException
  *
  * @covers       CollectionType\Map\MapAbstract::remove
  * @covers       CollectionType\Map\MapAbstract::validateValueForKeyType
  * @covers       CollectionType\Map\MapAbstract::containsKey
  * @covers       CollectionType\Map\MapAbstract::isSynchronizedIndex
  * @covers       CollectionType\Map\MapAbstract::__construct
  */
 public function testRemoveForNotSynchronizedMap()
 {
     $key1 = '1';
     $this->dummyKeyType->isValid($key1)->willReturn(true);
     $value1 = '1';
     $this->dummyValueType->isValid($value1)->willReturn(true);
     $this->map->put($key1, $value1);
     /** fake method, only for UnitTests */
     $this->map->putKey('2');
     $this->map->remove($key1);
 }
예제 #15
0
 /**
  * @covers       CollectionType\Map\MapAbstract::clear
  * @covers       CollectionType\Map\MapAbstract::__construct
  */
 public function testClearFilledMapForValues()
 {
     $key1 = '1';
     $value1 = '1';
     $this->dummyKeyType->isValid($key1)->willReturn(true);
     $this->dummyValueType->isValid($value1)->willReturn(true);
     $this->map->put($key1, $value1);
     $key2 = '2';
     $value2 = '2';
     $this->dummyKeyType->isValid($key2)->willReturn(true);
     $this->dummyValueType->isValid($value2)->willReturn(true);
     $this->map->put($key1, $value1);
     $this->map->clear();
     $result = $this->map->values();
     $this->assertEquals([], $result);
 }
 /**
  * @covers       CollectionType\Map\MapAbstract::putAll
  * @covers       CollectionType\Map\MapAbstract::isSynchronizedKeyAndValue
  * @covers       CollectionType\Map\MapAbstract::__construct
  * @covers       CollectionType\Common\KeyTypeTrait::validateValueForKeyType
  * @covers       CollectionType\Common\KeyTypeTrait::getKeyType
  * @covers       CollectionType\Common\ValueTypeTrait::validateValueForValueType
  */
 public function testPutAllToFilledMapForValidateValues()
 {
     $otherMap = new MapAbstractFake($this->dummyKeyType->reveal(), $this->dummyValueType->reveal());
     $key1 = new \stdClass();
     $key1->param = 'base';
     $valueNew = new \stdClass();
     $valueNew->param = 'new';
     $this->dummyKeyType->isValid($key1)->willReturn(true);
     $this->dummyValueType->isValid($valueNew)->willReturn(true);
     $otherMap->put($key1, $valueNew);
     $key2 = new \stdClass();
     $key2->param = 'key2';
     $value2 = new \stdClass();
     $value2->param = 'value2';
     $this->dummyKeyType->isValid($key2)->willReturn(true);
     $this->dummyValueType->isValid($value2)->willReturn(true);
     $otherMap->put($key2, $value2);
     $key3 = new \stdClass();
     $key3->param = 'key3';
     $value3 = new \stdClass();
     $value3->param = 'value3';
     $this->dummyKeyType->isValid($key3)->willReturn(true);
     $this->dummyValueType->isValid($value3)->willReturn(true);
     $otherMap->put($key3, $value3);
     $key0 = new \stdClass();
     $key0->param = 'key0';
     $value0 = new \stdClass();
     $value0->param = 'value0';
     $this->dummyKeyType->isValid($key0)->willReturn(true);
     $this->dummyValueType->isValid($value0)->willReturn(true);
     $this->map->put($key0, $value0);
     $key1 = new \stdClass();
     $key1->param = 'base';
     $value1 = new \stdClass();
     $value1->param = 'old';
     $this->dummyKeyType->isValid($key1)->willReturn(true);
     $this->dummyValueType->isValid($value1)->willReturn(true);
     $this->map->put($key1, $value1);
     $this->map->putAll($otherMap);
     $result = $this->map->values();
     $this->assertEquals([$value0, $valueNew, $value2, $value3], $result);
 }