mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Rename Collection class to BaseCollection. Add BaseCollection::isValidType() method to validate type of element before add it to collection. Add BaseCollection ::prepareElements() method to allow preparation of elements in custom way.
This commit is contained in:
86
tests/Collection/DateTimeCollectionTest.php
Normal file
86
tests/Collection/DateTimeCollectionTest.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Meritoo\Test\Common\Collection;
|
||||
|
||||
use DateTime;
|
||||
use Generator;
|
||||
use Meritoo\Common\Collection\DateTimeCollection;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
/**
|
||||
* Test case of the collection of DateTime instances
|
||||
*
|
||||
* @author Meritoo <github@meritoo.pl>
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Collection\DateTimeCollection
|
||||
*/
|
||||
class DateTimeCollectionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
DateTimeCollection::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
* @param array $elements
|
||||
* @param array $expectedElements
|
||||
*
|
||||
* @dataProvider provideDifferentTypesOfElements
|
||||
*/
|
||||
public function testCreateWithDifferentTypesOfElements(
|
||||
string $description,
|
||||
array $elements,
|
||||
array $expectedElements
|
||||
): void {
|
||||
$collection = new DateTimeCollection($elements);
|
||||
static::assertEquals($expectedElements, $collection->toArray(), $description);
|
||||
}
|
||||
|
||||
public function provideDifferentTypesOfElements(): ?Generator
|
||||
{
|
||||
yield[
|
||||
'An empty array',
|
||||
[],
|
||||
[],
|
||||
];
|
||||
|
||||
yield[
|
||||
'Valid elements only',
|
||||
[
|
||||
new DateTime('2001-01-01'),
|
||||
new DateTime('2001-01-02'),
|
||||
],
|
||||
[
|
||||
new DateTime('2001-01-01'),
|
||||
new DateTime('2001-01-02'),
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
'Mixed elements',
|
||||
[
|
||||
1,
|
||||
'test',
|
||||
new DateTime('2001-01-01'),
|
||||
'',
|
||||
[],
|
||||
234,
|
||||
new DateTime('2001-01-02'),
|
||||
],
|
||||
[
|
||||
2 => new DateTime('2001-01-01'),
|
||||
6 => new DateTime('2001-01-02'),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user