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
15 changes: 15 additions & 0 deletions documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,21 @@ Authenticates user for HTTP_AUTH
* `param` $password


### amOnAction

Opens web page by action name

``` php
<?php
$I->amOnAction('PostController::index');
$I->amOnAction('HomeController');
$I->amOnAction('ArticleController', ['slug' => 'lorem-ipsum']);
```

* `param string` $action
* `param array` $params


### amOnPage

Opens the page for the given relative URI.
Expand Down
42 changes: 42 additions & 0 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
Expand Down Expand Up @@ -770,4 +771,45 @@ private function getPossibleKernelClasses()

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

/**
* Opens web page by action name
*
* ``` php
* <?php
* $I->amOnAction('PostController::index');
* $I->amOnAction('HomeController');
* $I->amOnAction('ArticleController', ['slug' => 'lorem-ipsum']);
* ```
*
* @param string $action
* @param array $params
*/
public function amOnAction($action, $params = [])
{
$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) {
$resource = $router->match($route->getPath());
$url = $router->generate(
$resource['_route'],
$params,
UrlGeneratorInterface::ABSOLUTE_PATH
);
$this->amOnPage($url);
return;
}
}
}
}