Skip to content

Commit

Permalink
Symfony 4.3 deprecated free
Browse files Browse the repository at this point in the history
fix Symfony 4.3 deprecation warnings
  • Loading branch information
Klapaudius committed Sep 13, 2019
1 parent d12b2f0 commit b7db007
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 64 deletions.
32 changes: 14 additions & 18 deletions Controller/AuthorizeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use FOS\OAuthServerBundle\Model\ClientManagerInterface;
use OAuth2\OAuth2;
use OAuth2\OAuth2ServerException;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -31,6 +30,7 @@
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\User\UserInterface;
use Twig\Environment;

/**
* Controller handling basic authorization.
Expand Down Expand Up @@ -65,9 +65,9 @@ class AuthorizeController
private $oAuth2Server;

/**
* @var EngineInterface
* @var Environment
*/
private $templating;
private $twig;

/**
* @var RequestStack
Expand All @@ -89,11 +89,6 @@ class AuthorizeController
*/
private $clientManager;

/**
* @var string
*/
private $templateEngineType;

/**
* @var EventDispatcherInterface
*/
Expand All @@ -109,7 +104,7 @@ class AuthorizeController
* @param Form $authorizeForm
* @param AuthorizeFormHandler $authorizeFormHandler
* @param OAuth2 $oAuth2Server
* @param EngineInterface $templating
* @param Environment $twig
* @param TokenStorageInterface $tokenStorage
* @param UrlGeneratorInterface $router
* @param ClientManagerInterface $clientManager
Expand All @@ -122,20 +117,19 @@ public function __construct(
Form $authorizeForm,
AuthorizeFormHandler $authorizeFormHandler,
OAuth2 $oAuth2Server,
EngineInterface $templating,
Environment $twig,
TokenStorageInterface $tokenStorage,
UrlGeneratorInterface $router,
ClientManagerInterface $clientManager,
EventDispatcherInterface $eventDispatcher,
SessionInterface $session = null,
$templateEngineType = 'twig'
SessionInterface $session = null
) {
$this->requestStack = $requestStack;
$this->session = $session;
$this->authorizeForm = $authorizeForm;
$this->authorizeFormHandler = $authorizeFormHandler;
$this->oAuth2Server = $oAuth2Server;
$this->templating = $templating;
$this->twig = $twig;
$this->tokenStorage = $tokenStorage;
$this->router = $router;
$this->clientManager = $clientManager;
Expand Down Expand Up @@ -183,7 +177,7 @@ public function authorizeAction(Request $request)
'client' => $this->getClient(),
];

return $this->renderAuthorize($data, $this->templating, $this->templateEngineType);
return $this->renderAuthorize($data);
}

/**
Expand Down Expand Up @@ -261,16 +255,18 @@ protected function getClient()
/**
* @throws \RuntimeException
*/
protected function renderAuthorize(array $data, EngineInterface $engine, string $engineType): Response
protected function renderAuthorize(array $data): Response
{
return $engine->renderResponse(
'@FOSOAuthServer/Authorize/authorize.html.'.$engineType,
$respone = $engine->twig->renderResponse(
'@FOSOAuthServer/Authorize/authorize.html.twig',
$data
);

return $response instanceof Response ? $response : new Response($response);
}

/**
* @return null|Request
* @return Request|null
*/
private function getCurrentRequest()
{
Expand Down
15 changes: 0 additions & 15 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public function getConfigTreeBuilder()

$this->addAuthorizeSection($rootNode);
$this->addServiceSection($rootNode);
$this->addTemplateSection($rootNode);

return $treeBuilder;
}
Expand Down Expand Up @@ -142,18 +141,4 @@ private function addServiceSection(ArrayNodeDefinition $node)
->end()
;
}

private function addTemplateSection(ArrayNodeDefinition $node)
{
$node
->children()
->arrayNode('template')
->addDefaultsIfNotSet()
->children()
->scalarNode('engine')->defaultValue('twig')->end()
->end()
->end()
->end()
;
}
}
2 changes: 1 addition & 1 deletion Form/Handler/AuthorizeFormHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function process()
}

$this->form->handleRequest($request);
if (!$this->form->isValid()) {
if ( $this->form->isSubmitted() && ! $this->form->isValid()) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions Model/ClientManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public function createClient();
public function getClass();

/**
* @return null|ClientInterface
* @return ClientInterface|null
*/
public function findClientBy(array $criteria);

/**
* @param mixed $publicId
*
* @return null|ClientInterface
* @return ClientInterface|null
*/
public function findClientByPublicId($publicId);

Expand Down
3 changes: 1 addition & 2 deletions Resources/config/authorize.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
<argument type="service" id="fos_oauth_server.authorize.form" />
<argument type="service" id="fos_oauth_server.authorize.form.handler" />
<argument type="service" id="fos_oauth_server.server" />
<argument type="service" id="templating" />
<argument type="service" id="twig" />
<argument type="service" id="security.token_storage" />
<argument type="service" id="router" />
<argument type="service" id="fos_oauth_server.client_manager" />
<argument type="service" id="event_dispatcher" />
<argument type="service" id="session" on-invalid="null" />
<argument>%fos_oauth_server.template.engine%</argument>
</service>
</services>

Expand Down
2 changes: 0 additions & 2 deletions Resources/doc/configuration_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ fos_oauth_server:

# Enforce state to be passed in authorization (see RFC 6749, section 10.12)
#enforce_state: true or false
template:
engine: twig
```

[Back to index](index.md)
2 changes: 1 addition & 1 deletion Security/Authentication/Provider/OAuthProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(UserProviderInterface $userProvider, OAuth2 $serverS
/**
* @param OAuthToken&TokenInterface $token
*
* @return null|OAuthToken
* @return OAuthToken|null
*/
public function authenticate(TokenInterface $token)
{
Expand Down
4 changes: 2 additions & 2 deletions Storage/OAuthStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class OAuthStorage implements IOAuth2RefreshTokens, IOAuth2GrantUser, IOAuth2Gra
* @param AccessTokenManagerInterface $accessTokenManager
* @param RefreshTokenManagerInterface $refreshTokenManager
* @param AuthCodeManagerInterface $authCodeManager
* @param null|UserProviderInterface $userProvider
* @param null|EncoderFactoryInterface $encoderFactory
* @param UserProviderInterface|null $userProvider
* @param EncoderFactoryInterface|null $encoderFactory
*/
public function __construct(ClientManagerInterface $clientManager, AccessTokenManagerInterface $accessTokenManager,
RefreshTokenManagerInterface $refreshTokenManager, AuthCodeManagerInterface $authCodeManager,
Expand Down
26 changes: 10 additions & 16 deletions Tests/Controller/AuthorizeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use FOS\OAuthServerBundle\Model\ClientInterface;
use FOS\OAuthServerBundle\Model\ClientManagerInterface;
use OAuth2\OAuth2;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormView;
Expand All @@ -33,6 +32,7 @@
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\User\UserInterface;
use Twig\Environment;

class AuthorizeControllerTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -62,9 +62,9 @@ class AuthorizeControllerTest extends \PHPUnit\Framework\TestCase
protected $oAuth2Server;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|EngineInterface
* @var \PHPUnit_Framework_MockObject_MockObject|Environment
*/
protected $templateEngine;
protected $twig;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|TokenStorageInterface
Expand All @@ -86,11 +86,6 @@ class AuthorizeControllerTest extends \PHPUnit\Framework\TestCase
*/
protected $eventDispatcher;

/**
* @var string
*/
protected $templateEngineType;

/**
* @var AuthorizeController
*/
Expand Down Expand Up @@ -149,7 +144,7 @@ public function setUp()
->disableOriginalConstructor()
->getMock()
;
$this->templateEngine = $this->getMockBuilder(EngineInterface::class)
$this->twig = $this->getMockBuilder(Environment::class)
->disableOriginalConstructor()
->getMock()
;
Expand All @@ -173,20 +168,19 @@ public function setUp()
->disableOriginalConstructor()
->getMock()
;
$this->templateEngineType = 'twig';

$this->instance = new AuthorizeController(
$this->requestStack,
$this->form,
$this->authorizeFormHandler,
$this->oAuth2Server,
$this->templateEngine,
$this->twig,
$this->tokenStorage,
$this->router,
$this->clientManager,
$this->eventDispatcher,
$this->session,
$this->templateEngineType
$this->twigType
);

/** @var \PHPUnit_Framework_MockObject_MockObject&Request $request */
Expand Down Expand Up @@ -309,9 +303,9 @@ public function testAuthorizeActionWillRenderTemplate()

$response = new Response();

$this->templateEngine
$this->twig
->expects($this->at(0))
->method('renderResponse')
->method('render')
->with(
'@FOSOAuthServer/Authorize/authorize.html.twig',
[
Expand Down Expand Up @@ -468,9 +462,9 @@ public function testAuthorizeActionWillEnsureLogout()

$response = new Response();

$this->templateEngine
$this->twig
->expects($this->at(0))
->method('renderResponse')
->method('render')
->with(
'@FOSOAuthServer/Authorize/authorize.html.twig',
[
Expand Down
14 changes: 14 additions & 0 deletions Tests/Form/Handler/AuthorizeFormHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,13 @@ public function testProcessWillHandleRequestOnPost()
->willReturn($this->form)
;

$this->form
->expects($this->once())
->method('isSubmitted')
->with()
->willReturn(true)
;

$this->form
->expects($this->once())
->method('isValid')
Expand Down Expand Up @@ -412,6 +419,13 @@ public function testProcessWillHandleRequestOnPostAndWillProcessDataIfFormIsVali
->willReturn($this->form)
;

$this->form
->expects($this->once())
->method('isSubmitted')
->with()
->willReturn(true)
;

$this->form
->expects($this->once())
->method('isValid')
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
abstract class TestCase extends WebTestCase
{
/**
* @var null|KernelInterface
* @var KernelInterface|null
*/
protected static $kernel;

Expand Down
2 changes: 0 additions & 2 deletions Tests/Functional/config/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
framework:
templating:
engines: ["twig"]
form: ~
secret: test
router:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"friendsofsymfony/oauth2-php": "~1.1",
"symfony/dependency-injection": "~3.0|~4.0",
"symfony/framework-bundle": "~3.0|~4.0",
"symfony/security-bundle": "~3.0|~4.0"
"symfony/security-bundle": "~3.0|~4.0",
"symfony/twig-bundle": "~3.0|^4.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "~1.0",
Expand All @@ -37,7 +38,6 @@
"symfony/form": "~3.0|~4.0",
"symfony/phpunit-bridge": "~3.0|~4.0",
"symfony/templating": "~3.0|~4.0",
"symfony/twig-bundle": "~3.0|^4.0",
"symfony/yaml": "~3.0|~4.0",
"willdurand/propel-typehintable-behavior": "~1.0"
},
Expand Down

0 comments on commit b7db007

Please sign in to comment.