mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 01:31:45 +01:00
Collection > the getByIndex() method > returns element with given index
This commit is contained in:
@@ -327,6 +327,19 @@ class CollectionTest extends BaseTestCase
|
||||
static::assertMethodVisibilityAndArguments(Collection::class, 'exists', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description Description of test
|
||||
* @param Collection $collection Collection to search for element with given index
|
||||
* @param mixed $index Index / key of the element
|
||||
* @param mixed $expected Expected element with given index
|
||||
*
|
||||
* @dataProvider provideElementGetByIndex
|
||||
*/
|
||||
public function testGetByIndex($description, Collection $collection, $index, $expected)
|
||||
{
|
||||
static::assertEquals($expected, $collection->getByIndex($index), $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides element to add to collection
|
||||
*
|
||||
@@ -408,6 +421,73 @@ class CollectionTest extends BaseTestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function provideElementGetByIndex()
|
||||
{
|
||||
yield[
|
||||
'An empty collection and empty index',
|
||||
new Collection(),
|
||||
'',
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
'An empty collection and non-empty index',
|
||||
new Collection(),
|
||||
'test',
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Non-empty collection and not existing index',
|
||||
new Collection([
|
||||
'lorem' => 'ipsum',
|
||||
'dolor' => 'sit',
|
||||
]),
|
||||
'test',
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Collection with existing index',
|
||||
new Collection([
|
||||
'lorem' => 'ipsum',
|
||||
'dolor' => 'sit',
|
||||
]),
|
||||
'lorem',
|
||||
'ipsum',
|
||||
];
|
||||
|
||||
yield[
|
||||
'Collection with existing index (collection of arrays)',
|
||||
new Collection([
|
||||
[
|
||||
'lorem',
|
||||
'ipsum',
|
||||
],
|
||||
[
|
||||
'dolor',
|
||||
'sit',
|
||||
],
|
||||
]),
|
||||
0,
|
||||
[
|
||||
'lorem',
|
||||
'ipsum',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
'Collection with existing index (collection of objects)',
|
||||
new Collection([
|
||||
'x' => new \DateTime(),
|
||||
'y' => new \DateTime('2001-01-01'),
|
||||
'z' => new \DateTime('yesterday'),
|
||||
]),
|
||||
'y',
|
||||
new \DateTime('2001-01-01'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user