mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 01:31:45 +01:00
Increase code coverage of the BaseCollection class
This commit is contained in:
@@ -18,6 +18,9 @@
|
||||
<testsuite name="Meritoo Package - Main Test Suite">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Collection">
|
||||
<directory>tests/Collection</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user