diff --git a/phpunit.xml.dist b/phpunit.xml.dist index acd207b..a6964df 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -18,6 +18,9 @@ tests + + tests/Collection + diff --git a/tests/Collection/BaseCollectionTest.php b/tests/Collection/BaseCollectionTest.php index 0b64961..f6ea186 100644 --- a/tests/Collection/BaseCollectionTest.php +++ b/tests/Collection/BaseCollectionTest.php @@ -140,6 +140,24 @@ class BaseCollectionTest extends BaseTestCase static::assertInstanceOf(ArrayIterator::class, $this->simpleCollection->getIterator()); } + /** + * @param mixed $element The element to add + * @param int $expectedCount Expected count of elements in collection + * @param CollectionInterface $collection The collection + * + * @dataProvider provideElementToAddWithInvalidType + */ + public function testAddWithInvalidType( + $element, + int $expectedCount, + CollectionInterface $collection + ): void { + $collection->add($element); + + static::assertFalse($collection->has($element)); + static::assertSame($expectedCount, $collection->count()); + } + /** * @param mixed $element The element to add * @param int $expectedCount Expected count of elements in collection @@ -371,6 +389,24 @@ class BaseCollectionTest extends BaseTestCase static::assertSame($expected, $collection->toArray(), $description); } + public function provideElementToAddWithInvalidType(): ?Generator + { + yield [ + ['test'], + 0, + new StringCollection(), + ]; + + yield [ + 123, + 2, + new StringCollection([ + 'I am 1st', + 'I am 2nd', + ]), + ]; + } + /** * Provides element to add to collection *