Download the PHP package rocketage/behat-shortcode-extension without Composer
On this page you can find all versions of the php package rocketage/behat-shortcode-extension. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rocketage/behat-shortcode-extension
More information about rocketage/behat-shortcode-extension
Files in rocketage/behat-shortcode-extension
Package behat-shortcode-extension
Short Description A Behat extension that allows the use of shortcodes in step strings, tables and pystrings to translate runtime variables into feature files, eg dates.
License MIT
Homepage https://github.com/rocketage/behat_shortcode_extension
Informations about the package behat-shortcode-extension
Behat Shortcode Extension
Description
This extension was created to provide a transparent way to feed runtime values into a feature.
For example my last use-case was verifying a sitemap:
The extension will replace the shortcode [date type=now format=Y-m-d]
with the current date so the step code can perform a direct comparison.
Considerations
You should always seek to avoid having to use this extension!
Firstly, it should be possible to abstract runtime values into the step methods directly, without exposing them in the feature. The above example could easily be rewritten as:
Secondly runtimes values should be sought to be fixed by utilising doubles or mock services for your tests. Then runtime variables can be set in your 'given' steps:
Finally this extension uses reflection to inject the shortcode before the step method is called, which always feels wrong.
However, sometimes it's not always possible or practical to follow the perfect path and it can on occasions make features easier to read and step methods cleaner. Particularly when used in tables.
Installation
Install via composer:
Then add the extension to your behat.yml file:
Configuration
The extension currently only ships with a datetime shortcode, which
effectively wraps the DateTime php class. The shortcode uses the
following format [date type=now format=Y-m-d zone=UTC]
. Because it uses
DateTime you can use all the friendly contructor strings in the type
field like 'yesterday', 'last week', 'next year', etc.
You can add more shortcodes by supplying classnames in the behat.yml file:
The custom classes must return a SimpleShortCode instance via the __invoke magic method: