These are chat archives for Behat/Behat

8th
Feb 2017
Roel Monnens
@roelmonnens_twitter
Feb 08 2017 14:42 UTC

Hello, when describing a scenario with entities. Should you refer to those entities by their identifiers or just as the last inserted?
Title is just a variable for the folder and the theme.
Id is the real identifier of those entities.

What’s the best way to write a scenario
Example 1 (refering to last inserted):

Scenario: Add a theme to an empty folder
    Given I am a teacher
    And I have a folder with title "December"
    And I have a theme with title "Kerstmis" and themeImage "Bluebox"
    When I add my theme to my folder
    Then my folder should contain my theme
    And my theme should have an position of "1" within this folder

Example 2 (refering to Ids):

Scenario: Add a theme to an empty folder
    Given I am a teacher
    And I have a folder with id1and title "December"
    And I have a theme with id11and title "Kerstmis" and themeImage "Bluebox"
    When I add theme “11to folder “1"
    Then folder “1" should contain theme “11"
    And theme “11” should have an position of "1" within  folder “1"
Bertrand Dunogier
@bdunogier
Feb 08 2017 14:43 UTC
I'd say that you will refer to the ID if it matters for the scenario ?
Roel Monnens
@roelmonnens_twitter
Feb 08 2017 14:49 UTC

so If you look at the example of modelling by example blog (http://stakeholderwhisperer.com/posts/2014/10/introducing-modelling-by-example)

Scenario: Getting the delivery cost for a single product under £10
  Given a product named "White Marker" and priced £5 was added to the catalogue
  When I add the "White Marker" product from the catalogue to the picked up basket
  Then the overall basket price should be £9

The product Identifier in this case would be the name?

Radosław Kłak
@rklak
Feb 08 2017 14:56 UTC
No, because in this scenario we dont know anything about identifier because ID is a matter of implementation. You can write a solution for this in many ways - with or without ID.
Roel Monnens
@roelmonnens_twitter
Feb 08 2017 14:59 UTC

but further in the blogpost he does this.

$basket->addProductFromCatalogue($name, $this->catalogue);

With this code he will search for a product in the catalogue with $name. If it is not an identifier how can he be certain that not two products are added to the basket?

if you have two products with the same name?
Bertrand Dunogier
@bdunogier
Feb 08 2017 15:01 UTC
As I see it, the "name" doesn't matter that much. It is more of a descriptive element in the sentence. You could use "White Marker somesha1here" under the hood.
I personally wouldn't specify the product's name at all, as it doesn't matter at all in this scenario (what matters is the price, and the fact that there is one product in the basket).