Increase code coverage of the BaseCollection class

This commit is contained in:
Meritoo
2021-04-04 23:06:36 +02:00
parent d5542b60e3
commit 118fa64772
2 changed files with 39 additions and 0 deletions

View File

@@ -18,6 +18,9 @@
<testsuite name="Meritoo Package - Main Test Suite"> <testsuite name="Meritoo Package - Main Test Suite">
<directory>tests</directory> <directory>tests</directory>
</testsuite> </testsuite>
<testsuite name="Collection">
<directory>tests/Collection</directory>
</testsuite>
</testsuites> </testsuites>
<filter> <filter>

View File

@@ -140,6 +140,24 @@ class BaseCollectionTest extends BaseTestCase
static::assertInstanceOf(ArrayIterator::class, $this->simpleCollection->getIterator()); 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 mixed $element The element to add
* @param int $expectedCount Expected count of elements in collection * @param int $expectedCount Expected count of elements in collection
@@ -371,6 +389,24 @@ class BaseCollectionTest extends BaseTestCase
static::assertSame($expected, $collection->toArray(), $description); 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 * Provides element to add to collection
* *