SlideShare a Scribd company logo
Behavior Driven
Development and
Laravel
1
About Me
• Marcus Moore
• San Diego, CA
• Diego Dev Group
• San Diego PHP User Group co-organizer
2
Overview
• My history with Behavior Driven Development
• Behavior Driven Development
• Behavior Driven Development and Laravel
3
My History with BDD
• When I worked at a small school
• Gathering requirements was easy!
4
My History with BDD
• Working for an agency...
• Requirement gathering got harder...
• Many clients with many communication styles
• "Who has solved this?"
5
Behavior Driven Development
• Extension of Test Driven Development (TDD)
• BDD works closely with Unit Testing
• BDD is not about testing
• Helps you build the right thing
6
Communication is hard
• Ambiguities arise
• Assumptions are made
• Rework becomes inevitable
7
BDD's Goals
• Close communication gap between all stakeholders using
real examples
• Establish a shared understanding of the desired outcome
• Eliminate "rework"
8
Three Steps
1. Discovery
2. Formulation
3. Automation
9
Discovery
• Most important part!
• Enables stakeholders to have focused conversations
• Fills knowledge gaps
• Develops an understanding of how the software should
function using real examples
10
Methods of Discovery
• Discovery Workshops
• Example Mapping
• Event Storming
• etc...
11
Discovery Workshops
• AKA the Three Amigos
• Short and frequent meetings
• Different people with different perspectives
12
Three Amigos
1. Business Person (Product Owner)
• Determines "what"
• Expresses the user stories
2. Developer
• Determines "how"
• Looks for details and potential roadblocks
3. Quality Assurance
• Come up with the "what if's"
• Tries to determine what will break
13
Discovery Results
• Complete shared understanding
• Concrete examples
14
Formulation
• Documentation of the concrete examples
• Written in natural language syntax
• Readable by humans and software
• .feature files
• Gherkin
15
Gherkin
• Tells the Story via a narrative
• Easy for non-technical people to read
16
Feature: Requesting rides
As a verified user
I want to request a ride
So that I can get to my destination on time
Rule: Unverified users cannot request rides
Rule: User cannot request ride for more than 5 people
Scenario: A user requests a ride for 4 people
Given I am a verified user
And there is a van with 5 seats nearby
And there is a car with 3 seats next to me
When I request a ride for 4 people
Then I should see I am being connected to the van
17
Given - Set the state of the world
Given I am a verified user
And there is a van with 5 seats nearby
And there is a car with 3 seats next to me
18
When - Interact with the application
When I request a ride for 4 people
19
Then - Check the outcome of the interaction
Then I should see I am being connected to the van
20
Feature: Requesting rides
As a verified user
I want to request a ride
So that I can get to my destination on time
Rule: Unverified users cannot request rides
Rule: User cannot request ride for more than 5 people
Scenario: A user requests a ride for 4 people
Given I am a verified user
And there is a van with 5 seats nearby
And there is a car with 3 seats next to me
When I request a ride for 4 people
Then I should see I am being connected to the van
21
Formulation Results
• Common terminology solidified
• Shared understanding is documented in feature files
• New people can understand the application
22
Automation
• Start to implement the features with BDD and TDD
• Double-Loop Workflow
• Implement the features with Behat
23
Behat
• The go-to BDD Framework for PHP
• Implementation of Cucumber
24
Laravel and Behat
25
Installation and Setup
• Install via Composer
• vendor/bin/behat !"init
• Add your feature files to /features
• vendor/bin/behat !"append-snippets
26
Feature: Requesting rides
As a verified user
I want to request a ride
So that I can get to my destination on time
Rule: Unverified users cannot request rides
Rule: User cannot request ride for more than 5 people
Scenario: A user requests a ride for 4 people
Given I am a verified user
And there is a van with 5 seats nearby
And there is a car with 3 seats next to me
When I request a ride for 4 people
Then I should see I am being connected to the van
27
/**
* @Given I am a verified user
"#
public function iAmAVerifiedUser()
{
throw new PendingException();
}
28
/**
* @Given I am a verified user
"#
public function iAmAVerifiedUser()
{
$this"$actingUser = factory(User"%class)
"$state('verified')
"$create();
$this"$userLocation = [
'latitude' "& '32.7',
'longitude' "& '-117.1',
];
}
29
class FeatureContext implements Context
{
public function !"construct()
{
}
}
30
class BaseContext extends TestCase implements Context
{
use CreatesApplication;
public function !"construct()
{
putenv('APP_ENV=testing');
parent!#!"construct();
$this!$setUp();
$this!$withoutExceptionHandling();
}
/** @BeforeScenario !%
public function before(BeforeScenarioScope $scope)
{
$this!$artisan('migrate:fresh');
}
}
31
/**
* @Given I am a verified user
"#
public function iAmAVerifiedUser()
{
$this"$actingUser = factory(User"%class)
"$state('verified')
"$create();
$this"$userLocation = [
'latitude' "& '32.7',
'longitude' "& '-117.1',
];
}
32
/**
* @And there is a van with :arg1 seats nearby
!"
public function thereIsAVanWithSeatsNearby($arg1)
{
throw new PendingException();
}
33
And there is a van with 5 seats nearby
34
/**
* @And there is a van with :arg1 seats nearby
!"
public function thereIsAVanWithSeatsNearby($arg1)
{
throw new PendingException();
}
35
/**
* @And there is a van with :numberOfSeats seats nearby
!"
public function thereIsAVanWithSeatsNearby($numberOfSeats)
{
$this!#createVan($numberOfSeats, $distanceFromUser = 3);
}
36
/**
* @And there is a car with :numberOfSeats seats next to me
!"
public function thereIsACarWithSeatsNextToMe($numberOfSeats)
{
$this!#createCar($numberOfSeats, $distanceFromUser = 1);
}
37
$this!"createVan($numberOfSeats, $distanceFromUser = 3);
$this!"createCar($numberOfSeats, $distanceFromUser = 1);
38
Scenario: A user requests a ride for 4 people
Given I am a verified user
And there is a van with 5 seats nearby
And there is a car with 3 seats next to me
When I request a ride for 4 people
Then I should see I am being connected to the van
39
Scenario: A user requests a ride for 4 people
Given I am a verified user
And there is a "van" with "5" seats "nearby"
And there is a "car" with "3" seats "next to me"
When I request a ride for 4 people
Then I should see I am being connected to the van
40
/**
* @Given there is a :arg1 with :arg2 seats :arg3
!"
public function thereIsAWithSeats($arg1, $arg2, $arg3)
{
throw new PendingException();
}
41
/**
* @Given there is a :typeOfVehicle with :numberOfSeats seats :distanceFromUser
!"
public function thereIsAWithSeatsNearby($typeOfVehicle, $numberOfSeats, $distanceFromUser)
{
$distance = 3;
if ($distanceFromUser !!# 'next to me') {
$distance = 1;
}
$this!$vehicles[$typeOfVehicle] = $this!$createVehicle($typeOfVehicle, $numberOfSeats, $distance);
}
42
/**
* @When I request a ride for :numberOfPeople people
!"
public function iRequestARideForPeople($numberOfPeople)
{
$this!#response = $this!#actingAs($this!#actingUser)
!#json(
'POST',
'/api/get-ride',
[
'location' !% $this!#userLocation,
'number_of_seats' !% $numberOfPeople
]
);
}
43
!" Controller does some work to match user and driver
!" Good time to TDD a service!
return response()!#json([
'message' !$ $closestVehicle!#driver . ' will pick you up soon!',
]);
44
/**
* @Then I should see I am being connected to the van
!"
public function iShouldSeeIAmBeingConnectedToTheVan()
{
$messageFromResponse = $this!#response!#decodeResponseJson('message');
$nameOfVanDriver = $this!#vehicles['van']['driver'];
$this!#assertTrue(Str!$contains($messageFromResponse, $nameOfVanDriver));
}
45
Repeat the cycle for the rest of the scenarios...
46
Also... Mink
47
Automation Results
• Real-world examples drove the development of the
application
• The application is tested on multiple levels
48
So...
1. Discovery
2. Formulation
3. Automation
4.
! "
49
Thank you
• bit.ly/laracon-au-bdd
• twitter.com/marcusamoore
50

More Related Content

What's hot

JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Mats Bryntse
 
Technical SEO Myths Facts And Theories On Crawl Budget And The Importance Of ...
Technical SEO Myths Facts And Theories On Crawl Budget And The Importance Of ...Technical SEO Myths Facts And Theories On Crawl Budget And The Importance Of ...
Technical SEO Myths Facts And Theories On Crawl Budget And The Importance Of ...
Dawn Anderson MSc DigM
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
Mayank Panchal
 
DBA Fundamentals Group: Continuous SQL with Kafka and Flink
DBA Fundamentals Group: Continuous SQL with Kafka and FlinkDBA Fundamentals Group: Continuous SQL with Kafka and Flink
DBA Fundamentals Group: Continuous SQL with Kafka and Flink
Timothy Spann
 
Introduction to laravel framework
Introduction to laravel frameworkIntroduction to laravel framework
Introduction to laravel framework
Ahmad Fatoni
 
RxJS - The Basics & The Future
RxJS - The Basics & The FutureRxJS - The Basics & The Future
RxJS - The Basics & The Future
Tracy Lee
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
Mindfire Solutions
 
What Is Spring Framework In Java | Spring Framework Tutorial For Beginners Wi...
What Is Spring Framework In Java | Spring Framework Tutorial For Beginners Wi...What Is Spring Framework In Java | Spring Framework Tutorial For Beginners Wi...
What Is Spring Framework In Java | Spring Framework Tutorial For Beginners Wi...
Edureka!
 
Microservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring CloudMicroservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring Cloud
Eberhard Wolff
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
Piyush Aggarwal
 
Automação e virtualização de serviços
Automação e virtualização de serviçosAutomação e virtualização de serviços
Automação e virtualização de serviços
Elias Nogueira
 
Search Query Processing: The Secret Life of Queries, Parsing, Rewriting & SEO
Search Query Processing: The Secret Life of Queries, Parsing, Rewriting & SEOSearch Query Processing: The Secret Life of Queries, Parsing, Rewriting & SEO
Search Query Processing: The Secret Life of Queries, Parsing, Rewriting & SEO
Koray Tugberk GUBUR
 
JAVASCRIPT PPT [Autosaved].pptx
JAVASCRIPT PPT [Autosaved].pptxJAVASCRIPT PPT [Autosaved].pptx
JAVASCRIPT PPT [Autosaved].pptx
AchieversITAravind
 
laravel.pptx
laravel.pptxlaravel.pptx
laravel.pptx
asif290119
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
Ahmad Shah Hafizan Hamidin
 
Semantic search
Semantic searchSemantic search
Semantic search
Bill Slawski
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
Prem Sanil
 
Different wait methods or commands in Selenium
Different wait methods or commands in SeleniumDifferent wait methods or commands in Selenium
Different wait methods or commands in Selenium
Vinay Kumar Pulabaigari
 
What is JavaScript? Edureka
What is JavaScript? EdurekaWhat is JavaScript? Edureka
What is JavaScript? Edureka
Edureka!
 
Java Quiz Questions
Java Quiz QuestionsJava Quiz Questions
Java Quiz Questions
CodeOps Technologies LLP
 

What's hot (20)

JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Technical SEO Myths Facts And Theories On Crawl Budget And The Importance Of ...
Technical SEO Myths Facts And Theories On Crawl Budget And The Importance Of ...Technical SEO Myths Facts And Theories On Crawl Budget And The Importance Of ...
Technical SEO Myths Facts And Theories On Crawl Budget And The Importance Of ...
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
 
DBA Fundamentals Group: Continuous SQL with Kafka and Flink
DBA Fundamentals Group: Continuous SQL with Kafka and FlinkDBA Fundamentals Group: Continuous SQL with Kafka and Flink
DBA Fundamentals Group: Continuous SQL with Kafka and Flink
 
Introduction to laravel framework
Introduction to laravel frameworkIntroduction to laravel framework
Introduction to laravel framework
 
RxJS - The Basics & The Future
RxJS - The Basics & The FutureRxJS - The Basics & The Future
RxJS - The Basics & The Future
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
 
What Is Spring Framework In Java | Spring Framework Tutorial For Beginners Wi...
What Is Spring Framework In Java | Spring Framework Tutorial For Beginners Wi...What Is Spring Framework In Java | Spring Framework Tutorial For Beginners Wi...
What Is Spring Framework In Java | Spring Framework Tutorial For Beginners Wi...
 
Microservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring CloudMicroservice With Spring Boot and Spring Cloud
Microservice With Spring Boot and Spring Cloud
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Automação e virtualização de serviços
Automação e virtualização de serviçosAutomação e virtualização de serviços
Automação e virtualização de serviços
 
Search Query Processing: The Secret Life of Queries, Parsing, Rewriting & SEO
Search Query Processing: The Secret Life of Queries, Parsing, Rewriting & SEOSearch Query Processing: The Secret Life of Queries, Parsing, Rewriting & SEO
Search Query Processing: The Secret Life of Queries, Parsing, Rewriting & SEO
 
JAVASCRIPT PPT [Autosaved].pptx
JAVASCRIPT PPT [Autosaved].pptxJAVASCRIPT PPT [Autosaved].pptx
JAVASCRIPT PPT [Autosaved].pptx
 
laravel.pptx
laravel.pptxlaravel.pptx
laravel.pptx
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
 
Semantic search
Semantic searchSemantic search
Semantic search
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 
Different wait methods or commands in Selenium
Different wait methods or commands in SeleniumDifferent wait methods or commands in Selenium
Different wait methods or commands in Selenium
 
What is JavaScript? Edureka
What is JavaScript? EdurekaWhat is JavaScript? Edureka
What is JavaScript? Edureka
 
Java Quiz Questions
Java Quiz QuestionsJava Quiz Questions
Java Quiz Questions
 

Recently uploaded

Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
QuickwayInfoSystems3
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 

Recently uploaded (20)

Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 

Behavior Driven Development and Laravel

  • 2. About Me • Marcus Moore • San Diego, CA • Diego Dev Group • San Diego PHP User Group co-organizer 2
  • 3. Overview • My history with Behavior Driven Development • Behavior Driven Development • Behavior Driven Development and Laravel 3
  • 4. My History with BDD • When I worked at a small school • Gathering requirements was easy! 4
  • 5. My History with BDD • Working for an agency... • Requirement gathering got harder... • Many clients with many communication styles • "Who has solved this?" 5
  • 6. Behavior Driven Development • Extension of Test Driven Development (TDD) • BDD works closely with Unit Testing • BDD is not about testing • Helps you build the right thing 6
  • 7. Communication is hard • Ambiguities arise • Assumptions are made • Rework becomes inevitable 7
  • 8. BDD's Goals • Close communication gap between all stakeholders using real examples • Establish a shared understanding of the desired outcome • Eliminate "rework" 8
  • 9. Three Steps 1. Discovery 2. Formulation 3. Automation 9
  • 10. Discovery • Most important part! • Enables stakeholders to have focused conversations • Fills knowledge gaps • Develops an understanding of how the software should function using real examples 10
  • 11. Methods of Discovery • Discovery Workshops • Example Mapping • Event Storming • etc... 11
  • 12. Discovery Workshops • AKA the Three Amigos • Short and frequent meetings • Different people with different perspectives 12
  • 13. Three Amigos 1. Business Person (Product Owner) • Determines "what" • Expresses the user stories 2. Developer • Determines "how" • Looks for details and potential roadblocks 3. Quality Assurance • Come up with the "what if's" • Tries to determine what will break 13
  • 14. Discovery Results • Complete shared understanding • Concrete examples 14
  • 15. Formulation • Documentation of the concrete examples • Written in natural language syntax • Readable by humans and software • .feature files • Gherkin 15
  • 16. Gherkin • Tells the Story via a narrative • Easy for non-technical people to read 16
  • 17. Feature: Requesting rides As a verified user I want to request a ride So that I can get to my destination on time Rule: Unverified users cannot request rides Rule: User cannot request ride for more than 5 people Scenario: A user requests a ride for 4 people Given I am a verified user And there is a van with 5 seats nearby And there is a car with 3 seats next to me When I request a ride for 4 people Then I should see I am being connected to the van 17
  • 18. Given - Set the state of the world Given I am a verified user And there is a van with 5 seats nearby And there is a car with 3 seats next to me 18
  • 19. When - Interact with the application When I request a ride for 4 people 19
  • 20. Then - Check the outcome of the interaction Then I should see I am being connected to the van 20
  • 21. Feature: Requesting rides As a verified user I want to request a ride So that I can get to my destination on time Rule: Unverified users cannot request rides Rule: User cannot request ride for more than 5 people Scenario: A user requests a ride for 4 people Given I am a verified user And there is a van with 5 seats nearby And there is a car with 3 seats next to me When I request a ride for 4 people Then I should see I am being connected to the van 21
  • 22. Formulation Results • Common terminology solidified • Shared understanding is documented in feature files • New people can understand the application 22
  • 23. Automation • Start to implement the features with BDD and TDD • Double-Loop Workflow • Implement the features with Behat 23
  • 24. Behat • The go-to BDD Framework for PHP • Implementation of Cucumber 24
  • 26. Installation and Setup • Install via Composer • vendor/bin/behat !"init • Add your feature files to /features • vendor/bin/behat !"append-snippets 26
  • 27. Feature: Requesting rides As a verified user I want to request a ride So that I can get to my destination on time Rule: Unverified users cannot request rides Rule: User cannot request ride for more than 5 people Scenario: A user requests a ride for 4 people Given I am a verified user And there is a van with 5 seats nearby And there is a car with 3 seats next to me When I request a ride for 4 people Then I should see I am being connected to the van 27
  • 28. /** * @Given I am a verified user "# public function iAmAVerifiedUser() { throw new PendingException(); } 28
  • 29. /** * @Given I am a verified user "# public function iAmAVerifiedUser() { $this"$actingUser = factory(User"%class) "$state('verified') "$create(); $this"$userLocation = [ 'latitude' "& '32.7', 'longitude' "& '-117.1', ]; } 29
  • 30. class FeatureContext implements Context { public function !"construct() { } } 30
  • 31. class BaseContext extends TestCase implements Context { use CreatesApplication; public function !"construct() { putenv('APP_ENV=testing'); parent!#!"construct(); $this!$setUp(); $this!$withoutExceptionHandling(); } /** @BeforeScenario !% public function before(BeforeScenarioScope $scope) { $this!$artisan('migrate:fresh'); } } 31
  • 32. /** * @Given I am a verified user "# public function iAmAVerifiedUser() { $this"$actingUser = factory(User"%class) "$state('verified') "$create(); $this"$userLocation = [ 'latitude' "& '32.7', 'longitude' "& '-117.1', ]; } 32
  • 33. /** * @And there is a van with :arg1 seats nearby !" public function thereIsAVanWithSeatsNearby($arg1) { throw new PendingException(); } 33
  • 34. And there is a van with 5 seats nearby 34
  • 35. /** * @And there is a van with :arg1 seats nearby !" public function thereIsAVanWithSeatsNearby($arg1) { throw new PendingException(); } 35
  • 36. /** * @And there is a van with :numberOfSeats seats nearby !" public function thereIsAVanWithSeatsNearby($numberOfSeats) { $this!#createVan($numberOfSeats, $distanceFromUser = 3); } 36
  • 37. /** * @And there is a car with :numberOfSeats seats next to me !" public function thereIsACarWithSeatsNextToMe($numberOfSeats) { $this!#createCar($numberOfSeats, $distanceFromUser = 1); } 37
  • 38. $this!"createVan($numberOfSeats, $distanceFromUser = 3); $this!"createCar($numberOfSeats, $distanceFromUser = 1); 38
  • 39. Scenario: A user requests a ride for 4 people Given I am a verified user And there is a van with 5 seats nearby And there is a car with 3 seats next to me When I request a ride for 4 people Then I should see I am being connected to the van 39
  • 40. Scenario: A user requests a ride for 4 people Given I am a verified user And there is a "van" with "5" seats "nearby" And there is a "car" with "3" seats "next to me" When I request a ride for 4 people Then I should see I am being connected to the van 40
  • 41. /** * @Given there is a :arg1 with :arg2 seats :arg3 !" public function thereIsAWithSeats($arg1, $arg2, $arg3) { throw new PendingException(); } 41
  • 42. /** * @Given there is a :typeOfVehicle with :numberOfSeats seats :distanceFromUser !" public function thereIsAWithSeatsNearby($typeOfVehicle, $numberOfSeats, $distanceFromUser) { $distance = 3; if ($distanceFromUser !!# 'next to me') { $distance = 1; } $this!$vehicles[$typeOfVehicle] = $this!$createVehicle($typeOfVehicle, $numberOfSeats, $distance); } 42
  • 43. /** * @When I request a ride for :numberOfPeople people !" public function iRequestARideForPeople($numberOfPeople) { $this!#response = $this!#actingAs($this!#actingUser) !#json( 'POST', '/api/get-ride', [ 'location' !% $this!#userLocation, 'number_of_seats' !% $numberOfPeople ] ); } 43
  • 44. !" Controller does some work to match user and driver !" Good time to TDD a service! return response()!#json([ 'message' !$ $closestVehicle!#driver . ' will pick you up soon!', ]); 44
  • 45. /** * @Then I should see I am being connected to the van !" public function iShouldSeeIAmBeingConnectedToTheVan() { $messageFromResponse = $this!#response!#decodeResponseJson('message'); $nameOfVanDriver = $this!#vehicles['van']['driver']; $this!#assertTrue(Str!$contains($messageFromResponse, $nameOfVanDriver)); } 45
  • 46. Repeat the cycle for the rest of the scenarios... 46
  • 48. Automation Results • Real-world examples drove the development of the application • The application is tested on multiple levels 48
  • 49. So... 1. Discovery 2. Formulation 3. Automation 4. ! " 49
  • 50. Thank you • bit.ly/laracon-au-bdd • twitter.com/marcusamoore 50