BDD with Behat and PHPSpec

17
BDD with Behat and PHPSpec Rob Ingram

Transcript of BDD with Behat and PHPSpec

Page 1: BDD with Behat and PHPSpec

BDD with Behat and PHPSpecRob Ingram

Page 2: BDD with Behat and PHPSpec

Image credit: J Williams

Page 3: BDD with Behat and PHPSpec

Outline

Narrative

Background

Scenarios

Page 4: BDD with Behat and PHPSpec

Outline

In order to <achieve a business goal>

As a <stakeholder>

I want <something>

Page 5: BDD with Behat and PHPSpec

Outline

Feature: store locator

In order to shop at the closest store

As a customer

I want to search for stores in my city

Page 6: BDD with Behat and PHPSpec

Alternative format

Feature: store locator

As a customer

I want to search for stores in my city

So that I can shop at the closest store

Page 7: BDD with Behat and PHPSpec

Scenario

Given <a context>

When <something happens>

Then <I expect some outcomes>

Page 8: BDD with Behat and PHPSpec

ScenarioScenario: search by city name

Given I am on the homepage

When I fill in "location" with "Christchurch"

And I press "Locate"

Then I should be on the “Store Locator” page

And I should see “Kathmandu Christchurch CBD Re:START”

And I should see “0.2km”

Page 9: BDD with Behat and PHPSpec

ScenarioScenario: search by city name

Given I am on the homepage

When I fill in "location" with "Christchurch"

And I press “Locate"

Then I should be on the “Store Locator” page

And I should see the following store results:| name | distance || Kathmandu Christchurch CBD Re:START | 0.2km || Kathmandu Tower Junction | 2.5km |

Page 10: BDD with Behat and PHPSpec

Background

Background:

Given I am logged in

Page 11: BDD with Behat and PHPSpec

Image credit: PittCaleb

Page 12: BDD with Behat and PHPSpec
Page 13: BDD with Behat and PHPSpec

PHPSpec<?php

namespace spec;

use PhpSpec\ObjectBehavior;

class MarkdownSpec extends ObjectBehavior{ function it_converts_plain_text_to_html_paragraphs() { $this->toHtml("Hi, there")->shouldReturn("<p>Hi, there</p>"); }}

Page 14: BDD with Behat and PHPSpec

Live coding

Kinda

Page 15: BDD with Behat and PHPSpec
Page 16: BDD with Behat and PHPSpec

Image credit: @joefoodie

Page 17: BDD with Behat and PHPSpec

Links

Behat: http://docs.behat.org/en/v3.0/

Behat Silverstripe: https://github.com/silverstripe-labs/silverstripe-behat-extension

PHPSpec: http://www.phpspec.net/en/stable/