PHPUnit > increase code coverage

This commit is contained in:
Meritoo
2019-04-06 08:14:48 +02:00
parent a13a629408
commit e05bc2302d
3 changed files with 128 additions and 7 deletions

View File

@@ -72,6 +72,19 @@ class RepositoryTest extends BaseTestCase
static::assertEquals($before, $after);
}
/**
* @param string $description Description of test
* @param array $items Objects who have "getPosition()" and "setPosition()" methods or arrays
* @param array $expected Expected items with positions replenished
*
* @dataProvider provideSortedItems
*/
public function testReplenishPositionsUsingSortedItems(string $description, array $items, array $expected)
{
Repository::replenishPositions($items);
static::assertSame($expected, $items, $description);
}
/**
* @param array $items Objects who have "getPosition()" and "setPosition()" methods or arrays
* @dataProvider provideArraysWithoutExtremePosition
@@ -833,4 +846,88 @@ class RepositoryTest extends BaseTestCase
'qb.first_name DESC',
];
}
public function provideSortedItems()
{
$sortable1 = new Sortable();
$sortable1->setPosition(1);
$sortable2 = new Sortable();
$sortable2->setPosition(2);
$sortable3 = new Sortable();
$sortable3->setPosition(309);
yield[
'An array with 1 item only',
[
[
'test 1',
'position' => 1,
],
],
[
[
'test 1',
'position' => 1,
],
],
];
yield[
'An array with more than 1 item',
[
[
'test 1',
'position' => 1,
],
[
'test 2',
'position' => 2,
],
[
'test 3',
'position' => 309,
],
],
[
[
'test 1',
'position' => 1,
],
[
'test 2',
'position' => 2,
],
[
'test 3',
'position' => 309,
],
],
];
yield[
'1 object only',
[
$sortable1,
],
[
$sortable1,
],
];
yield[
'More than 1 object',
[
$sortable1,
$sortable2,
$sortable3,
],
[
$sortable1,
$sortable2,
$sortable3,
],
];
}
}