These are chat archives for Behat/Behat

8th
Sep 2014
Carlos Goce
@carlosgoce
Sep 08 2014 08:04 UTC
Hello, there is someway to pass a null value? I tried with the '~' character but it's not working
Tried with this transformation /* @Transform /^(null)$/ but it's not working neither. It is because it's inside a TableNode?
Maxime Veber
@Nek-
Sep 08 2014 08:37 UTC
@carlosgoce explain your problem. Your message make no sense without context.
Carlos Goce
@carlosgoce
Sep 08 2014 08:53 UTC
Imagine this Scenario:
Scenario: Save all products from file
Given the following products:
| code | name |
| 1 | null |
Well, null is the string 'null', not a real null value.
Can I make it null somehow?
I mean, when you get the data with the DableNode
*TableNode
Maxime Veber
@Nek-
Sep 08 2014 08:55 UTC
Simply by not setting it in your TableNode I guess
Carlos Goce
@carlosgoce
Sep 08 2014 08:57 UTC
In that case an empty string is passed
(sorry for my english if is wrong)
Maxime Veber
@Nek-
Sep 08 2014 08:58 UTC
You're using FriendlyContext ?
(weird that you give an empty string, if it's for testing your object it's not the job of behat)
Carlos Goce
@carlosgoce
Sep 08 2014 09:07 UTC
Just the default implements SnippetAcceptingContext
This is not the real Scenario, it is just an example
Maxime Veber
@Nek-
Sep 08 2014 09:09 UTC
So you can easily use $name = $name !== 'null' ?: null;
Ciaran McNulty
@ciaranmcnulty
Sep 08 2014 09:12 UTC
@carlosgoce you can use a table transform to do what you want
Ciaran McNulty
@ciaranmcnulty
Sep 08 2014 09:21 UTC
e.g. in your example you'd use @Transform table:code,name
that function would receive the TableNode and return... something. I guess an array?
Then your step definition would type hint array instead of TableNode and get the processed array
  • any other steps that use that same table format
Params from Gherkin are always strings
Carlos Goce
@carlosgoce
Sep 08 2014 09:30 UTC
Thank you. I am going to try
Ciaran McNulty
@ciaranmcnulty
Sep 08 2014 09:55 UTC
There is a PR for @Transform row:code,name that avoids you having to write the loop but it's not been merged yet, might be in 3.1