Eğer elimizde birden fazla scenario varsa, ve de bunların hepsi birkaç tane ufak tefek farklılıklar haricinde birbirlerine benziyorlarsa, kod tekrarlamayı behatın scenario outlines özelliğini kullanarak önleyebiliriz.


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 |

Sonuç


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$