Skip to content

Removed superfluous service validation logic #44

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
merged 1 commit into from
Nov 20, 2020
Merged
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
62 changes: 0 additions & 62 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -851,15 +851,11 @@ public function seeNumRecords(int $expectedNum, string $className, array $criter
public function logout()
{
$container = $this->_getContainer();

if ($container->has('security.token_storage')) {
$tokenStorage = $this->grabService('security.token_storage');
$tokenStorage->setToken(null);
}

if (!$container->has('session')) {
$this->fail("Symfony container doesn't have 'session' service");
}
$session = $this->grabService('session');

$sessionName = $session->getName();
Expand Down Expand Up @@ -893,12 +889,6 @@ public function logout()
*/
public function seeInSession(string $attrib, $value = null)
{
$container = $this->_getContainer();

if (!$container->has('session')) {
$this->fail("Symfony container doesn't have 'session' service");
}

$session = $this->grabService('session');

if (!$session->has($attrib)) {
Expand All @@ -925,12 +915,6 @@ public function seeInSession(string $attrib, $value = null)
*/
public function amOnAction(string $action, array $params = [])
{
$container = $this->_getContainer();

if (!$container->has('router')) {
$this->fail("Symfony container doesn't have 'router' service");
}

$router = $this->grabService('router');

$routes = $router->getRouteCollection()->getIterator();
Expand Down Expand Up @@ -964,12 +948,6 @@ public function amOnAction(string $action, array $params = [])
*/
public function seeAuthentication(bool $remembered = false)
{
$container = $this->_getContainer();

if (!$container->has('security.helper')) {
$this->fail("Symfony container doesn't have 'security.helper' service");
}

$security = $this->grabService('security.helper');

$user = $security->getUser();
Expand Down Expand Up @@ -1026,12 +1004,6 @@ public function submitSymfonyForm(string $name, array $fields)
*/
public function seeUserHasRole(string $role)
{
$container = $this->_getContainer();

if (!$container->has('security.helper')) {
$this->fail("Symfony container doesn't have 'security.helper' service");
}

$security = $this->grabService('security.helper');

$user = $security->getUser();
Expand Down Expand Up @@ -1063,12 +1035,6 @@ public function seeUserHasRole(string $role)
*/
public function dontSeeAuthentication(bool $remembered = true)
{
$container = $this->_getContainer();

if (!$container->has('security.helper')) {
$this->fail("Symfony container doesn't have 'security.helper' service");
}

$security = $this->grabService('security.helper');

$role = $remembered ? 'IS_AUTHENTICATED_REMEMBERED' : 'IS_AUTHENTICATED_FULLY';
Expand All @@ -1092,12 +1058,6 @@ public function dontSeeAuthentication(bool $remembered = true)
*/
public function grabParameter(string $name)
{
$container = $this->_getContainer();

if (!$container->has('parameter_bag')) {
$this->fail("Symfony container doesn't have 'parameter_bag' service");
return null;
}
$parameterBag = $this->grabService('parameter_bag');
return $parameterBag->get($name);
}
Expand All @@ -1115,12 +1075,6 @@ public function grabParameter(string $name)
*/
public function seeCurrentActionIs(string $action)
{
$container = $this->_getContainer();

if (!$container->has('router')) {
$this->fail("Symfony container doesn't have 'router' service");
}

$router = $this->grabService('router');

$routes = $router->getRouteCollection()->getIterator();
Expand Down Expand Up @@ -1154,35 +1108,19 @@ public function seeCurrentActionIs(string $action)
*/
public function seeUserPasswordDoesNotNeedRehash(UserInterface $user = null)
{
$container = $this->_getContainer();

if ($user === null) {
if (!$container->has('security.helper')) {
$this->fail("Symfony container doesn't have 'security.helper' service");
}

$security = $this->grabService('security.helper');
if (!$user = $security->getUser()) {
$this->fail('No user found to validate');
}
}

if (!$container->has('security.user_password_encoder.generic')) {
$this->fail("Symfony container doesn't have 'security.user_password_encoder.generic' service");
}

$encoder = $this->grabService('security.user_password_encoder.generic');

$this->assertFalse($encoder->needsRehash($user), 'User password needs rehash');
}

public function amLoggedInAs(UserInterface $user, string $firewallName = 'main', $firewallContext = null)
{
$container = $this->_getContainer();
if (!$container->has('session')) {
$this->fail("Symfony container doesn't have 'session' service");
}

$session = $this->grabService('session');

if ($this->config['guard']) {
Expand Down