Update readme about new example
authorwidmogrod <widmogrod@gmail.com>
Wed, 13 Dec 2017 00:14:58 +0000 (01:14 +0100)
committerwidmogrod <widmogrod@gmail.com>
Wed, 13 Dec 2017 00:14:58 +0000 (01:14 +0100)
README.md

index 86c31dc..0682681 100644 (file)
--- a/README.md
+++ b/README.md
@@ -242,10 +242,41 @@ Free monad enables you to do exactly that, and more:
 - Write your own DLS (domain specific language)
 - Decouple implementation from interpretation.
 
+#### Echo program
 Example Free Monad example of `echo program` can be found here:
 - [FreeMonadTest.php](/example/FreeMonadTest.php) - example based on first implementation of Free
 - [Free2MonadTest.php](/example/Free2MonadTest.php) - example based on second implementation of Free, based on [Haskell implementation](https://hackage.haskell.org/package/free-4.12.4/docs/Control-Monad-Free-Class.html)
 
+#### DSL for `BDD` tests
+Example that use `Free Monad` to creates simple DSL (Domain Specific Language) to define BDD type of framework: 
+
+- [Free2BddStyleDSLTest.php](/example/Free2BddStyleDSLTest.php) - example based on second implementation of Free, based on [Haskell implementation](https://hackage.haskell.org/package/free-4.12.4/docs/Control-Monad-Free-Class.html)
+
+```php
+$state = [
+    'productsCount' => 0,
+    'products' => [],
+];
+
+$scenario =
+    Given('Product in cart', $state)
+        ->When("I add product 'coca-cola'")
+        ->When("I add product 'milk'")
+        ->Then("The number of products is '2'");
+
+$result = $scenario->Run([
+    "/^I add product '(.*)'/" => function ($state, $productName) {
+        $state['productsCount'] += 1;
+        $state['products'][] = $productName;
+
+        return $state;
+    },
+], [
+    "/^The number of products is '(\d+)'/" => function ($state, int $expected) {
+        return $state['productsCount'] === $expected;
+    },
+]);
+```
 
 ### Haskell Do Notation in PHP
 **NOTE:** This is experimental feature.