Skip to content

[SecurityBundle] Rename FirewallContext#getContext() #20417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions UPGRADE-3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ Security

* The `RoleInterface` has been deprecated. Extend the `Symfony\Component\Security\Core\Role\Role`
class in your custom role implementations instead.

SecurityBundle
--------------

* The `FirewallContext::getContext()` method has been deprecated and will be removed in 4.0.
Use the `getListeners()` method instead.
5 changes: 5 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ FrameworkBundle
`serializer.mapping.cache.apc` and `serializer.mapping.cache.doctrine.apc`
have been removed. APCu should now be automatically used when available.

SecurityBundle
--------------

* The `FirewallContext::getContext()` method has been removed, use the `getListeners()` method instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this line could be wrapped to be in line with the other lines in the file


HttpFoundation
---------------

Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Bundle/SecurityBundle/Security/FirewallContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ public function getConfig()
return $this->config;
}

/**
* @deprecated since version 3.3, will be removed in 4.0. Use {@link getListeners()} instead.
*/
public function getContext()
{
@trigger_error(sprintf('Method %s() is deprecated since version 3.3 and will be removed in 4.0. Use %s::getListeners() instead.', __METHOD__, __CLASS__), E_USER_DEPRECATED);

return $this->getListeners();
}

public function getListeners()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit confusing considering that this returns both an array of listeners and an exception listener. getListeners may be expected to return just $this->listeners

{
return array($this->listeners, $this->exceptionListener);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getListeners(Request $request)
return array(array(), null);
}

return $context->getContext();
return $context->getListeners();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ class FirewallContextTest extends \PHPUnit_Framework_TestCase
public function testGetters()
{
$config = new FirewallConfig('main', 'user_checker', 'request_matcher');

$exceptionListener = $this
->getMockBuilder(ExceptionListener::class)
->disableOriginalConstructor()
->getMock();

$exceptionListener = $this->getExceptionListenerMock();
$listeners = array(
$this
->getMockBuilder(ListenerInterface::class)
Expand All @@ -36,7 +31,25 @@ public function testGetters()

$context = new FirewallContext($listeners, $exceptionListener, $config);

$this->assertEquals(array($listeners, $exceptionListener), $context->getContext());
$this->assertEquals(array($listeners, $exceptionListener), $context->getListeners());
$this->assertEquals($config, $context->getConfig());
}

/**
* @expectedDeprecation Method Symfony\Bundle\SecurityBundle\Security\FirewallContext::getContext() is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Bundle\SecurityBundle\Security\FirewallContext::getListeners() instead.
* @group legacy
*/
public function testGetContextTriggersDeprecation()
{
(new FirewallContext(array(), $this->getExceptionListenerMock(), new FirewallConfig('main', 'request_matcher', 'user_checker')))
->getContext();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should also assert the return value, to ensure that the BC layer works fine (returning null would make your test pass, but the class would be broken)

}

private function getExceptionListenerMock()
{
return $this
->getMockBuilder(ExceptionListener::class)
->disableOriginalConstructor()
->getMock();
}
}