File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -948,6 +948,19 @@ $I->seeCookie('PHPSESSID');
948948 * ` param array ` $params
949949
950950
951+ ### seeCurrentActionIs
952+
953+ Checks that current page matches action
954+
955+ ``` php
956+ <?php
957+ $I->seeCurrentActionIs('PostController::index');
958+ $I->seeCurrentActionIs('HomeController');
959+ ```
960+
961+ * ` param string ` $action
962+
963+
951964### seeCurrentRouteIs
952965
953966Checks that current url matches route.
Original file line number Diff line number Diff line change @@ -1032,4 +1032,41 @@ public function dontSeeAuthentication($remembered = true)
10321032 'There is an user authenticated '
10331033 );
10341034 }
1035+
1036+ /**
1037+ * Checks that current page matches action
1038+ *
1039+ * ``` php
1040+ * <?php
1041+ * $I->seeCurrentActionIs('PostController::index');
1042+ * $I->seeCurrentActionIs('HomeController');
1043+ * ```
1044+ *
1045+ * @param string $action
1046+ */
1047+ public function seeCurrentActionIs ($ action )
1048+ {
1049+ $ container = $ this ->_getContainer ();
1050+
1051+ if (!$ container ->has ('router ' )) {
1052+ $ this ->fail ("Symfony container doesn't have 'router' service " );
1053+ return ;
1054+ }
1055+
1056+ $ router = $ this ->grabService ('router ' );
1057+
1058+ $ routes = $ router ->getRouteCollection ()->getIterator ();
1059+
1060+ foreach ($ routes as $ route ) {
1061+ $ controller = basename ($ route ->getDefault ('_controller ' ));
1062+ if ($ controller === $ action ) {
1063+ $ request = $ this ->client ->getRequest ();
1064+ $ currentAction = basename ($ request ->attributes ->get ('_controller ' ));
1065+
1066+ $ this ->assertEquals ($ currentAction , $ action , "Current action is ' $ currentAction'. " );
1067+ return ;
1068+ }
1069+ }
1070+ $ this ->fail ("Action ' $ action' does not exist " );
1071+ }
10351072}
You can’t perform that action at this time.
0 commit comments