Skip to content

Commit b531115

Browse files
wbloszykphansys
andcommittedSep 23, 2020
Bump sonata-project/datagrid-bundle to version ^3.0
Update UPGRADE-4.x.md Co-authored-by: Javier Spagnoletti <phansys@gmail.com> Update UPGRADE-4.x.md Co-authored-by: Javier Spagnoletti <phansys@gmail.com> Update tests/Controller/Api/UserControllerTest.php Co-authored-by: Javier Spagnoletti <phansys@gmail.com> Update tests/Controller/Api/GroupControllerTest.php Co-authored-by: Javier Spagnoletti <phansys@gmail.com> Update tests/Controller/Api/UserControllerTest.php Co-authored-by: Javier Spagnoletti <phansys@gmail.com> Update UPGRADE-4.x.md Co-authored-by: Javier Spagnoletti <phansys@gmail.com> Update UPGRADE-4.x.md Co-authored-by: Javier Spagnoletti <phansys@gmail.com> Update UPGRADE-4.x.md Co-authored-by: Javier Spagnoletti <phansys@gmail.com> Update UPGRADE-4.x.md Co-authored-by: Javier Spagnoletti <phansys@gmail.com>
1 parent b3b54ef commit b531115

10 files changed

+40
-35
lines changed
 

‎UPGRADE-4.x.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
UPGRADE 4.x
22
===========
33

4-
UPGRADE FROM 3.x to 3.x
4+
UPGRADE FROM 4.x to 4.x
55
=======================
66

7-
### Support for NelmioApiDocBundle > 3.6 is added
7+
### Dependencies
88

9-
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.
9+
- "sonata-project/datagrid-bundle" is bumped from ^2.4 to ^3.0.
10+
11+
If you are extending these method you MUST add argument and return type declarations:
12+
- `Sonata\UserBundle\Entity\UserManager::getPager()`
13+
- `Sonata\UserBundle\Entity\GroupManager::getPager()`
14+
15+
- Added support for "nelmio/api-doc-bundle" ^3.6.
16+
17+
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.
1018

1119
UPGRADE FROM 4.6 to 4.7
1220
========================

‎composer.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"php": "^7.2",
2525
"friendsofsymfony/user-bundle": "^2.0",
2626
"sonata-project/admin-bundle": "^3.34",
27-
"sonata-project/datagrid-bundle": "^2.4.0",
27+
"sonata-project/datagrid-bundle": "^3.0.1",
2828
"sonata-project/doctrine-extensions": "^1.8",
2929
"sonata-project/form-extensions": "^0.1 || ^1.4",
3030
"swiftmailer/swiftmailer": "^4.3 || ^5.0 || ^6.0",
@@ -50,8 +50,10 @@
5050
"sonata-project/google-authenticator": "<1.0"
5151
},
5252
"require-dev": {
53+
"doctrine/annotations": "^1.10",
5354
"doctrine/doctrine-bundle": "^2.0",
5455
"doctrine/orm": "^2.0",
56+
"egulias/email-validator": "^2.1.9",
5557
"friendsofsymfony/rest-bundle": "^2.1 || ^3.0",
5658
"jms/serializer-bundle": "^1.0 || ^2.0 || ^3.0",
5759
"matthiasnoback/symfony-config-test": "^4.0",

‎src/Controller/Api/GroupController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ public function getGroupsAction(ParamFetcherInterface $paramFetcher)
110110
'enabled' => '',
111111
];
112112

113-
$page = $paramFetcher->get('page');
114-
$limit = $paramFetcher->get('count');
113+
$page = $paramFetcher->get('page') ?? 1;
114+
$limit = $paramFetcher->get('count') ?? 10;
115115
$sort = $paramFetcher->get('orderBy');
116116
$criteria = array_intersect_key($paramFetcher->all(), $supportedFilters);
117117

‎src/Controller/Api/Legacy/GroupController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public function getGroupsAction(ParamFetcherInterface $paramFetcher)
7575
'enabled' => '',
7676
];
7777

78-
$page = $paramFetcher->get('page');
79-
$limit = $paramFetcher->get('count');
78+
$page = $paramFetcher->get('page') ?? 1;
79+
$limit = $paramFetcher->get('count') ?? 10;
8080
$sort = $paramFetcher->get('orderBy');
8181
$criteria = array_intersect_key($paramFetcher->all(), $supportedFilters);
8282

‎src/Controller/Api/Legacy/UserController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public function getUsersAction(ParamFetcherInterface $paramFetcher)
7979
'enabled' => '',
8080
];
8181

82-
$page = $paramFetcher->get('page');
83-
$limit = $paramFetcher->get('count');
82+
$page = $paramFetcher->get('page') ?? 1;
83+
$limit = $paramFetcher->get('count') ?? 10;
8484
$sort = $paramFetcher->get('orderBy');
8585
$criteria = array_intersect_key($paramFetcher->all(), $supporedCriteria);
8686

‎src/Controller/Api/UserController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public function getUsersAction(ParamFetcherInterface $paramFetcher)
114114
'enabled' => '',
115115
];
116116

117-
$page = $paramFetcher->get('page');
118-
$limit = $paramFetcher->get('count');
117+
$page = $paramFetcher->get('page') ?? 1;
118+
$limit = $paramFetcher->get('count') ?? 10;
119119
$sort = $paramFetcher->get('orderBy');
120120
$criteria = array_intersect_key($paramFetcher->all(), $supporedCriteria);
121121

‎src/Entity/GroupManager.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use FOS\UserBundle\Doctrine\GroupManager as BaseGroupManager;
1717
use Sonata\DatagridBundle\Pager\Doctrine\Pager;
18-
use Sonata\DatagridBundle\ProxyQuery\Doctrine\ProxyQuery;
18+
use Sonata\DatagridBundle\Pager\PagerInterface;
1919
use Sonata\UserBundle\Model\GroupManagerInterface;
2020

2121
/**
@@ -34,7 +34,7 @@ public function findGroupsBy(?array $criteria = null, ?array $orderBy = null, $l
3434
/**
3535
* {@inheritdoc}
3636
*/
37-
public function getPager(array $criteria, $page, $limit = 10, array $sort = [])
37+
public function getPager(array $criteria, int $page, int $limit = 10, array $sort = []): PagerInterface
3838
{
3939
$query = $this->repository
4040
->createQueryBuilder('g')
@@ -64,12 +64,6 @@ public function getPager(array $criteria, $page, $limit = 10, array $sort = [])
6464

6565
$query->setParameters($parameters);
6666

67-
$pager = new Pager();
68-
$pager->setMaxPerPage($limit);
69-
$pager->setQuery(new ProxyQuery($query));
70-
$pager->setPage($page);
71-
$pager->init();
72-
73-
return $pager;
67+
return Pager::create($query, $limit, $page);
7468
}
7569
}

‎src/Entity/UserManager.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use FOS\UserBundle\Doctrine\UserManager as BaseUserManager;
1717
use Sonata\DatagridBundle\Pager\Doctrine\Pager;
18-
use Sonata\DatagridBundle\ProxyQuery\Doctrine\ProxyQuery;
18+
use Sonata\DatagridBundle\Pager\PagerInterface;
1919
use Sonata\Doctrine\Model\ManagerInterface;
2020
use Sonata\UserBundle\Model\UserInterface;
2121
use Sonata\UserBundle\Model\UserManagerInterface;
@@ -116,7 +116,7 @@ public function getConnection()
116116
/**
117117
* {@inheritdoc}
118118
*/
119-
public function getPager(array $criteria, $page, $limit = 10, array $sort = [])
119+
public function getPager(array $criteria, int $page, int $limit = 10, array $sort = []): PagerInterface
120120
{
121121
$query = $this->getRepository()
122122
->createQueryBuilder('u')
@@ -140,12 +140,6 @@ public function getPager(array $criteria, $page, $limit = 10, array $sort = [])
140140
$query->setParameter('enabled', $criteria['enabled']);
141141
}
142142

143-
$pager = new Pager();
144-
$pager->setMaxPerPage($limit);
145-
$pager->setQuery(new ProxyQuery($query));
146-
$pager->setPage($page);
147-
$pager->init();
148-
149-
return $pager;
143+
return Pager::create($query, $limit, $page);
150144
}
151145
}

‎tests/Controller/Api/GroupControllerTest.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use FOS\RestBundle\View\View;
1818
use FOS\UserBundle\Model\GroupInterface;
1919
use PHPUnit\Framework\TestCase;
20+
use Sonata\DatagridBundle\Pager\PagerInterface;
2021
use Sonata\UserBundle\Controller\Api\GroupController;
2122
use Sonata\UserBundle\Entity\BaseGroup;
2223
use Sonata\UserBundle\Model\GroupManagerInterface;
@@ -35,14 +36,16 @@ public function testGetGroupsAction(): void
3536
{
3637
$group = $this->createMock(GroupInterface::class);
3738
$groupManager = $this->createMock(GroupManagerInterface::class);
38-
$groupManager->expects($this->once())->method('getPager')->willReturn([$group]);
39+
$pager = $this->createStub(PagerInterface::class);
40+
$pager->method('getResults')->willReturn([$group]);
41+
$groupManager->expects($this->once())->method('getPager')->willReturn($pager);
3942

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

4245
$paramFetcher->expects($this->exactly(3))->method('get');
4346
$paramFetcher->expects($this->once())->method('all')->willReturn([]);
4447

45-
$this->assertSame([$group], $this->createGroupController(null, $groupManager)->getGroupsAction($paramFetcher));
48+
$this->assertSame([$group], $this->createGroupController(null, $groupManager)->getGroupsAction($paramFetcher)->getResults());
4649
}
4750

4851
public function testGetGroupAction(): void

‎tests/Controller/Api/UserControllerTest.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use FOS\UserBundle\Model\GroupInterface;
1919
use FOS\UserBundle\Model\UserInterface;
2020
use PHPUnit\Framework\TestCase;
21+
use Sonata\DatagridBundle\Pager\PagerInterface;
2122
use Sonata\UserBundle\Controller\Api\UserController;
2223
use Sonata\UserBundle\Entity\BaseUser;
2324
use Sonata\UserBundle\Model\GroupManagerInterface;
@@ -35,19 +36,22 @@ class UserControllerTest extends TestCase
3536
{
3637
public function testGetUsersAction(): void
3738
{
39+
$user = $this->createMock(UserInterface::class);
3840
$userManager = $this->createMock(UserManagerInterface::class);
39-
$userManager->expects($this->once())->method('getPager')->willReturn([]);
41+
$pager = $this->createStub(PagerInterface::class);
42+
$pager->method('getResults')->willReturn([$user]);
43+
$userManager->expects($this->once())->method('getPager')->willReturn($pager);
4044

4145
$paramFetcher = $this->createMock(ParamFetcherInterface::class);
4246
$paramFetcher->expects($this->exactly(3))->method('get');
4347
$paramFetcher->expects($this->once())->method('all')->willReturn([]);
4448

45-
$this->assertSame([], $this->createUserController(null, $userManager)->getUsersAction($paramFetcher));
49+
$this->assertSame([$user], $this->createUserController(null, $userManager)->getUsersAction($paramFetcher)->getResults());
4650
}
4751

4852
public function testGetUserAction(): void
4953
{
50-
$user = $this->createMock(\Sonata\UserBundle\Model\UserInterface::class);
54+
$user = $this->createStub(UserInterface::class);
5155
$this->assertSame($user, $this->createUserController($user)->getUserAction(1));
5256
}
5357

0 commit comments

Comments
 (0)