Skip to content

Commit

Permalink
chore: update tests for phpunit 10 and 11 (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
rancoud authored Dec 7, 2024
1 parent 7f14b39 commit 27c33c8
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions tests/PaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace tests;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Rancoud\Pagination\Item;
use Rancoud\Pagination\Pagination;
Expand Down Expand Up @@ -115,7 +116,7 @@ public function testConfiguration(): void
/**
* @return array
*/
public function dataCeil(): array
public static function dataCeil(): array
{
$configuration = [
'use_previous' => true,
Expand Down Expand Up @@ -192,7 +193,7 @@ public function dataCeil(): array
'count' => 1,
'per_page' => 1
],
'data_out' => [
'dataOut' => [
'previous' => $previous,
'links' => [],
'next' => null
Expand All @@ -205,7 +206,7 @@ public function dataCeil(): array
'count' => 1,
'per_page' => 1
],
'data_out' => [
'dataOut' => [
'previous' => null,
'links' => [$linkPage1Current],
'next' => null,
Expand All @@ -218,7 +219,7 @@ public function dataCeil(): array
'count' => 1,
'per_page' => -9
],
'data_out' => [
'dataOut' => [
'previous' => null,
'links' => [$linkPage1Current],
'next' => null,
Expand All @@ -231,7 +232,7 @@ public function dataCeil(): array
'count' => -9,
'per_page' => 1
],
'data_out' => [
'dataOut' => [
'previous' => null,
'links' => [],
'next' => null,
Expand All @@ -244,7 +245,7 @@ public function dataCeil(): array
'count' => 6,
'per_page' => 2
],
'data_out' => [
'dataOut' => [
'previous' => $previousPage3,
'links' => [],
'next' => null
Expand All @@ -257,7 +258,7 @@ public function dataCeil(): array
'count' => 6,
'per_page' => 2
],
'data_out' => [
'dataOut' => [
'previous' => null,
'links' => [
$linkPage1Current,
Expand All @@ -274,7 +275,7 @@ public function dataCeil(): array
'count' => 6,
'per_page' => -9
],
'data_out' => [
'dataOut' => [
'previous' => $previous,
'links' => [
$linkPage1,
Expand All @@ -292,7 +293,7 @@ public function dataCeil(): array
'count' => -9,
'per_page' => 2
],
'data_out' => [
'dataOut' => [
'previous' => null,
'links' => [],
'next' => null,
Expand All @@ -310,6 +311,7 @@ public function dataCeil(): array
*
* @throws PaginationException
*/
#[DataProvider('dataCeil')]
public function testIncorrectCeilCompute(array $configuration, array $params, array $dataOut): void
{
$p = new Pagination();
Expand All @@ -322,7 +324,7 @@ public function testIncorrectCeilCompute(array $configuration, array $params, ar
/**
* @return array
*/
public function dataShowAllLinks(): array
public static function dataShowAllLinks(): array
{
$configuration = [
'use_previous' => true,
Expand Down Expand Up @@ -395,7 +397,7 @@ public function dataShowAllLinks(): array
'count' => 50,
'per_page' => 1
],
'data_out' => [
'dataOut' => [
'previous' => null,
'links' => $linksCurrentPage1,
'next' => $nextPage2
Expand All @@ -408,7 +410,7 @@ public function dataShowAllLinks(): array
'count' => 50,
'per_page' => 1
],
'data_out' => [
'dataOut' => [
'previous' => $previousPage1,
'links' => $linksCurrentPage2,
'next' => $nextPage3
Expand All @@ -421,7 +423,7 @@ public function dataShowAllLinks(): array
'count' => 50,
'per_page' => 1
],
'data_out' => [
'dataOut' => [
'previous' => $previousPage49,
'links' => $linksCurrentPage50,
'next' => null
Expand All @@ -439,6 +441,7 @@ public function dataShowAllLinks(): array
*
* @throws PaginationException
*/
#[DataProvider('dataShowAllLinks')]
public function testShowAllLinks(array $configuration, array $params, array $dataOut): void
{
$p = new Pagination();
Expand All @@ -451,7 +454,7 @@ public function testShowAllLinks(array $configuration, array $params, array $dat
/**
* @return array
*/
public function dataAdjacentAndLimitConfiguration(): array
public static function dataAdjacentAndLimitConfiguration(): array
{
$linkCurrentPage20 = new Item();
$linkCurrentPage20->isDots = false;
Expand Down Expand Up @@ -527,7 +530,7 @@ public function dataAdjacentAndLimitConfiguration(): array
'count_pages_pair_adjacent' => 0,
],
'params' => $params,
'data_out' => [
'dataOut' => [
'links' => $currentPage,
]
],
Expand All @@ -537,7 +540,7 @@ public function dataAdjacentAndLimitConfiguration(): array
'count_pages_pair_adjacent' => 0,
],
'params' => $params,
'data_out' => [
'dataOut' => [
'links' => \array_merge($limitPagesLeft, $currentPage, $limitPagesRight),
]
],
Expand All @@ -547,7 +550,7 @@ public function dataAdjacentAndLimitConfiguration(): array
'count_pages_pair_adjacent' => 5,
],
'params' => $params,
'data_out' => [
'dataOut' => [
'links' => \array_merge($adjacentPagesLeft, $currentPage, $adjacentPagesRight),
]
],
Expand All @@ -557,7 +560,7 @@ public function dataAdjacentAndLimitConfiguration(): array
'count_pages_pair_adjacent' => 5,
],
'params' => $params,
'data_out' => [
'dataOut' => [
'links' => \array_merge($limitPagesLeft, $adjacentPagesLeft, $currentPage, $adjacentPagesRight, $limitPagesRight), // phpcs:ignore
]
]
Expand All @@ -573,6 +576,7 @@ public function dataAdjacentAndLimitConfiguration(): array
*
* @throws PaginationException
*/
#[DataProvider('dataAdjacentAndLimitConfiguration')]
public function testAdjacentAndLimitConfiguration(array $configuration, array $params, array $dataOut): void
{
$p = new Pagination();
Expand All @@ -585,7 +589,7 @@ public function testAdjacentAndLimitConfiguration(array $configuration, array $p
/**
* @return array
*/
public function dataRenderHtml(): array
public static function dataRenderHtml(): array
{
return [
'pretty html off' => [
Expand Down Expand Up @@ -913,6 +917,7 @@ public function dataRenderHtml(): array
*
* @throws PaginationException
*/
#[DataProvider('dataRenderHtml')]
public function testRenderHtml(array $configuration, array $params, string $expectedHtml): void
{
$p = new Pagination();
Expand All @@ -924,7 +929,7 @@ public function testRenderHtml(array $configuration, array $params, string $expe
/**
* @return array
*/
public function dataCountPages(): array
public static function dataCountPages(): array
{
return [
'1 item + 1 per page' => [1, 1, 1],
Expand All @@ -941,6 +946,7 @@ public function dataCountPages(): array
* @param int $countElementPerPage
* @param int $expected
*/
#[DataProvider('dataCountPages')]
public function testCountPages(int $countElements, int $countElementPerPage, int $expected): void
{
static::assertSame($expected, Pagination::countPages($countElements, $countElementPerPage));
Expand All @@ -949,7 +955,7 @@ public function testCountPages(int $countElements, int $countElementPerPage, int
/**
* @return array
*/
public function dataLocateItemInPage(): array
public static function dataLocateItemInPage(): array
{
return [
'1 per page + item index 1' => [1, 1, 1],
Expand All @@ -970,12 +976,13 @@ public function dataLocateItemInPage(): array
* @param int $itemIndex
* @param int $expected
*/
#[DataProvider('dataLocateItemInPage')]
public function testLocateItemInPage(int $countElementPerPage, int $itemIndex, int $expected): void
{
static::assertSame($expected, Pagination::locateItemInPage($countElementPerPage, $itemIndex));
}

public function dataPaginationException(): array
public static function dataPaginationException(): array
{
return [
'aria_label_nav' => [
Expand Down Expand Up @@ -1017,6 +1024,7 @@ public function dataPaginationException(): array
*
* @throws PaginationException
*/
#[DataProvider('dataPaginationException')]
public function testException(array $conf, string $message): void
{
$this->expectException(PaginationException::class);
Expand Down

0 comments on commit 27c33c8

Please sign in to comment.