Skip to content
Closed
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
13 changes: 13 additions & 0 deletions documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,19 @@ $I->seeCookie('PHPSESSID');
* `param array` $params


### seeCurrentActionIs

Checks that current page matches action

``` php
<?php
$I->seeCurrentActionIs('PostController::index');
$I->seeCurrentActionIs('HomeController');
```

* `param string` $action


### seeCurrentRouteIs

Checks that current url matches route.
Expand Down
37 changes: 37 additions & 0 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -770,4 +770,41 @@ private function getPossibleKernelClasses()

return [$this->config['kernel_class']];
}

/**
* Checks that current page matches action
*
* ``` php
* <?php
* $I->seeCurrentActionIs('PostController::index');
* $I->seeCurrentActionIs('HomeController');
* ```
*
* @param string $action
*/
public function seeCurrentActionIs($action)
{
$container = $this->_getContainer();

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

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

$routes = $router->getRouteCollection()->getIterator();

foreach ($routes as $route) {
$controller = basename($route->getDefault('_controller'));
if ($controller === $action) {
$request = $this->client->getRequest();
$currentAction = basename($request->attributes->get('_controller'));

$this->assertEquals($currentAction, $action, "Current action is '$currentAction'.");
return;
}
}
$this->fail("Action '$action' does not exist");
}
}