Skip to content

Commit

Permalink
Use ExpectDeprecationTrait::expectDeprecation() instead of deprecat…
Browse files Browse the repository at this point in the history
…ed annotation `@expectedDeprecation`
  • Loading branch information
phansys authored and jordisala1991 committed Jul 28, 2020
1 parent 611e254 commit 409502c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 17 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
11 changes: 10 additions & 1 deletion tests/Controller/AdminResettingControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
{
Expand All @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion tests/Controller/AdminSecurityControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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();
}
Expand Down
45 changes: 31 additions & 14 deletions tests/DependencyInjection/SonataUserExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +35,8 @@
*/
final class SonataUserExtensionTest extends AbstractExtensionTestCase
{
use ExpectDeprecationTrait;

/**
* {@inheritdoc}
*/
Expand All @@ -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(
Expand Down Expand Up @@ -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
{
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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' => [
Expand All @@ -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,
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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', ]]);

Expand All @@ -256,21 +271,23 @@ 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');
}

/**
* @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');
Expand Down

0 comments on commit 409502c

Please sign in to comment.