Moving away from legacy code with BDD
-
Upload
konstantin-kudryashov -
Category
Technology
-
view
8.034 -
download
7
description
Transcript of Moving away from legacy code with BDD
![Page 1: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/1.jpg)
Moving away from legacy code
with BDD
![Page 2: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/2.jpg)
Who?!
BDD Evangelist !
BDD Practice Manager @Inviqa !
Creator of Behat, Mink, PhpSpec2, Prophecy
!Contributor to Symfony2, Composer
!Host of the “Elephant in the Room”
podcast
![Page 3: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/3.jpg)
This talk is about
• Solving purely technical “TCIAM” problem with agile business analysis and discovery processes
• Building a delivery strategy on the idea of constant change
• Real-life experience
![Page 4: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/4.jpg)
This talk is not about
• Greenfield projects
• Solutions for everyone
• How to write code
![Page 5: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/5.jpg)
This talk is not about
• Greenfield projects
• Maintenance-mode projects
• Solutions for everyone
• How to write code (well, mostly)
![Page 6: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/6.jpg)
Legacy projects
![Page 7: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/7.jpg)
How most developers see their next project
![Page 8: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/8.jpg)
My next project
![Page 9: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/9.jpg)
My next project
His actual next project
![Page 10: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/10.jpg)
Agile, TDD, BDD, General QA, etc…
// TODO: refactor this later
![Page 11: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/11.jpg)
Is it really that bad?
![Page 12: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/12.jpg)
If the project can afford at least one full-time specialist on a payroll that whines how horrible this project is, then surely it did something right.
![Page 13: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/13.jpg)
// TODO: refactor this later
![Page 14: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/14.jpg)
// TODO: refactor this later
![Page 15: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/15.jpg)
// TODO: refactor this later
![Page 16: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/16.jpg)
This world is full of brilliant projects that nobody wants to whine about. Sadly, it’s often simply because there’s no one left to pay for that.
![Page 17: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/17.jpg)
The truth is: You deliver value!
Just not as effectively as you could
![Page 18: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/18.jpg)
// TODO: refactor this later
Agile, TDD, BDD, General QA, etc…
![Page 19: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/19.jpg)
How?
![Page 20: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/20.jpg)
Three options
1. Rewrite an entire application using “the right way”
2. Do functional refactoring
3. Do business-oriented rewrite using “BDD pipeline”
![Page 21: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/21.jpg)
#1: Full Rewrite
![Page 22: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/22.jpg)
#1: Full Rewrite
• Scrum / Kanban
• TDD / BDD / DDD / Pair-programming
• New everything
• Mirroring functionality
![Page 23: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/23.jpg)
#1: Income
![Page 24: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/24.jpg)
6 Months later…
![Page 25: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/25.jpg)
#1: Almost there…
![Page 26: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/26.jpg)
#1: Full Rewrite
Just spaghetti, please: 4 man years
Full London meal (TDD, BDD, Agile, QA): ??? man years
![Page 27: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/27.jpg)
#2: FUNCTIONAL Refactoring
![Page 28: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/28.jpg)
#2: Functional Refactoring
• Blackbox testing
• New routing
• New templating system
• Migration of model layer (MySQL -> Mongo)
![Page 29: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/29.jpg)
#2: Income
![Page 30: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/30.jpg)
6 Months later…
![Page 31: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/31.jpg)
#2: Ta-da!!!
![Page 32: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/32.jpg)
– Your client. (most likely)
“Exactly what did you do here?”
![Page 33: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/33.jpg)
#3: BDD PIPELINEAKA Business-Oriented rewrite
![Page 34: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/34.jpg)
Why do some legacy projects suck?
![Page 35: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/35.jpg)
Cost
Time
Because of the cost of change
![Page 36: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/36.jpg)
… Of change where?
![Page 37: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/37.jpg)
Why do applications change?
![Page 38: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/38.jpg)
Welcome to the wonderland
of Agile Business Analysis
![Page 39: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/39.jpg)
Questionnaire
1. What is the goal and minimal valuable product?
2. What is the minimal set of features to support it?
3. Which features are more likely to change?
4. How fully those features should be implemented?
5. How to avoid gold plating?
![Page 40: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/40.jpg)
“BDD Pipeline”
1. Impact Mapping
2. Feature Mapping
3. Prioritisation
4. Example Workshop
5. Full-stack BDD
![Page 41: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/41.jpg)
1. What is the Goal & minimal valuable product?
Impact Mapping
![Page 42: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/42.jpg)
– Gojko Adzic
“Impact mapping is a strategic planning technique that prevents organisations from getting lost
while building products and delivering projects, by clearly communicating assumptions, helping teams align their activities with overall business objectives and make better roadmap decisions.”
![Page 43: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/43.jpg)
Four levels of Impact Map
1. Why? are we doing all this (rewrite)? What is the goal we’re trying to achieve?
2. Who? will be impacted by it?
3. How? can they help us to achieve the goal?
4. What? can we do to support them?
![Page 44: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/44.jpg)
![Page 45: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/45.jpg)
MVP
![Page 47: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/47.jpg)
2. What is the minimal set of features to support it?
Feature Mapping
![Page 48: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/48.jpg)
– Marcello Duarte
“Feature mapping is a backlog grooming technique. It is a graphical process which helps teams in finding features that are necessary to
support discovered MVP”
![Page 49: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/49.jpg)
Three levels of feature map
1. What? is the minimal marketable feature?
2. Who? will be impacted by this feature?
3. What? particular parts of this feature do they need to create this impact?
![Page 50: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/50.jpg)
![Page 51: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/51.jpg)
Product Backlog
![Page 52: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/52.jpg)
![Page 53: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/53.jpg)
In order to buy more products As a customer I need to have a product autocompletion in the search field
![Page 54: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/54.jpg)
3. Which features are more likely to change?
Prioritisation workshop
![Page 55: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/55.jpg)
In order to maintain my shopping history As a site visitor I need to be able to register on this site
![Page 56: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/56.jpg)
In order to maintain my shopping history As a site visitor I need to be able to register on this site
benefit !actor
![Page 57: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/57.jpg)
SELECT s.* FROM backlog as s ORDER BY s.role, s.benefit LIMIT 25
![Page 58: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/58.jpg)
4. How fully those features should be implemented?
Example workshops
![Page 59: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/59.jpg)
Three layers of a User-Story
• Business rule(s)
• Communication
• Acceptance criteria
![Page 60: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/60.jpg)
Three layers of a User-Story
• Business rule(s) == Acceptance criteria
• Communication
![Page 61: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/61.jpg)
Three layers of a User-Story
• Business rule(s) == Acceptance criteria
• Communication == Examples
![Page 62: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/62.jpg)
Three layers of a User-Story
• Business rule(s)
• Communication == Examples == Acceptance criteria
![Page 63: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/63.jpg)
in order to maintain my shopping history as a site visitor i need to be able to register on this site
Feature: registration
![Page 64: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/64.jpg)
in order to maintain my shopping history as a site visitor i need to be able to register on this site
Feature: registration
Scenario: Successful registration when visitor provides all the required info
![Page 65: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/65.jpg)
in order to maintain my shopping history as a site visitor i need to be able to register on this site
Feature: registration
Scenario: Successful registration when visitor provides all the required info
Scenario: Unable to register when visitor misses required info
![Page 66: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/66.jpg)
in order to maintain my shopping history as a site visitor i need to be able to register on this site
Feature: registration
Scenario: Successful registration when visitor provides all the required info
Scenario: Unable to register when visitor misses required info
Scenario: ...
![Page 67: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/67.jpg)
Scenario: ...
Scenario: ...
Scenario: ...
Scenario: ...
in order to maintain my shopping history as a site visitor i need to be able to register on this site
Feature: registration
Scenario: Successful registration when visitor provides all the required info
Scenario: Unable to register when visitor misses required info
Scenario: ...
![Page 68: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/68.jpg)
in order to maintain my shopping history as a site visitor i need to be able to register on this site
Feature: registration
Scenario: Successful registration when visitor provides all the required info
Given I am on the homepage When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
![Page 69: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/69.jpg)
5. How to avoid gold plating?
Delivery
![Page 70: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/70.jpg)
Architecture
![Page 71: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/71.jpg)
ArchitectureHTTP layering
![Page 72: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/72.jpg)
Legacy system
Infrastructure
[GET] /products
![Page 73: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/73.jpg)
Legacy system
Infrastructure
[GET] /products
[GET] /products/123
![Page 74: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/74.jpg)
Legacy system
Infrastructure
[GET] /products
[GET] /products/123
New system
![Page 75: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/75.jpg)
Legacy system
Infrastructure
[GET] /products
[GET] /products/123
New system
New system
![Page 76: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/76.jpg)
Implementation
![Page 77: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/77.jpg)
ImplementationFull-stack BDD
![Page 78: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/78.jpg)
Stories
Examples
Describe
ImplementDesign
![Page 79: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/79.jpg)
Stories
Examples
Describe
ImplementDesign
Scenario-BDD
![Page 80: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/80.jpg)
in order to maintain my shopping history as a site visitor i need to be able to register on this site
Feature: registration
Scenario: Successful registration when visitor provides all the required info
Given I am on the homepage When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
![Page 81: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/81.jpg)
in orderas ai need
Feature:
Scenario: Successful registration when visitor provides
Given I am on the When And I fill in And I submit itThen And I should be on the homepage
What could be automated should be automated
![Page 82: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/82.jpg)
![Page 83: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/83.jpg)
assertEquals(Your Feature, Your App)
![Page 84: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/84.jpg)
Setup
1. Dump your sprint features into text files
2. Put those text files into the `features/` folder inside project
3. Install behat (via composer or behat.phar)
4. Initialize behat test suite by running `bin/behat —init`
![Page 85: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/85.jpg)
Feature Context<?php !use Behat\Behat\Context\ClosuredContextInterface, Behat\Behat\Context\TranslatedContextInterface, Behat\Behat\Context\BehatContext, Behat\Behat\Exception\PendingException; use Behat\Gherkin\Node\PyStringNode, Behat\Gherkin\Node\TableNode; !class FeatureContext extends BehatContext { }
![Page 86: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/86.jpg)
First run$> bin/behat ... You can implement step definitions for undefined steps with these snippets: ! /** * @Then I should see :arg1 */ public function iShouldSee($arg1) { throw new PendingException(); }
...
![Page 87: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/87.jpg)
Append snippets$> bin/behat --append-snippets
![Page 88: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/88.jpg)
Feedback loop$> bin/behat !Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage TODO: write pending definition When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
![Page 89: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/89.jpg)
Stories
Examples
Describe
ImplementDesign
Scenario-BDD
![Page 90: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/90.jpg)
Colour it Red
![Page 91: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/91.jpg)
Colour it red /** * @Given /^I am on the homepage$/ */ public function iAmOnTheHomepage() { $crawler = new \Some\Crawler\Lib\Crawler(); $crawler->goto(“http://localhost:8080/”); if (200 !== $crawler->getCurrentStatusCode()) { throw new RuntimeException(‘Can not open homepage’); } }
![Page 92: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/92.jpg)
Colour it red$> bin/behat !Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage Can not open homepage (RuntimeException) When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
![Page 93: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/93.jpg)
Stories
Examples
Describe
ImplementDesign
Scenario-BDD
![Page 94: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/94.jpg)
Change the messageAs quickly as possible
![Page 95: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/95.jpg)
Change the message$> bin/behat !Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage Can not open homepage (RuntimeException) When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
![Page 96: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/96.jpg)
Change the message$> bin/behat !Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage Route … not found (FrameworkException) When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
![Page 97: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/97.jpg)
Change the message$> bin/behat !Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage Template … not found (FrameworkException) When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
![Page 98: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/98.jpg)
Change the message$> bin/behat !Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage When I follow “sign up” TODO: write pending definition And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
![Page 100: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/100.jpg)
Change the message$> bin/behat !Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered Object `User` and its method `isRegistered` does not exist (RuntimeException) And I should be on the homepage again
![Page 101: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/101.jpg)
Stories
Examples
Describe
ImplementDesign
Spec-BDD
![Page 102: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/102.jpg)
![Page 103: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/103.jpg)
Setup
1. Install phpspec via composer
2. use it
![Page 104: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/104.jpg)
Stories
Examples
Describe
ImplementDesign
Spec-BDD
![Page 105: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/105.jpg)
Prepare your first spec$> bin/phpspec desc Acme/Userbase/User
![Page 106: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/106.jpg)
Describe your first message<?php !namespace spec\Acme\Userbase; !class User extends ObjectBehavior{ function it_is_registered_by_default() { $this->shouldBeRegistered(); } }
![Page 107: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/107.jpg)
Colour it red$> bin/phpspec !Class “Acme\Userbase\User” does not exist. Create? [Y/n] y !Method `Acme\Userbase\User::isRegistered()` does not exist. Create? [Y/n] y
![Page 108: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/108.jpg)
Stories
Examples
Describe
ImplementDesign
Spec-BDD
![Page 109: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/109.jpg)
Stories
Examples
Describe
ImplementDesign
Spec-BDD
![Page 110: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/110.jpg)
Stories
Examples
Describe
ImplementDesign
Spec-BDD
![Page 112: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/112.jpg)
Verify feature$> bin/behat !Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
![Page 113: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/113.jpg)
Verify feature$> bin/behat !Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
![Page 114: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/114.jpg)
Stories
Examples
Describe
ImplementDesign
![Page 115: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/115.jpg)
#3: Income
![Page 116: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/116.jpg)
6 months later…
![Page 117: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/117.jpg)
#3: Same ashtrays, better car
![Page 118: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/118.jpg)
We do that for clients
![Page 119: Moving away from legacy code with BDD](https://reader031.fdocuments.us/reader031/viewer/2022020217/540dc27d8d7f72927e8b49de/html5/thumbnails/119.jpg)
We do that for clientsAnd teach others in those rare
moments when we don’t
http:// .com