Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

If we have set of scenarios and all the steps are same as each other apart from a few different sections then we can use scenario outlines to prevent duplications.


Controller


/**
* @Route("user")
*/
class UserController extends Controller
{
/**
* @param string $code
*
* @Route("/{code}", requirements={"code"="[A-Z]{2}"})
* @Method({"GET"})
*
* @return Response
*/
public function listAction($code)
{
$countries = [
'GB' => 'Great Britain',
'DE' => 'Germany',
'TR' => 'Turkey'
];

return new Response($countries[$code]);
}
}

Scenario


Feature: Just a test

Scenario Outline: I can get the country name by providing its code
Given I am on "/user/<code>"
Then the response status code should be 200
And the response should contain "<name>"

Examples:
| code | name |
| GB | Great Britain |
| DE | Germany |
| TR | Turkey |

Result


Inanzzz-MBP:football inanzzz$ bin/behat --profile=backend
Feature: Just a test

Scenario Outline: I can get the country name by providing its code
Given I am on "/user/<code>"
Then the response status code should be 200
And the response should contain "<name>"

Examples:
| code | name |
| GB | Great Britain |
| DE | Germany |
| TR | Turkey |

3 scenarios (3 passed)
9 steps (9 passed)
0m5.549s
Inanzzz-MBP:football inanzzz$