Skip to content

Commit bf5af03

Browse files
committed
Update to phpunit v12
1 parent 7842ca4 commit bf5af03

8 files changed

Lines changed: 780 additions & 640 deletions

File tree

phpstan-baseline.neon

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,6 @@ parameters:
162162
count: 1
163163
path: tests/Action/LoginActionTest.php
164164

165-
-
166-
message: '#^Call to function method_exists\(\) with ''Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserProviderInterface'' and ''loadUserByIdentifier'' will always evaluate to true\.$#'
167-
identifier: function.alreadyNarrowedType
168-
count: 1
169-
path: tests/Action/SendEmailActionTest.php
170-
171165
-
172166
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertNotEmpty\(\) with Nucleos\\UserAdminBundle\\Admin\\Entity\\GroupAdmin will always evaluate to true\.$#'
173167
identifier: staticMethod.alreadyNarrowedType
@@ -186,30 +180,6 @@ parameters:
186180
count: 1
187181
path: tests/App/Entity/User.php
188182

189-
-
190-
message: '#^Call to function method_exists\(\) with ''Symfony\\\\Bundle\\\\TwigBundle\\\\DependencyInjection\\\\TwigExtension'' and ''getAlias'' will always evaluate to true\.$#'
191-
identifier: function.alreadyNarrowedType
192-
count: 1
193-
path: tests/DependencyInjection/NucleosUserAdminExtensionTest.php
194-
195-
-
196-
message: '#^Call to function method_exists\(\) with ''Symfony\\\\Bundle\\\\TwigBundle\\\\DependencyInjection\\\\TwigExtension'' and ''load'' will always evaluate to true\.$#'
197-
identifier: function.alreadyNarrowedType
198-
count: 1
199-
path: tests/DependencyInjection/NucleosUserAdminExtensionTest.php
200-
201-
-
202-
message: '#^Call to function method_exists\(\) with ''Symfony\\\\Component\\\\DependencyInjection\\\\ContainerBuilder'' and ''hasExtension'' will always evaluate to true\.$#'
203-
identifier: function.alreadyNarrowedType
204-
count: 1
205-
path: tests/DependencyInjection/NucleosUserAdminExtensionTest.php
206-
207-
-
208-
message: '#^Call to function method_exists\(\) with ''Symfony\\\\Component\\\\DependencyInjection\\\\ContainerBuilder'' and ''prependExtensionCon…'' will always evaluate to true\.$#'
209-
identifier: function.alreadyNarrowedType
210-
count: 1
211-
path: tests/DependencyInjection/NucleosUserAdminExtensionTest.php
212-
213183
-
214184
message: '#^Method Nucleos\\UserAdminBundle\\Tests\\Fixtures\\PoolMockFactory\:\:create\(\) has parameter \$adminServiceIds with generic interface Sonata\\AdminBundle\\Admin\\AdminInterface but does not specify its types\: T$#'
215185
identifier: missingType.generics

tests/Action/AdminsTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
use Generator;
1515
use Nucleos\UserAdminBundle\Tests\App\Entity\Group;
1616
use Nucleos\UserAdminBundle\Tests\App\Entity\User;
17+
use PHPUnit\Framework\Attributes\DataProvider;
1718

1819
/**
1920
* @group integration
2021
*/
2122
final class AdminsTest extends IntegrationTestCase
2223
{
23-
/**
24-
* @dataProvider provideCrudUrlsCases
25-
*/
24+
#[DataProvider('provideCrudUrlsCases')]
2625
public function testCrudUrls(string $url): void
2726
{
2827
$client = self::createClient();

tests/Action/LoginActionTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Nucleos\UserAdminBundle\Tests\Fixtures\PoolMockFactory;
1717
use Nucleos\UserBundle\Model\UserInterface;
1818
use PHPUnit\Framework\Assert;
19+
use PHPUnit\Framework\Attributes\DataProvider;
1920
use PHPUnit\Framework\MockObject\MockObject;
2021
use PHPUnit\Framework\MockObject\Rule\InvokedCount;
2122
use PHPUnit\Framework\TestCase;
@@ -150,9 +151,7 @@ static function (string $message): string {
150151
], $session->getFlashBag()->all());
151152
}
152153

153-
/**
154-
* @dataProvider provideUserGrantedAdminCases
155-
*/
154+
#[DataProvider('provideUserGrantedAdminCases')]
156155
public function testUserGrantedAdmin(string $referer, string $expectedRedirectUrl): void
157156
{
158157
$session = $this->createMock(Session::class);
@@ -197,10 +196,9 @@ public static function provideUserGrantedAdminCases(): iterable
197196
}
198197

199198
/**
200-
* @dataProvider provideUnauthenticatedCases
201-
*
202199
* @SuppressWarnings("PHPMD.ExcessiveMethodLength")
203200
*/
201+
#[DataProvider('provideUnauthenticatedCases')]
204202
public function testUnauthenticated(string $lastUsername, ?AuthenticationException $errorMessage = null): void
205203
{
206204
$session = $this->createMock(Session::class);

tests/Action/SendEmailActionTest.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,7 @@ protected function setUp(): void
6868
$this->userManager = $this->createMock(UserManager::class);
6969
$this->mailer = $this->createMock(ResettingMailer::class);
7070
$this->tokenGenerator = $this->createMock(TokenGenerator::class);
71-
72-
if (!method_exists(UserProviderInterface::class, 'loadUserByIdentifier')) {
73-
$this->userProvider = $this->getMockBuilder(UserProviderInterface::class)
74-
->addMethods(['loadUserByIdentifier'])
75-
->getMockForAbstractClass()
76-
;
77-
} else {
78-
$this->userProvider = $this->createMock(UserProviderInterface::class);
79-
}
80-
71+
$this->userProvider = $this->createMock(UserProviderInterface::class);
8172
$this->resetTtl = 60;
8273
$this->fromEmail = 'noreply@localhost';
8374
$this->container = $this->createMock(ContainerBuilder::class);

tests/DependencyInjection/NucleosUserAdminExtensionTest.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -158,34 +158,14 @@ protected function getContainerExtensions(): array
158158
*/
159159
private function createContainerBuilder(): ContainerBuilder
160160
{
161-
$mockBuilder = $this->getMockBuilder(ContainerBuilder::class)
162-
->disableOriginalConstructor()
163-
;
164-
165-
if (!method_exists(ContainerBuilder::class, 'hasExtension')) {
166-
$mockBuilder->addMethods(['hasExtension']);
167-
}
168-
if (!method_exists(ContainerBuilder::class, 'prependExtensionConfig')) {
169-
$mockBuilder->addMethods(['prependExtensionConfig']);
170-
}
171-
172-
return $mockBuilder->getMock();
161+
return $this->createMock(ContainerBuilder::class);
173162
}
174163

175164
/**
176165
* @return MockObject&TwigExtension
177166
*/
178167
private function createTwigExtension(): TwigExtension
179168
{
180-
$mockBuilder = $this->getMockBuilder(TwigExtension::class);
181-
182-
if (!method_exists(TwigExtension::class, 'load')) {
183-
$mockBuilder = $mockBuilder->addMethods(['load']);
184-
}
185-
if (!method_exists(TwigExtension::class, 'getAlias')) {
186-
$mockBuilder = $mockBuilder->addMethods(['getAlias']);
187-
}
188-
189-
return $mockBuilder->getMock();
169+
return $this->createMock(TwigExtension::class);
190170
}
191171
}

tests/Resources/XliffTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Nucleos\UserAdminBundle\Tests\Resources;
1313

14+
use PHPUnit\Framework\Attributes\DataProvider;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\Translation\Exception\InvalidResourceException;
1617
use Symfony\Component\Translation\Loader\XliffFileLoader;
@@ -29,9 +30,7 @@ protected function setUp(): void
2930
$this->loader = new XliffFileLoader();
3031
}
3132

32-
/**
33-
* @dataProvider provideXliffCases
34-
*/
33+
#[DataProvider('provideXliffCases')]
3534
public function testXliff(string $path): void
3635
{
3736
$this->validatePath($path);

vendor-bin/tools/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"phpstan/phpstan-phpunit": "^2.0.0",
1313
"phpstan/phpstan-strict-rules": "^2.0.0",
1414
"phpstan/phpstan-symfony": "^2.0.0",
15-
"phpunit/phpunit": "^10.1.2",
15+
"phpunit/phpunit": "^12.0.0",
1616
"symfony/phpunit-bridge": "^7.0"
1717
},
1818
"config": {

0 commit comments

Comments
 (0)