cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,148 +1,135 @@
<?php
/*
/**
* Chill is a software for social workers
* Copyright (C) 2016 Champs-Libres Coopérative <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Tests\Pagination;
use Chill\MainBundle\Pagination\Page;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Chill\MainBundle\Pagination\Page;
/**
* Test the Page class
* Test the Page class.
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* @author Champs Libres <info@champs-libres.coop>
* @internal
* @coversNothing
*/
class PageTest extends KernelTestCase
{
protected $paginator;
protected $prophet;
public function setUp() {
$this->prophet = new \Prophecy\Prophet;
public function setUp()
{
$this->prophet = new \Prophecy\Prophet();
}
/**
*
* @param int $maxResult
* @param int $itemPerPage
* @param string $route
* @param array $routeParameters
* @return Page
*/
protected function generatePage(
$number = 1,
$itemPerPage = 10,
$route = 'route',
array $routeParameters = array(),
$totalItems = 100
) {
$urlGenerator = $this->prophet->prophesize();
$urlGenerator->willImplement(UrlGeneratorInterface::class);
return new Page(
$number,
$itemPerPage,
$urlGenerator->reveal(),
$route,
$routeParameters,
$totalItems
);
}
public function testPageNumber() {
$page = $this->generatePage(1);
$this->assertEquals(1, $page->getNumber());
}
/**
* return a set of element to testGetFirstItemNumber
*
* the set contains :
* return a set of element to testGetFirstItemNumber.
*
* the set contains :
* - the page number ;
* - the number of item per page ;
* - the expected first item number
*
*
* @return array
*/
public function generateGetFirstItemNumber() {
return array(
[1, 10, 0],
[2, 10, 10]
);
public function generateGetFirstItemNumber()
{
return [
[1, 10, 0],
[2, 10, 10],
];
}
/**
* return a set of element to testGetLastItemNumber.
*
* the set contains :
* - the page number ;
* - the number of item per page ;
* - the expected last item number
*
* @return array
*/
public function generateGetLastItemNumber()
{
return [
[1, 10, 9],
[2, 10, 19],
];
}
/**
*
* @param int $number
* @param int $itemPerPage
* @param int $expectedItemPerPage
* @dataProvider generateGetFirstItemNumber
*/
public function testGetFirstItemNumber(
$number,
$itemPerPage,
$expectedItemPerPage
$number,
$itemPerPage,
$expectedItemPerPage
) {
$page = $this->generatePage($number, $itemPerPage);
$this->assertEquals($expectedItemPerPage, $page->getFirstItemNumber());
}
/**
* return a set of element to testGetLastItemNumber
*
* the set contains :
* - the page number ;
* - the number of item per page ;
* - the expected last item number
*
* @return array
*/
public function generateGetLastItemNumber() {
return array(
[1, 10, 9],
[2, 10, 19]
);
}
/**
*
* @param int $number
* @param int $itemPerPage
* @param int $expectedItemPerPage
* @dataProvider generateGetLastItemNumber
*/
public function testGetLastItemNumber(
$number,
$itemPerPage,
$expectedItemPerPage
$number,
$itemPerPage,
$expectedItemPerPage
) {
$page = $this->generatePage($number, $itemPerPage);
$this->assertEquals($expectedItemPerPage, $page->getLastItemNumber());
}
public function testPageNumber()
{
$page = $this->generatePage(1);
$this->assertEquals(1, $page->getNumber());
}
/**
* @param int $itemPerPage
* @param string $route
* @param mixed $number
* @param mixed $totalItems
*
* @return Page
*/
protected function generatePage(
$number = 1,
$itemPerPage = 10,
$route = 'route',
array $routeParameters = [],
$totalItems = 100
) {
$urlGenerator = $this->prophet->prophesize();
$urlGenerator->willImplement(UrlGeneratorInterface::class);
return new Page(
$number,
$itemPerPage,
$urlGenerator->reveal(),
$route,
$routeParameters,
$totalItems
);
}
}

View File

@@ -1,133 +1,110 @@
<?php
/*
/**
* Chill is a software for social workers
* Copyright (C) 2016 Champs-Libres Coopérative <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Tests\Pagination;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Chill\MainBundle\Pagination\Paginator;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* Test the paginator class
* Test the paginator class.
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* @author Champs Libres <info@champs-libres.coop>
* @internal
* @coversNothing
*/
class PaginatorTest extends KernelTestCase
{
protected $paginator;
protected $prophet;
public function setUp()
public function setUp()
{
$this->prophet = new \Prophecy\Prophet;
$this->prophet = new \Prophecy\Prophet();
}
/**
*
* @param int $maxResult
* @param int $itemPerPage
* @param string $route
* @param array $routeParameters
* @return Paginator
*/
protected function generatePaginator(
$totalItems,
$itemPerPage,
$currentPageNumber = 1,
$route = '',
array $routeParameters = array()
) {
$urlGenerator = $this->prophet->prophesize();
$urlGenerator->willImplement(UrlGeneratorInterface::class);
return new Paginator(
$totalItems,
$itemPerPage,
$currentPageNumber,
$route,
$routeParameters,
$urlGenerator->reveal(),
'page',
'item_per_page'
);
}
/**
* generate a set of pages with different maxItem, itemPerPage, and
* expected page number
*
* @return array
*/
public function generatePageNumber()
{
return array(
[12, 10, 2],
[20, 10, 2],
[21, 10, 3],
[19, 10, 2],
[1, 10, 1],
[0, 10, 1],
[10, 10, 1]
);
}
/**
* Test that the countPages method (and his alias `count`) return
* valid results.
*
* @param int $totalItems
* @param int $itemPerPage
* @param int $expectedPageNumber
* @dataProvider generatePageNumber
*/
public function testPageNumber($totalItems, $itemPerPage, $expectedPageNumber)
{
$paginator = $this->generatePaginator($totalItems, $itemPerPage);
$this->assertEquals($expectedPageNumber, $paginator->countPages());
$this->assertEquals($expectedPageNumber, count($paginator));
}
/**
* generate an array with a set of page with :
* - total items ;
* - item per page ;
* - current page number ;
* - expected hasNextPage result
*
* - expected hasNextPage result.
*
* @return array
*/
public function generateHasNextPage()
public function generateHasNextPage()
{
return array(
[10, 10, 1, false],
[20, 10, 1, true],
[12, 10, 1, true],
[12, 10, 2, false]
);
return [
[10, 10, 1, false],
[20, 10, 1, true],
[12, 10, 1, true],
[12, 10, 2, false],
];
}
public function generateHasPage()
{
return [
[10, 10, -1, false],
[12, 10, 1, true],
[12, 10, 2, true],
[12, 10, 3, false],
];
}
/**
* generate an array with a set of page with :
* - total items ;
* - item per page ;
* - current page number ;
* - expected hasPreviousPage result.
*
* @return array
*/
public function generateHasPreviousPage()
{
return [
[10, 10, 1, false],
[20, 10, 1, false],
[12, 10, 1, false],
[12, 10, 2, true],
];
}
/**
* generate a set of pages with different maxItem, itemPerPage, and
* expected page number.
*
* @return array
*/
public function generatePageNumber()
{
return [
[12, 10, 2],
[20, 10, 2],
[21, 10, 3],
[19, 10, 2],
[1, 10, 1],
[0, 10, 1],
[10, 10, 1],
];
}
public function testGetPage()
{
$paginator = $this->generatePaginator(105, 10);
$this->assertEquals(5, $paginator->getPage(5)->getNumber());
}
/**
*
* @param int $totalItems
* @param int $itemPerPage
* @param int $currentPage
@@ -135,103 +112,123 @@ class PaginatorTest extends KernelTestCase
* @dataProvider generateHasNextPage
*/
public function testHasNextPage(
$totalItems,
$itemPerPage,
$currentPage,
$expectedHasNextPage
$totalItems,
$itemPerPage,
$currentPage,
$expectedHasNextPage
) {
$paginator = $this->generatePaginator($totalItems, $itemPerPage, $currentPage);
$this->assertEquals($expectedHasNextPage, $paginator->hasNextPage());
}
/**
* generate an array with a set of page with :
* - total items ;
* - item per page ;
* - current page number ;
* - expected hasPreviousPage result
*
* @return array
*/
public function generateHasPreviousPage()
{
return array(
[10, 10, 1, false],
[20, 10, 1, false],
[12, 10, 1, false],
[12, 10, 2, true],
);
}
/**
*
* @param int $totalItems
* @param int $itemPerPage
* @param int $currentPage
* @param bool $expectedHasPreviousPage
* @dataProvider generateHasPreviousPage
*/
public function testHasPreviousPage(
$totalItems,
$itemPerPage,
$currentPage,
$expectedHasNextPage
) {
$paginator = $this->generatePaginator($totalItems, $itemPerPage, $currentPage);
$this->assertEquals($expectedHasNextPage, $paginator->hasPreviousPage());
}
public function generateHasPage()
{
return array(
[10, 10, -1, false],
[12, 10, 1, true],
[12, 10, 2, true],
[12, 10, 3, false]
);
}
/**
* test the HasPage function
*
*
* test the HasPage function.
*
* @param int $totalItems
* @param int $itemPerpage
* @param int $pageNumber
* @param bool $expectedHasPage
* @dataProvider generateHasPage
*/
public function testHasPage($totalItems, $itemPerpage, $pageNumber,
$expectedHasPage)
public function testHasPage(
$totalItems,
$itemPerpage,
$pageNumber,
$expectedHasPage
)
{
$paginator = $this->generatePaginator($totalItems, $itemPerpage);
$this->assertEquals($expectedHasPage, $paginator->hasPage($pageNumber));
}
public function testGetPage()
{
$paginator = $this->generatePaginator(105, 10);
$this->assertEquals(5, $paginator->getPage(5)->getNumber());
/**
* @param int $totalItems
* @param int $itemPerPage
* @param int $currentPage
* @param mixed $expectedHasNextPage
* @dataProvider generateHasPreviousPage
*/
public function testHasPreviousPage(
$totalItems,
$itemPerPage,
$currentPage,
$expectedHasNextPage
) {
$paginator = $this->generatePaginator($totalItems, $itemPerPage, $currentPage);
$this->assertEquals($expectedHasNextPage, $paginator->hasPreviousPage());
}
/**
* Test that the countPages method (and his alias `count`) return
* valid results.
*
* @param int $totalItems
* @param int $itemPerPage
* @param int $expectedPageNumber
* @dataProvider generatePageNumber
*/
public function testPageNumber($totalItems, $itemPerPage, $expectedPageNumber)
{
$paginator = $this->generatePaginator($totalItems, $itemPerPage);
$this->assertEquals($expectedPageNumber, $paginator->countPages());
$this->assertEquals($expectedPageNumber, count($paginator));
}
public function testPagesGenerator()
{
$paginator = $this->generatePaginator(105, 10);
$generator = $paginator->getPagesGenerator();
$i = 1;
foreach($generator as $page) {
$this->assertEquals($i, $page->getNumber(),
"assert that the current page number is $i");
$i++;
foreach ($generator as $page) {
$this->assertEquals(
$i,
$page->getNumber(),
"assert that the current page number is {$i}"
);
++$i;
}
$this->assertEquals(11, $page->getNumber(),
"assert that the last page number is 11");
$this->assertEquals(
11,
$page->getNumber(),
'assert that the last page number is 11'
);
}
/**
* @param int $itemPerPage
* @param string $route
* @param mixed $totalItems
* @param mixed $currentPageNumber
*
* @return Paginator
*/
protected function generatePaginator(
$totalItems,
$itemPerPage,
$currentPageNumber = 1,
$route = '',
array $routeParameters = []
) {
$urlGenerator = $this->prophet->prophesize();
$urlGenerator->willImplement(UrlGeneratorInterface::class);
return new Paginator(
$totalItems,
$itemPerPage,
$currentPageNumber,
$route,
$routeParameters,
$urlGenerator->reveal(),
'page',
'item_per_page'
);
}
}