/** * @return boolean */ public function add($element) { if ($this->contains($element)) { return false; } return parent::add($element); }
public function testAddAllAddsUnique() { $setA = new BasicSet(new SimpleComparator()); $setA->add('foo'); $collectionB = new BasicCollection(); $collectionB->add('foo'); self::assertFalse($setA->addAll($collectionB)); }
public function testConvertToArray() { $collection = new BasicCollection(); $collection->add('foo'); $collection->add('bar'); $collection->add('baz'); $collection->remove('bar'); // this call should not create a gap in the index sequence $actual = $collection->toArray(); $expected = [0 => 'foo', 1 => 'baz']; self::assertEquals($expected, $actual); }