Skip to content

Commit f7449fb

Browse files
TavoNiievezNaktibalda
authored andcommitted
Added seeCurrentActionIs function
1 parent 321ef5e commit f7449fb

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

documentation.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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

953966
Checks that current url matches route.

src/Codeception/Module/Symfony.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)