diff --git a/composer.json b/composer.json index 9f287c351..458f94674 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "sonata-project/doctrine-orm-admin-bundle": "^3.18", "sonata-project/google-authenticator": "^1.0 || ^2.0", "symfony/browser-kit": "^4.4 || ^5.1", - "symfony/phpunit-bridge": "^5.1" + "symfony/phpunit-bridge": "^5.1.1" }, "suggest": { "friendsofsymfony/rest-bundle": "For using the public API methods.", diff --git a/tests/Controller/AdminResettingControllerTest.php b/tests/Controller/AdminResettingControllerTest.php index c133fa9dc..9e76c3e06 100644 --- a/tests/Controller/AdminResettingControllerTest.php +++ b/tests/Controller/AdminResettingControllerTest.php @@ -20,12 +20,15 @@ use Sonata\UserBundle\Action\ResetAction; use Sonata\UserBundle\Action\SendEmailAction; use Sonata\UserBundle\Controller\AdminResettingController; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; class AdminResettingControllerTest extends TestCase { + use ExpectDeprecationTrait; + /** * @var RequestStack|MockObject */ @@ -75,7 +78,6 @@ public function getController(): AdminResettingController /** * @group legacy - * @expectedDeprecation The Sonata\UserBundle\Controller\AdminResettingController class is deprecated since version 4.3.0 and will be removed in 5.0. Use Sonata\UserBundle\Action\RequestAction, Sonata\UserBundle\Action\CheckEmailAction, Sonata\UserBundle\Action\ResetAction or Sonata\UserBundle\Action\SendEmailAction instead. */ public function testCheckEmailAction(): void { @@ -85,7 +87,14 @@ public function testCheckEmailAction(): void ->method('getCurrentRequest') ->willReturn($request); + $this->expectDeprecation( + 'The Sonata\UserBundle\Controller\AdminResettingController class is deprecated since version 4.3.0' + .' and will be removed in 5.0. Use Sonata\UserBundle\Action\RequestAction, Sonata\UserBundle\Action\CheckEmailAction' + .', Sonata\UserBundle\Action\ResetAction or Sonata\UserBundle\Action\SendEmailAction instead.' + ); + $controller = $this->getController(); + $result = $controller->checkEmailAction($request); $this->assertSame('ok', $result); diff --git a/tests/Controller/AdminSecurityControllerTest.php b/tests/Controller/AdminSecurityControllerTest.php index b3aec3658..6d40d2a4b 100644 --- a/tests/Controller/AdminSecurityControllerTest.php +++ b/tests/Controller/AdminSecurityControllerTest.php @@ -19,12 +19,15 @@ use Sonata\UserBundle\Action\LoginAction; use Sonata\UserBundle\Action\LogoutAction; use Sonata\UserBundle\Controller\AdminSecurityController; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; class AdminSecurityControllerTest extends TestCase { + use ExpectDeprecationTrait; + /** * @var TestSecurityAction */ @@ -67,10 +70,15 @@ public function getController(): AdminSecurityController /** * @group legacy - * @expectedDeprecation The Sonata\UserBundle\Controller\AdminSecurityController class is deprecated since version 4.3.0 and will be removed in 5.0. Use Sonata\UserBundle\Action\CheckLoginAction, Sonata\UserBundle\Action\LoginAction or Sonata\UserBundle\Action\LogoutAction instead. */ public function testLogoutAction(): void { + $this->expectDeprecation( + 'The Sonata\UserBundle\Controller\AdminSecurityController class is deprecated since version 4.3.0' + .' and will be removed in 5.0. Use Sonata\UserBundle\Action\CheckLoginAction, Sonata\UserBundle\Action\LoginAction' + .' or Sonata\UserBundle\Action\LogoutAction instead.' + ); + $controller = $this->getController(); $controller->logoutAction(); } diff --git a/tests/DependencyInjection/SonataUserExtensionTest.php b/tests/DependencyInjection/SonataUserExtensionTest.php index 724fcab73..ea9472c83 100644 --- a/tests/DependencyInjection/SonataUserExtensionTest.php +++ b/tests/DependencyInjection/SonataUserExtensionTest.php @@ -24,6 +24,7 @@ use Sonata\UserBundle\Tests\Admin\Document\UserAdmin; use Sonata\UserBundle\Tests\Document\Group; use Sonata\UserBundle\Tests\Document\User; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension; use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -34,6 +35,8 @@ */ final class SonataUserExtensionTest extends AbstractExtensionTestCase { + use ExpectDeprecationTrait; + /** * {@inheritdoc} */ @@ -49,10 +52,11 @@ protected function setUp(): void /** * @group legacy - * @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. */ public function testLoadDefault(): void { + $this->expectDeprecation('The \'Google\Authenticator\' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0.'); + $this->load(); $this->assertContainerBuilderHasAlias( @@ -90,7 +94,6 @@ public function testTwigConfigParameterIsSetting(): void /** * @group legacy - * @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. */ public function testTwigConfigParameterIsSet(): void { @@ -104,6 +107,8 @@ public function testTwigConfigParameterIsSet(): void $this->container->registerExtension($fakeTwigExtension); + $this->expectDeprecation('The \'Google\Authenticator\' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0.'); + $this->load(); $twigConfigurations = $this->container->getExtensionConfig('twig'); @@ -118,10 +123,11 @@ public function testTwigConfigParameterIsSet(): void /** * @group legacy - * @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. */ public function testTwigConfigParameterIsNotSet(): void { + $this->expectDeprecation('The \'Google\Authenticator\' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0.'); + $this->load(); $twigConfigurations = $this->container->getExtensionConfig('twig'); @@ -131,37 +137,41 @@ public function testTwigConfigParameterIsNotSet(): void /** * @group legacy - * @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. */ public function testCorrectModelClass(): void { + $this->expectDeprecation('The \'Google\Authenticator\' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0.'); + $this->load(['class' => ['user' => \Sonata\UserBundle\Tests\Entity\User::class]]); } /** * @group legacy - * @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. */ public function testCorrectModelClassWithLeadingSlash(): void { + $this->expectDeprecation('The \'Google\Authenticator\' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0.'); + $this->load(['class' => ['user' => \Sonata\UserBundle\Tests\Entity\User::class]]); } /** * @group legacy - * @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. */ public function testCorrectAdminClass(): void { + $this->expectDeprecation('The \'Google\Authenticator\' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0.'); + $this->load(['admin' => ['user' => ['class' => \Sonata\UserBundle\Tests\Admin\Entity\UserAdmin::class]]]); } /** * @group legacy - * @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. */ public function testCorrectModelClassWithNotDefaultManagerType(): void { + $this->expectDeprecation('The \'Google\Authenticator\' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0.'); + $this->load([ 'manager_type' => 'mongodb', 'class' => [ @@ -177,10 +187,11 @@ public function testCorrectModelClassWithNotDefaultManagerType(): void /** * @group legacy - * @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. */ public function testFosUserBundleModelClasses(): void { + $this->expectDeprecation('The \'Google\Authenticator\' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0.'); + $this->load(['manager_type' => 'orm', 'class' => [ 'user' => UserInterface::class, 'group' => GroupInterface::class, @@ -189,7 +200,6 @@ public function testFosUserBundleModelClasses(): void /** * @group legacy - * @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. */ public function testNotCorrespondingUserClass(): void { @@ -199,12 +209,13 @@ public function testNotCorrespondingUserClass(): void 'Model class "Sonata\UserBundle\Entity\BaseUser" does not correspond to manager type "mongodb".' ); + $this->expectDeprecation('The \'Google\Authenticator\' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0.'); + $this->load(['manager_type' => 'mongodb', 'class' => ['user' => \Sonata\UserBundle\Entity\BaseUser::class]]); } /** * @group legacy - * @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. */ public function testNotCorrespondingGroupClass(): void { @@ -214,6 +225,8 @@ public function testNotCorrespondingGroupClass(): void 'Model class "Sonata\UserBundle\Entity\BaseGroup" does not correspond to manager type "mongodb".' ); + $this->expectDeprecation('The \'Google\Authenticator\' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0.'); + $this->load(['manager_type' => 'mongodb', 'class' => [ 'user' => BaseUser::class, 'group' => BaseGroup::class, @@ -222,10 +235,11 @@ public function testNotCorrespondingGroupClass(): void /** * @group legacy - * @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. */ public function testConfigureGoogleAuthenticatorDisabled(): void { + $this->expectDeprecation('The \'Google\Authenticator\' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0.'); + $this->load(['google_authenticator' => ['enabled' => false]]); $this->assertContainerBuilderHasParameter('sonata.user.google.authenticator.enabled', false); @@ -237,10 +251,11 @@ public function testConfigureGoogleAuthenticatorDisabled(): void /** * @group legacy - * @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. */ public function testConfigureGoogleAuthenticatorEnabled(): void { + $this->expectDeprecation('The \'Google\Authenticator\' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0.'); + $this->load(['google_authenticator' => ['enabled' => true, 'forced_for_role' => ['ROLE_USER'], 'ip_white_list' => ['0.0.0.1'], 'server' => 'bar', ]]); @@ -256,10 +271,11 @@ public function testConfigureGoogleAuthenticatorEnabled(): void /** * @group legacy - * @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. */ public function testMailerConfigParameterIfNotSet(): void { + $this->expectDeprecation('The \'Google\Authenticator\' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0.'); + $this->load(); $this->assertContainerBuilderHasAlias('sonata.user.mailer', 'sonata.user.mailer.default'); @@ -267,10 +283,11 @@ public function testMailerConfigParameterIfNotSet(): void /** * @group legacy - * @expectedDeprecation The 'Google\Authenticator' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0. */ public function testMailerConfigParameter(): void { + $this->expectDeprecation('The \'Google\Authenticator\' namespace is deprecated in sonata-project/GoogleAuthenticator since version 2.1 and will be removed in 3.0.'); + $this->load(['mailer' => 'custom.mailer.service.id']); $this->assertContainerBuilderHasAlias('sonata.user.mailer', 'custom.mailer.service.id');