Skip to content

Commit 2ea7ed1

Browse files
authored
Removed superfluous service validation logic (#44)
1 parent b65b2c7 commit 2ea7ed1

File tree

1 file changed

+0
-62
lines changed

1 file changed

+0
-62
lines changed

src/Codeception/Module/Symfony.php

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -851,15 +851,11 @@ public function seeNumRecords(int $expectedNum, string $className, array $criter
851851
public function logout()
852852
{
853853
$container = $this->_getContainer();
854-
855854
if ($container->has('security.token_storage')) {
856855
$tokenStorage = $this->grabService('security.token_storage');
857856
$tokenStorage->setToken(null);
858857
}
859858

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

865861
$sessionName = $session->getName();
@@ -893,12 +889,6 @@ public function logout()
893889
*/
894890
public function seeInSession(string $attrib, $value = null)
895891
{
896-
$container = $this->_getContainer();
897-
898-
if (!$container->has('session')) {
899-
$this->fail("Symfony container doesn't have 'session' service");
900-
}
901-
902892
$session = $this->grabService('session');
903893

904894
if (!$session->has($attrib)) {
@@ -925,12 +915,6 @@ public function seeInSession(string $attrib, $value = null)
925915
*/
926916
public function amOnAction(string $action, array $params = [])
927917
{
928-
$container = $this->_getContainer();
929-
930-
if (!$container->has('router')) {
931-
$this->fail("Symfony container doesn't have 'router' service");
932-
}
933-
934918
$router = $this->grabService('router');
935919

936920
$routes = $router->getRouteCollection()->getIterator();
@@ -964,12 +948,6 @@ public function amOnAction(string $action, array $params = [])
964948
*/
965949
public function seeAuthentication(bool $remembered = false)
966950
{
967-
$container = $this->_getContainer();
968-
969-
if (!$container->has('security.helper')) {
970-
$this->fail("Symfony container doesn't have 'security.helper' service");
971-
}
972-
973951
$security = $this->grabService('security.helper');
974952

975953
$user = $security->getUser();
@@ -1026,12 +1004,6 @@ public function submitSymfonyForm(string $name, array $fields)
10261004
*/
10271005
public function seeUserHasRole(string $role)
10281006
{
1029-
$container = $this->_getContainer();
1030-
1031-
if (!$container->has('security.helper')) {
1032-
$this->fail("Symfony container doesn't have 'security.helper' service");
1033-
}
1034-
10351007
$security = $this->grabService('security.helper');
10361008

10371009
$user = $security->getUser();
@@ -1063,12 +1035,6 @@ public function seeUserHasRole(string $role)
10631035
*/
10641036
public function dontSeeAuthentication(bool $remembered = true)
10651037
{
1066-
$container = $this->_getContainer();
1067-
1068-
if (!$container->has('security.helper')) {
1069-
$this->fail("Symfony container doesn't have 'security.helper' service");
1070-
}
1071-
10721038
$security = $this->grabService('security.helper');
10731039

10741040
$role = $remembered ? 'IS_AUTHENTICATED_REMEMBERED' : 'IS_AUTHENTICATED_FULLY';
@@ -1092,12 +1058,6 @@ public function dontSeeAuthentication(bool $remembered = true)
10921058
*/
10931059
public function grabParameter(string $name)
10941060
{
1095-
$container = $this->_getContainer();
1096-
1097-
if (!$container->has('parameter_bag')) {
1098-
$this->fail("Symfony container doesn't have 'parameter_bag' service");
1099-
return null;
1100-
}
11011061
$parameterBag = $this->grabService('parameter_bag');
11021062
return $parameterBag->get($name);
11031063
}
@@ -1115,12 +1075,6 @@ public function grabParameter(string $name)
11151075
*/
11161076
public function seeCurrentActionIs(string $action)
11171077
{
1118-
$container = $this->_getContainer();
1119-
1120-
if (!$container->has('router')) {
1121-
$this->fail("Symfony container doesn't have 'router' service");
1122-
}
1123-
11241078
$router = $this->grabService('router');
11251079

11261080
$routes = $router->getRouteCollection()->getIterator();
@@ -1154,35 +1108,19 @@ public function seeCurrentActionIs(string $action)
11541108
*/
11551109
public function seeUserPasswordDoesNotNeedRehash(UserInterface $user = null)
11561110
{
1157-
$container = $this->_getContainer();
1158-
11591111
if ($user === null) {
1160-
if (!$container->has('security.helper')) {
1161-
$this->fail("Symfony container doesn't have 'security.helper' service");
1162-
}
1163-
11641112
$security = $this->grabService('security.helper');
11651113
if (!$user = $security->getUser()) {
11661114
$this->fail('No user found to validate');
11671115
}
11681116
}
1169-
1170-
if (!$container->has('security.user_password_encoder.generic')) {
1171-
$this->fail("Symfony container doesn't have 'security.user_password_encoder.generic' service");
1172-
}
1173-
11741117
$encoder = $this->grabService('security.user_password_encoder.generic');
11751118

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

11791122
public function amLoggedInAs(UserInterface $user, string $firewallName = 'main', $firewallContext = null)
11801123
{
1181-
$container = $this->_getContainer();
1182-
if (!$container->has('session')) {
1183-
$this->fail("Symfony container doesn't have 'session' service");
1184-
}
1185-
11861124
$session = $this->grabService('session');
11871125

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

0 commit comments

Comments
 (0)