|
13 | 13 | use Symfony\Component\Finder\Finder;
|
14 | 14 | use Symfony\Component\DependencyInjection\ContainerInterface;
|
15 | 15 | use Symfony\Component\Finder\SplFileInfo;
|
| 16 | +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
16 | 17 | use Symfony\Component\VarDumper\Cloner\Data;
|
17 | 18 | use Symfony\Bundle\FrameworkBundle\Console\Application;
|
18 | 19 | use Symfony\Component\Console\Input\ArrayInput;
|
@@ -871,12 +872,53 @@ public function seeInSession($attrib, $value = null)
|
871 | 872 |
|
872 | 873 | $session = $this->grabService('session');
|
873 | 874 |
|
874 |
| - if (! $session->has($attrib)) { |
| 875 | + if (!$session->has($attrib)) { |
875 | 876 | $this->fail("No session attribute with name '$attrib'");
|
876 | 877 | }
|
877 | 878 |
|
878 | 879 | if (null !== $value) {
|
879 | 880 | $this->assertEquals($value, $session->get($attrib));
|
880 | 881 | }
|
881 | 882 | }
|
| 883 | + |
| 884 | + /** |
| 885 | + * Opens web page by action name |
| 886 | + * |
| 887 | + * ``` php |
| 888 | + * <?php |
| 889 | + * $I->amOnAction('PostController::index'); |
| 890 | + * $I->amOnAction('HomeController'); |
| 891 | + * $I->amOnAction('ArticleController', ['slug' => 'lorem-ipsum']); |
| 892 | + * ``` |
| 893 | + * |
| 894 | + * @param string $action |
| 895 | + * @param array $params |
| 896 | + */ |
| 897 | + public function amOnAction($action, $params = []) |
| 898 | + { |
| 899 | + $container = $this->_getContainer(); |
| 900 | + |
| 901 | + if (!$container->has('router')) { |
| 902 | + $this->fail("Symfony container doesn't have 'router' service"); |
| 903 | + return; |
| 904 | + } |
| 905 | + |
| 906 | + $router = $this->grabService('router'); |
| 907 | + |
| 908 | + $routes = $router->getRouteCollection()->getIterator(); |
| 909 | + |
| 910 | + foreach ($routes as $route) { |
| 911 | + $controller = basename($route->getDefault('_controller')); |
| 912 | + if ($controller === $action) { |
| 913 | + $resource = $router->match($route->getPath()); |
| 914 | + $url = $router->generate( |
| 915 | + $resource['_route'], |
| 916 | + $params, |
| 917 | + UrlGeneratorInterface::ABSOLUTE_PATH |
| 918 | + ); |
| 919 | + $this->amOnPage($url); |
| 920 | + return; |
| 921 | + } |
| 922 | + } |
| 923 | + } |
882 | 924 | }
|
0 commit comments