I’ve got a PHP-based library that takes phone numbers and translates them into locally appropriate display formats. (E.g., the American phone number 14083493300 becomes 1 (408) 349-4993)
The code is part of our office telephone system, which has a physical server in every office. Each server has a set of constants defined that govern what local customs the library should use: country code, outside line prefix, local extension length, etc. In production this hasn’t caused any problems, since these constants never change at run time.
But the library is kind of unwieldy, and we’re asking non-devs to edit it, so I want to introduce BDD so we can document what it’s supposed to do and watch out for regressions.
The first test set using Behat works like a charm; set up all the constants for one region, run a bucket of tests, good. But when Behat loads the next .feature file, which describes a different region with different values for the same constants, PHP barfs.
I can just manually run Behat separately on each .feature file, but is there a better workaround? Something that gets Behat to clean out constant-space before loading the next Feature file?
It’s not possible to re-define a constant in PHP. Since all the features are run within one PHP process you cannot really do it one pass.
Solution might be running them separately as you suggested yourself. It should be fairly easy to implement a script which would find all the feature files and run them.
You could also try to run code which defines constants as a separate process with system(), capture it’s output with ob_start()+ob_get_contents() and inspect it in your step(s). Of course it depends on how your code is built.