Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump sonata-project/datagrid-bundle to version ^3.0 #1230

Merged
merged 1 commit into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions UPGRADE-4.x.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
UPGRADE 4.x
===========

UPGRADE FROM 3.x to 3.x
UPGRADE FROM 4.x to 4.x
=======================

### Support for NelmioApiDocBundle > 3.6 is added
### Dependencies

Controllers for NelmioApiDocBundle v2 were moved under `Sonata\UserBundle\Controller\Api\Legacy\` namespace and controllers for NelmioApiDocBundle v3 were added as replacement. If you extend them, you must ensure they are using the corresponding inheritance.
- "sonata-project/datagrid-bundle" is bumped from ^2.4 to ^3.0.

If you are extending these methods, you MUST add argument and return type declarations:
- `Sonata\UserBundle\Entity\UserManager::getPager()`
- `Sonata\UserBundle\Entity\GroupManager::getPager()`

- Added support for "nelmio/api-doc-bundle" ^3.6.

Controllers for NelmioApiDocBundle v2 were moved under `Sonata\UserBundle\Controller\Api\Legacy\` namespace and controllers for NelmioApiDocBundle v3 were added as replacement. If you extend them, you must ensure they are using the corresponding inheritance.

UPGRADE FROM 4.6 to 4.7
========================
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"php": "^7.2",
"friendsofsymfony/user-bundle": "^2.0",
"sonata-project/admin-bundle": "^3.34",
"sonata-project/datagrid-bundle": "^2.4.0",
"sonata-project/datagrid-bundle": "^3.0.1",
"sonata-project/doctrine-extensions": "^1.8",
"sonata-project/form-extensions": "^0.1 || ^1.4",
"swiftmailer/swiftmailer": "^4.3 || ^5.0 || ^6.0",
Expand All @@ -50,8 +50,10 @@
"sonata-project/google-authenticator": "<1.0"
},
"require-dev": {
"doctrine/annotations": "^1.10",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/orm": "^2.0",
"egulias/email-validator": "^2.1.9",
"friendsofsymfony/rest-bundle": "^2.1 || ^3.0",
"jms/serializer-bundle": "^1.0 || ^2.0 || ^3.0",
"matthiasnoback/symfony-config-test": "^4.0",
Expand Down
12 changes: 3 additions & 9 deletions src/Entity/GroupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use FOS\UserBundle\Doctrine\GroupManager as BaseGroupManager;
use Sonata\DatagridBundle\Pager\Doctrine\Pager;
use Sonata\DatagridBundle\ProxyQuery\Doctrine\ProxyQuery;
use Sonata\DatagridBundle\Pager\PagerInterface;
use Sonata\UserBundle\Model\GroupManagerInterface;

/**
Expand All @@ -34,7 +34,7 @@ public function findGroupsBy(?array $criteria = null, ?array $orderBy = null, $l
/**
* {@inheritdoc}
*/
public function getPager(array $criteria, $page, $limit = 10, array $sort = [])
public function getPager(array $criteria, int $page, int $limit = 10, array $sort = []): PagerInterface
{
$query = $this->repository
->createQueryBuilder('g')
Expand Down Expand Up @@ -64,12 +64,6 @@ public function getPager(array $criteria, $page, $limit = 10, array $sort = [])

$query->setParameters($parameters);

$pager = new Pager();
$pager->setMaxPerPage($limit);
$pager->setQuery(new ProxyQuery($query));
$pager->setPage($page);
$pager->init();

return $pager;
return Pager::create($query, $limit, $page);
}
}
12 changes: 3 additions & 9 deletions src/Entity/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use FOS\UserBundle\Doctrine\UserManager as BaseUserManager;
use Sonata\DatagridBundle\Pager\Doctrine\Pager;
use Sonata\DatagridBundle\ProxyQuery\Doctrine\ProxyQuery;
use Sonata\DatagridBundle\Pager\PagerInterface;
use Sonata\Doctrine\Model\ManagerInterface;
use Sonata\UserBundle\Model\UserInterface;
use Sonata\UserBundle\Model\UserManagerInterface;
Expand Down Expand Up @@ -116,7 +116,7 @@ public function getConnection()
/**
* {@inheritdoc}
*/
public function getPager(array $criteria, $page, $limit = 10, array $sort = [])
public function getPager(array $criteria, int $page, int $limit = 10, array $sort = []): PagerInterface
{
$query = $this->getRepository()
->createQueryBuilder('u')
Expand All @@ -140,12 +140,6 @@ public function getPager(array $criteria, $page, $limit = 10, array $sort = [])
$query->setParameter('enabled', $criteria['enabled']);
}

$pager = new Pager();
$pager->setMaxPerPage($limit);
$pager->setQuery(new ProxyQuery($query));
$pager->setPage($page);
$pager->init();

return $pager;
return Pager::create($query, $limit, $page);
}
}
9 changes: 6 additions & 3 deletions tests/Controller/Api/GroupControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use FOS\RestBundle\View\View;
use FOS\UserBundle\Model\GroupInterface;
use PHPUnit\Framework\TestCase;
use Sonata\DatagridBundle\Pager\PagerInterface;
use Sonata\UserBundle\Controller\Api\GroupController;
use Sonata\UserBundle\Entity\BaseGroup;
use Sonata\UserBundle\Model\GroupManagerInterface;
Expand All @@ -35,14 +36,16 @@ public function testGetGroupsAction(): void
{
$group = $this->createMock(GroupInterface::class);
$groupManager = $this->createMock(GroupManagerInterface::class);
$groupManager->expects($this->once())->method('getPager')->willReturn([$group]);
$pager = $this->createStub(PagerInterface::class);
$pager->method('getResults')->willReturn([$group]);
$groupManager->expects($this->once())->method('getPager')->willReturn($pager);

$paramFetcher = $this->createMock(ParamFetcherInterface::class);

$paramFetcher->expects($this->exactly(3))->method('get');
$paramFetcher->expects($this->exactly(3))->method('get')->willReturn(1, 10, null);
$paramFetcher->expects($this->once())->method('all')->willReturn([]);

$this->assertSame([$group], $this->createGroupController(null, $groupManager)->getGroupsAction($paramFetcher));
$this->assertSame([$group], $this->createGroupController(null, $groupManager)->getGroupsAction($paramFetcher)->getResults());
}

public function testGetGroupAction(): void
Expand Down
12 changes: 8 additions & 4 deletions tests/Controller/Api/UserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use FOS\UserBundle\Model\GroupInterface;
use FOS\UserBundle\Model\UserInterface;
use PHPUnit\Framework\TestCase;
use Sonata\DatagridBundle\Pager\PagerInterface;
use Sonata\UserBundle\Controller\Api\UserController;
use Sonata\UserBundle\Entity\BaseUser;
use Sonata\UserBundle\Model\GroupManagerInterface;
Expand All @@ -35,19 +36,22 @@ class UserControllerTest extends TestCase
{
public function testGetUsersAction(): void
{
$user = $this->createMock(UserInterface::class);
$userManager = $this->createMock(UserManagerInterface::class);
$userManager->expects($this->once())->method('getPager')->willReturn([]);
$pager = $this->createStub(PagerInterface::class);
$pager->method('getResults')->willReturn([$user]);
$userManager->expects($this->once())->method('getPager')->willReturn($pager);

$paramFetcher = $this->createMock(ParamFetcherInterface::class);
$paramFetcher->expects($this->exactly(3))->method('get');
$paramFetcher->expects($this->exactly(3))->method('get')->willReturn(1, 10, null);
$paramFetcher->expects($this->once())->method('all')->willReturn([]);

$this->assertSame([], $this->createUserController(null, $userManager)->getUsersAction($paramFetcher));
$this->assertSame([$user], $this->createUserController(null, $userManager)->getUsersAction($paramFetcher)->getResults());
}

public function testGetUserAction(): void
{
$user = $this->createMock(\Sonata\UserBundle\Model\UserInterface::class);
$user = $this->createStub(UserInterface::class);
$this->assertSame($user, $this->createUserController($user)->getUserAction(1));
}

Expand Down