SlideShare a Scribd company logo
1 of 52
Welcome to Las Vegas!
Session Breakdown
Preface (this)
Intro to BDD
Intro to Behat
Build some Tests
Why Are You Here?
What is your role in the development lifecycle?
What is your reason for attending this session?
What do you hope to get out of this session?
What is your experience level with PHP, Behat,
and BDD?
Pre-Run Checklist
Make sure you have:
PHP 5.6+ w/Composer
https://github.com/aenglander/bdd-with-behat-for-
beginners
Selenium Server and a browser with the Selenium
driver (Optional)
Gotchas
Missing one of these extensions:
curl
mbstring
openssl
No default timezone in PHP.ini
What is BDD?
BDD is business driven, user focused, and test first.
It focuses on delivering business value as effectively
and efficiently as possible while maintaining
consistent quality throughout the entire application.
BDD is a methodology built around the principles of
lean development, extreme programming, test driven
development, and domain driven design.
What BDD Provides
Better understanding of the business requirement for
development and QA
Better understanding of existing features for the
business
Better communication via a ubiquitous language
Real insight into the business effect of a defect
What BDD Doesn’t Provide
The answer to all your problems
A replacement for unit testing
A replacement for manual testing
Super easy to implement everywhere right this second
A measure of code quality
Failed to Assert False is True
or
How I learned to love BDD
Stay Focused
It is crucial to the success of BDD to focus on what
value a feature provides to the business.
Always understand the the role of the user and
their relationship to the feature.
Do not get distracted by the technical aspects of
the implementation.
Story BDD Hierarchy
Feature
Background (optional)
Scenario
Step Step
Scenario
Step Step
Writing Features
Applications are comprised of features
BDD discretely separates each feature into its
very own set of tests
Separated use cases into scenarios
Narrative
Feature narratives are written similarly to Agile/Scrum
stories and must answer these questions:
What is the business benefit?
Who is the beneficiary?
What is the action performed?
Background
A background should contain steps common to all, or
at least most, scenarios to prepare the application
environment for the scenarios.
Background steps should be tested elsewhere as part
of another feature.
Steps failing in the background steps will identify that
the failure is not related to the feature.
Scenario
A scenarios should contain a descriptive narrative
Scenarios work in a manner similar to unit tests by arranging
the environment necessary to begin the test, perform
actions, and then assert that the expected results have been
attained
Scenarios should not test multiple features. Do not perform
actions after assertions.
Scenario Outline
Scenario outlines use a common set of steps with
placeholders for data provided in a data table.
They are a replacement for multiple scenarios in which
data is the only differentiator and does not define the
feature. Adding sales tax would be an example of a
feature in which the data in the action and assertion
would be different.
Step
Steps do one of the following:
Arrange the environment
Perform an action
Assert a result of the previous actions
Steps should be reasonably reusable
Steps should be aggregated for simplification when
arranging the environment
What is Behat?
Open source Behavior Driven Development
framework for PHP
Official PHP implementation of Cucumber
One of the easiest Cucumber implementations to
get up and running quickly
Good documentation: http://docs.behat.org
Installation
PHAR installation
Single global install
One version for feature contexts
Project Installation
Composer based install as dependency
Version and dependencies tied to project
Components
Command line executable – behat
Configuration file – behat.yml
Feature context(s)
Feature Files
Command Line Executable
Allows for initializing the environment
Running features
Features and scenarios filterable by tags
Chooses environment
Listing step definitions
Configuration File
Split up into profiles
(inherit from default)
Configures custom
autoloader path
Defines global tag filters
Defines output
formatters
Defines feature suites
Configures extensions
Feature Context
Defines steps
May extend other contexts
May access other contexts
May add hooks for pre/post tag, step, scenario,
feature, and suite execution.
Gherkin
Gherkin is a Domain Specific Language (DSL)
utilized to write Features in Behat. It uses key words
to identify the type of step:
Given – Arrange
When – Act
Then - Assert
Example Gherkin
Feature: Home Page
Scenario: Login Link
Given I am on the homepage
When I click " Login"
Then I will be on the "LaunchKey | Log in"
page
Step Backing Code
Method on a feature context
Contains doc block annotated (@) matchers
Support defined in context. Defaults to Turnip
Supports Turnip and regular expressions
Can contain examples doc block
Can contain descript in the doc block
Example Step
/**
* Opens homepage
* Example: Given I am on "/"
* Example: When I go to "/"
* Example: And I go to "/”
* @Given (I )am on :path
* @When (I )go to :path
*/
public function visitPath($path)
{
$this->browser->open($path);
}
Create a Project
Composer “init”
Add requirements
Behat “init”
Add Contexts to Config
Verify Your Install
Run “vendor/bin/behat –h”
You should see the help text
Initialize Behat
Initialize the behat project via the Behat CLI
with the --init flag
Verify by running “vendor/bin/behat”
Add Mink to Config
• Add the extension to the default profile
• Set the base URL
• Add the drivers
Add Contexts to Config
• Add Mink context to get access to pre-built
browser steps
• Add project context to make custom steps
Verify Configuration
Run “vendor/bin/behat –dl”
You should see a LOT of steps
Run “vendor/bin/behat –di”
You should see additional information for the
steps
Lets Write A Feature Test
User Story:
In order to use the site
As a site visitor
I can access the website
Let’s Make Another
Requirement:
In order to be a user
As a visitor
I can register for a user account
What About Clean Up
Requirement:
E-Mail Address is the user identifier and must be
unique among all users
We’re going to have to clean up users in a hook
Steps Need to Be Intuitive
Checking for errors on registration submission
will require a custom step with some additional
logic
Add Other Requirements
E-Mail Address is the user identifier and must be
unique among all users
Name is required and captures the users name
Password is required and must utilize a verification
field to ensure correct password entry
Finish Up Labs/Examples
Server and Behat features found in GitHub:
https://github.com/aenglander/bdd-with-behat-for-
beginners
Master branch is Behat
Master is tagged to go step by step
Server branch is server
Selenium
Industry standard
Server with remote API
Direct integration with Behat/Mink via Selenium
Driver
Can be used headless with PhantomJS via
GhostDriver implementation
Using Selenium Server
Add config to bahat.yml and specify browser
Apply @javascript tag to scenarios or a feature
Start Selenium Standalone Server
Run tests
Selenium Grid
Allows for multiple simultaneous test runs, multiple
browser versions, and multiple operating systems
One Hub and Multiple Nodes
Uses same app as Standalone Server
Can be flakey and hard to manage
Sauce Labs/BrowserStack
Special Drivers for Sauce Labs and
BrowserStack
Not well documented but work very well
Allow for a “Grid” style environment without
managing the Grid
Configuring Mink Driver
Poorly documented
Easy to figure out the settings by looking at the
driver factories. See:
vendor/behat/mink-
extension/src/Behat/MinkExtension/ServiceContainer
/Driver
Best Practices
Feature files contain one Feature
Features should be more business than
technical focused
Best Practices (cont.)
Use the three A’s
Arrange – Background – Given
Act – When
Assert - Then
Best Practices (cont.)
Make steps visually verifiable. Feature files
should be able to serve as documentation
Clean up after yourself
Scenarios should be idempotent
Spend the time to do it the right way

More Related Content

What's hot

DB2 and PHP in Depth on IBM i
DB2 and PHP in Depth on IBM iDB2 and PHP in Depth on IBM i
DB2 and PHP in Depth on IBM iAlan Seiden
 
Zend Core on IBM i - Security Considerations
Zend Core on IBM i - Security ConsiderationsZend Core on IBM i - Security Considerations
Zend Core on IBM i - Security ConsiderationsZendCon
 
Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentShahar Evron
 
Killer Docker Workflows for Development
Killer Docker Workflows for DevelopmentKiller Docker Workflows for Development
Killer Docker Workflows for DevelopmentChris Tankersley
 
Building and deploying PHP applications with Phing
Building and deploying PHP applications with PhingBuilding and deploying PHP applications with Phing
Building and deploying PHP applications with PhingMichiel Rook
 
PHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBeneluxPHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBeneluxNick Belhomme
 
PHP and Platform Independance in the Cloud
PHP and Platform Independance in the CloudPHP and Platform Independance in the Cloud
PHP and Platform Independance in the CloudZendCon
 
PHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iPHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden
 
Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)Chris Tankersley
 
Performance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHPPerformance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHPMax Romanovsky
 
Digpen 7: Why choose Laravel?
Digpen 7: Why choose Laravel?Digpen 7: Why choose Laravel?
Digpen 7: Why choose Laravel?John Blackmore
 
HTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityHTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityPeter Lubbers
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael Pirnat
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend frameworkAlan Seiden
 
Automated Deployment With Phing
Automated Deployment With PhingAutomated Deployment With Phing
Automated Deployment With PhingDaniel Cousineau
 
10 Reasons ColdFusion PDFs should rule the world
10 Reasons ColdFusion PDFs should rule the world10 Reasons ColdFusion PDFs should rule the world
10 Reasons ColdFusion PDFs should rule the worldColdFusionConference
 
Virtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 MayVirtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 MayPuppet
 
Zend expressive workshop
Zend expressive workshopZend expressive workshop
Zend expressive workshopAdam Culp
 
EuroPython 2011 - How to build complex web applications having fun?
EuroPython 2011 - How to build complex web applications having fun?EuroPython 2011 - How to build complex web applications having fun?
EuroPython 2011 - How to build complex web applications having fun?Andrew Mleczko
 

What's hot (20)

DB2 and PHP in Depth on IBM i
DB2 and PHP in Depth on IBM iDB2 and PHP in Depth on IBM i
DB2 and PHP in Depth on IBM i
 
Zend Core on IBM i - Security Considerations
Zend Core on IBM i - Security ConsiderationsZend Core on IBM i - Security Considerations
Zend Core on IBM i - Security Considerations
 
Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application Deployment
 
Killer Docker Workflows for Development
Killer Docker Workflows for DevelopmentKiller Docker Workflows for Development
Killer Docker Workflows for Development
 
Building and deploying PHP applications with Phing
Building and deploying PHP applications with PhingBuilding and deploying PHP applications with Phing
Building and deploying PHP applications with Phing
 
PHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBeneluxPHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBenelux
 
PHP and Platform Independance in the Cloud
PHP and Platform Independance in the CloudPHP and Platform Independance in the Cloud
PHP and Platform Independance in the Cloud
 
PHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iPHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM i
 
Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)
 
Performance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHPPerformance tips for Symfony2 & PHP
Performance tips for Symfony2 & PHP
 
Digpen 7: Why choose Laravel?
Digpen 7: Why choose Laravel?Digpen 7: Why choose Laravel?
Digpen 7: Why choose Laravel?
 
HTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityHTML5 Real-Time and Connectivity
HTML5 Real-Time and Connectivity
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend framework
 
Automated Deployment With Phing
Automated Deployment With PhingAutomated Deployment With Phing
Automated Deployment With Phing
 
10 Reasons ColdFusion PDFs should rule the world
10 Reasons ColdFusion PDFs should rule the world10 Reasons ColdFusion PDFs should rule the world
10 Reasons ColdFusion PDFs should rule the world
 
Virtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 MayVirtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 May
 
Zend expressive workshop
Zend expressive workshopZend expressive workshop
Zend expressive workshop
 
EuroPython 2011 - How to build complex web applications having fun?
EuroPython 2011 - How to build complex web applications having fun?EuroPython 2011 - How to build complex web applications having fun?
EuroPython 2011 - How to build complex web applications having fun?
 
Phalcon - Giant Killer
Phalcon - Giant KillerPhalcon - Giant Killer
Phalcon - Giant Killer
 

Similar to Zend con 2016 bdd with behat for beginners

PHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for BeginnersPHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for BeginnersAdam Englander
 
CucumberSeleniumWD
CucumberSeleniumWDCucumberSeleniumWD
CucumberSeleniumWDVikas Sarin
 
Php[tek] 2016 - BDD with Behat for Beginners
Php[tek] 2016 - BDD with Behat for BeginnersPhp[tek] 2016 - BDD with Behat for Beginners
Php[tek] 2016 - BDD with Behat for BeginnersAdam Englander
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by ExampleNalin Goonawardana
 
BDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User StoriesBDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User StoriesSauce Labs
 
BDD with Behat and Symfony2
BDD with Behat and Symfony2BDD with Behat and Symfony2
BDD with Behat and Symfony2katalisha
 
Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1willmation
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Mack Hardy
 
Automated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choiceAutomated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choicetoddbr
 
Slides from LAX & DEN usergroup meetings
Slides from LAX & DEN usergroup meetingsSlides from LAX & DEN usergroup meetings
Slides from LAX & DEN usergroup meetings10n Software, LLC
 
Introducing BDD and TDD with Cucumber
Introducing BDD and TDD with CucumberIntroducing BDD and TDD with Cucumber
Introducing BDD and TDD with CucumberKnoldus Inc.
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven DevelopmentMonocularVision
 
MuleSoft Nashik Virtual Meetup#4 - Implementing CI/CD pipeline for deploying ...
MuleSoft Nashik Virtual Meetup#4 - Implementing CI/CD pipeline for deploying ...MuleSoft Nashik Virtual Meetup#4 - Implementing CI/CD pipeline for deploying ...
MuleSoft Nashik Virtual Meetup#4 - Implementing CI/CD pipeline for deploying ...Jitendra Bafna
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroSteven Pignataro
 
[drupalday2017] - Behat per Drupal: test automatici e molto di più
[drupalday2017] - Behat per Drupal: test automatici e molto di più[drupalday2017] - Behat per Drupal: test automatici e molto di più
[drupalday2017] - Behat per Drupal: test automatici e molto di piùDrupalDay
 
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual StudioSPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual StudioNCCOMMS
 
The "Holy Grail" of Dev/Ops
The "Holy Grail" of Dev/OpsThe "Holy Grail" of Dev/Ops
The "Holy Grail" of Dev/OpsErik Osterman
 
TDD with BizTalk
TDD with BizTalkTDD with BizTalk
TDD with BizTalkBen Carey
 

Similar to Zend con 2016 bdd with behat for beginners (20)

PHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for BeginnersPHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for Beginners
 
Gherkin /BDD intro
Gherkin /BDD introGherkin /BDD intro
Gherkin /BDD intro
 
CucumberSeleniumWD
CucumberSeleniumWDCucumberSeleniumWD
CucumberSeleniumWD
 
Php[tek] 2016 - BDD with Behat for Beginners
Php[tek] 2016 - BDD with Behat for BeginnersPhp[tek] 2016 - BDD with Behat for Beginners
Php[tek] 2016 - BDD with Behat for Beginners
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by Example
 
Cucumber_Training_ForQA
Cucumber_Training_ForQACucumber_Training_ForQA
Cucumber_Training_ForQA
 
BDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User StoriesBDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User Stories
 
BDD with Behat and Symfony2
BDD with Behat and Symfony2BDD with Behat and Symfony2
BDD with Behat and Symfony2
 
Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
 
Automated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choiceAutomated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choice
 
Slides from LAX & DEN usergroup meetings
Slides from LAX & DEN usergroup meetingsSlides from LAX & DEN usergroup meetings
Slides from LAX & DEN usergroup meetings
 
Introducing BDD and TDD with Cucumber
Introducing BDD and TDD with CucumberIntroducing BDD and TDD with Cucumber
Introducing BDD and TDD with Cucumber
 
Behavior Driven Development
Behavior Driven DevelopmentBehavior Driven Development
Behavior Driven Development
 
MuleSoft Nashik Virtual Meetup#4 - Implementing CI/CD pipeline for deploying ...
MuleSoft Nashik Virtual Meetup#4 - Implementing CI/CD pipeline for deploying ...MuleSoft Nashik Virtual Meetup#4 - Implementing CI/CD pipeline for deploying ...
MuleSoft Nashik Virtual Meetup#4 - Implementing CI/CD pipeline for deploying ...
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
 
[drupalday2017] - Behat per Drupal: test automatici e molto di più
[drupalday2017] - Behat per Drupal: test automatici e molto di più[drupalday2017] - Behat per Drupal: test automatici e molto di più
[drupalday2017] - Behat per Drupal: test automatici e molto di più
 
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual StudioSPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
 
The "Holy Grail" of Dev/Ops
The "Holy Grail" of Dev/OpsThe "Holy Grail" of Dev/Ops
The "Holy Grail" of Dev/Ops
 
TDD with BizTalk
TDD with BizTalkTDD with BizTalk
TDD with BizTalk
 

More from Adam Englander

Making PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptxMaking PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptxAdam Englander
 
Practical API Security - PyCon 2019
Practical API Security - PyCon 2019Practical API Security - PyCon 2019
Practical API Security - PyCon 2019Adam Englander
 
Threat Modeling for Dummies
Threat Modeling for DummiesThreat Modeling for Dummies
Threat Modeling for DummiesAdam Englander
 
ZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API SecurityZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API SecurityAdam Englander
 
ZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in DepthZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in DepthAdam Englander
 
Threat Modeling for Dummies - Cascadia PHP 2018
Threat Modeling for Dummies - Cascadia PHP 2018Threat Modeling for Dummies - Cascadia PHP 2018
Threat Modeling for Dummies - Cascadia PHP 2018Adam Englander
 
Dutch PHP 2018 - Cryptography for Beginners
Dutch PHP 2018 - Cryptography for BeginnersDutch PHP 2018 - Cryptography for Beginners
Dutch PHP 2018 - Cryptography for BeginnersAdam Englander
 
php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2108 - Cryptography Advances in PHP 7.2php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2108 - Cryptography Advances in PHP 7.2Adam Englander
 
php[tek] 2018 - Biometrics, fantastic failure point of the future
php[tek] 2018 - Biometrics, fantastic failure point of the futurephp[tek] 2018 - Biometrics, fantastic failure point of the future
php[tek] 2018 - Biometrics, fantastic failure point of the futureAdam Englander
 
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Biometrics: Sexy, Secure and... Stupid - RSAC 2018Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Biometrics: Sexy, Secure and... Stupid - RSAC 2018Adam Englander
 
Practical API Security - PyCon 2018
Practical API Security - PyCon 2018Practical API Security - PyCon 2018
Practical API Security - PyCon 2018Adam Englander
 
Practical API Security - Midwest PHP 2018
Practical API Security - Midwest PHP 2018Practical API Security - Midwest PHP 2018
Practical API Security - Midwest PHP 2018Adam Englander
 
Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018Adam Englander
 
Cryptography for Beginners - Sunshine PHP 2018
Cryptography for Beginners - Sunshine PHP 2018Cryptography for Beginners - Sunshine PHP 2018
Cryptography for Beginners - Sunshine PHP 2018Adam Englander
 
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the FutureConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the FutureAdam Englander
 
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
Con Foo 2017 - Don't Loose Sleep - Secure Your RESTCon Foo 2017 - Don't Loose Sleep - Secure Your REST
Con Foo 2017 - Don't Loose Sleep - Secure Your RESTAdam Englander
 
ZendCon 2017 - Cryptography for Beginners
ZendCon 2017 - Cryptography for BeginnersZendCon 2017 - Cryptography for Beginners
ZendCon 2017 - Cryptography for BeginnersAdam Englander
 
ZendCon 2017: The Red Team is Coming
ZendCon 2017: The Red Team is ComingZendCon 2017: The Red Team is Coming
ZendCon 2017: The Red Team is ComingAdam Englander
 
ZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async PrimerZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async PrimerAdam Englander
 
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Symfony Live San Franciso 2017 - BDD API Development with Symfony and BehatSymfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Symfony Live San Franciso 2017 - BDD API Development with Symfony and BehatAdam Englander
 

More from Adam Englander (20)

Making PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptxMaking PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptx
 
Practical API Security - PyCon 2019
Practical API Security - PyCon 2019Practical API Security - PyCon 2019
Practical API Security - PyCon 2019
 
Threat Modeling for Dummies
Threat Modeling for DummiesThreat Modeling for Dummies
Threat Modeling for Dummies
 
ZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API SecurityZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API Security
 
ZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in DepthZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in Depth
 
Threat Modeling for Dummies - Cascadia PHP 2018
Threat Modeling for Dummies - Cascadia PHP 2018Threat Modeling for Dummies - Cascadia PHP 2018
Threat Modeling for Dummies - Cascadia PHP 2018
 
Dutch PHP 2018 - Cryptography for Beginners
Dutch PHP 2018 - Cryptography for BeginnersDutch PHP 2018 - Cryptography for Beginners
Dutch PHP 2018 - Cryptography for Beginners
 
php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2108 - Cryptography Advances in PHP 7.2php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2108 - Cryptography Advances in PHP 7.2
 
php[tek] 2018 - Biometrics, fantastic failure point of the future
php[tek] 2018 - Biometrics, fantastic failure point of the futurephp[tek] 2018 - Biometrics, fantastic failure point of the future
php[tek] 2018 - Biometrics, fantastic failure point of the future
 
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Biometrics: Sexy, Secure and... Stupid - RSAC 2018Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
 
Practical API Security - PyCon 2018
Practical API Security - PyCon 2018Practical API Security - PyCon 2018
Practical API Security - PyCon 2018
 
Practical API Security - Midwest PHP 2018
Practical API Security - Midwest PHP 2018Practical API Security - Midwest PHP 2018
Practical API Security - Midwest PHP 2018
 
Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018
 
Cryptography for Beginners - Sunshine PHP 2018
Cryptography for Beginners - Sunshine PHP 2018Cryptography for Beginners - Sunshine PHP 2018
Cryptography for Beginners - Sunshine PHP 2018
 
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the FutureConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
 
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
Con Foo 2017 - Don't Loose Sleep - Secure Your RESTCon Foo 2017 - Don't Loose Sleep - Secure Your REST
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
 
ZendCon 2017 - Cryptography for Beginners
ZendCon 2017 - Cryptography for BeginnersZendCon 2017 - Cryptography for Beginners
ZendCon 2017 - Cryptography for Beginners
 
ZendCon 2017: The Red Team is Coming
ZendCon 2017: The Red Team is ComingZendCon 2017: The Red Team is Coming
ZendCon 2017: The Red Team is Coming
 
ZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async PrimerZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async Primer
 
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Symfony Live San Franciso 2017 - BDD API Development with Symfony and BehatSymfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
 

Recently uploaded

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 

Recently uploaded (20)

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 

Zend con 2016 bdd with behat for beginners

  • 1.
  • 2. Welcome to Las Vegas!
  • 3. Session Breakdown Preface (this) Intro to BDD Intro to Behat Build some Tests
  • 4. Why Are You Here? What is your role in the development lifecycle? What is your reason for attending this session? What do you hope to get out of this session? What is your experience level with PHP, Behat, and BDD?
  • 5. Pre-Run Checklist Make sure you have: PHP 5.6+ w/Composer https://github.com/aenglander/bdd-with-behat-for- beginners Selenium Server and a browser with the Selenium driver (Optional)
  • 6. Gotchas Missing one of these extensions: curl mbstring openssl No default timezone in PHP.ini
  • 7.
  • 8. What is BDD? BDD is business driven, user focused, and test first. It focuses on delivering business value as effectively and efficiently as possible while maintaining consistent quality throughout the entire application. BDD is a methodology built around the principles of lean development, extreme programming, test driven development, and domain driven design.
  • 9. What BDD Provides Better understanding of the business requirement for development and QA Better understanding of existing features for the business Better communication via a ubiquitous language Real insight into the business effect of a defect
  • 10. What BDD Doesn’t Provide The answer to all your problems A replacement for unit testing A replacement for manual testing Super easy to implement everywhere right this second A measure of code quality
  • 11. Failed to Assert False is True or How I learned to love BDD
  • 12.
  • 13. Stay Focused It is crucial to the success of BDD to focus on what value a feature provides to the business. Always understand the the role of the user and their relationship to the feature. Do not get distracted by the technical aspects of the implementation.
  • 14. Story BDD Hierarchy Feature Background (optional) Scenario Step Step Scenario Step Step
  • 15. Writing Features Applications are comprised of features BDD discretely separates each feature into its very own set of tests Separated use cases into scenarios
  • 16. Narrative Feature narratives are written similarly to Agile/Scrum stories and must answer these questions: What is the business benefit? Who is the beneficiary? What is the action performed?
  • 17. Background A background should contain steps common to all, or at least most, scenarios to prepare the application environment for the scenarios. Background steps should be tested elsewhere as part of another feature. Steps failing in the background steps will identify that the failure is not related to the feature.
  • 18. Scenario A scenarios should contain a descriptive narrative Scenarios work in a manner similar to unit tests by arranging the environment necessary to begin the test, perform actions, and then assert that the expected results have been attained Scenarios should not test multiple features. Do not perform actions after assertions.
  • 19. Scenario Outline Scenario outlines use a common set of steps with placeholders for data provided in a data table. They are a replacement for multiple scenarios in which data is the only differentiator and does not define the feature. Adding sales tax would be an example of a feature in which the data in the action and assertion would be different.
  • 20. Step Steps do one of the following: Arrange the environment Perform an action Assert a result of the previous actions Steps should be reasonably reusable Steps should be aggregated for simplification when arranging the environment
  • 21.
  • 22. What is Behat? Open source Behavior Driven Development framework for PHP Official PHP implementation of Cucumber One of the easiest Cucumber implementations to get up and running quickly Good documentation: http://docs.behat.org
  • 23. Installation PHAR installation Single global install One version for feature contexts Project Installation Composer based install as dependency Version and dependencies tied to project
  • 24. Components Command line executable – behat Configuration file – behat.yml Feature context(s) Feature Files
  • 25. Command Line Executable Allows for initializing the environment Running features Features and scenarios filterable by tags Chooses environment Listing step definitions
  • 26. Configuration File Split up into profiles (inherit from default) Configures custom autoloader path Defines global tag filters Defines output formatters Defines feature suites Configures extensions
  • 27. Feature Context Defines steps May extend other contexts May access other contexts May add hooks for pre/post tag, step, scenario, feature, and suite execution.
  • 28. Gherkin Gherkin is a Domain Specific Language (DSL) utilized to write Features in Behat. It uses key words to identify the type of step: Given – Arrange When – Act Then - Assert
  • 29. Example Gherkin Feature: Home Page Scenario: Login Link Given I am on the homepage When I click " Login" Then I will be on the "LaunchKey | Log in" page
  • 30. Step Backing Code Method on a feature context Contains doc block annotated (@) matchers Support defined in context. Defaults to Turnip Supports Turnip and regular expressions Can contain examples doc block Can contain descript in the doc block
  • 31. Example Step /** * Opens homepage * Example: Given I am on "/" * Example: When I go to "/" * Example: And I go to "/” * @Given (I )am on :path * @When (I )go to :path */ public function visitPath($path) { $this->browser->open($path); }
  • 32.
  • 33. Create a Project Composer “init” Add requirements Behat “init” Add Contexts to Config
  • 34. Verify Your Install Run “vendor/bin/behat –h” You should see the help text
  • 35. Initialize Behat Initialize the behat project via the Behat CLI with the --init flag Verify by running “vendor/bin/behat”
  • 36. Add Mink to Config • Add the extension to the default profile • Set the base URL • Add the drivers
  • 37. Add Contexts to Config • Add Mink context to get access to pre-built browser steps • Add project context to make custom steps
  • 38. Verify Configuration Run “vendor/bin/behat –dl” You should see a LOT of steps Run “vendor/bin/behat –di” You should see additional information for the steps
  • 39. Lets Write A Feature Test User Story: In order to use the site As a site visitor I can access the website
  • 40. Let’s Make Another Requirement: In order to be a user As a visitor I can register for a user account
  • 41. What About Clean Up Requirement: E-Mail Address is the user identifier and must be unique among all users We’re going to have to clean up users in a hook
  • 42. Steps Need to Be Intuitive Checking for errors on registration submission will require a custom step with some additional logic
  • 43. Add Other Requirements E-Mail Address is the user identifier and must be unique among all users Name is required and captures the users name Password is required and must utilize a verification field to ensure correct password entry
  • 44. Finish Up Labs/Examples Server and Behat features found in GitHub: https://github.com/aenglander/bdd-with-behat-for- beginners Master branch is Behat Master is tagged to go step by step Server branch is server
  • 45. Selenium Industry standard Server with remote API Direct integration with Behat/Mink via Selenium Driver Can be used headless with PhantomJS via GhostDriver implementation
  • 46. Using Selenium Server Add config to bahat.yml and specify browser Apply @javascript tag to scenarios or a feature Start Selenium Standalone Server Run tests
  • 47. Selenium Grid Allows for multiple simultaneous test runs, multiple browser versions, and multiple operating systems One Hub and Multiple Nodes Uses same app as Standalone Server Can be flakey and hard to manage
  • 48. Sauce Labs/BrowserStack Special Drivers for Sauce Labs and BrowserStack Not well documented but work very well Allow for a “Grid” style environment without managing the Grid
  • 49. Configuring Mink Driver Poorly documented Easy to figure out the settings by looking at the driver factories. See: vendor/behat/mink- extension/src/Behat/MinkExtension/ServiceContainer /Driver
  • 50. Best Practices Feature files contain one Feature Features should be more business than technical focused
  • 51. Best Practices (cont.) Use the three A’s Arrange – Background – Given Act – When Assert - Then
  • 52. Best Practices (cont.) Make steps visually verifiable. Feature files should be able to serve as documentation Clean up after yourself Scenarios should be idempotent Spend the time to do it the right way

Editor's Notes

  1. Extensions are usually pre-enabled by default with Linux or Mac package managers. Windows users need to uncomment the line n the php.ini. Search for “date.timezone”. Set it to whatever you like. If you are not sure you can use “UTC”.
  2. The direct correlation between the SOAP box and BDD is the reason BDD is becoming more and more popular.
  3. I never meant to learn BDD. I was just looking for a tool to help me stop breaking a critical legacy business application every time we released a new feature. We had built entire integration testing platforms but they would not give me or the business what we needed to identify defects and were constantly giving false positives and negatives to the brittle nature of the tests. The first step was using feature based testing with Cucumber and then Behat when it became available. Embracing BDD, like everything else in my career, was a process of enlightenment. It took time and required pain to drive growth.
  4. composer init composer require --dev behat/behat behat/mink-extension behat/mink-goutte-driver behat/mink-selenium2-driver vendor/bin/behat --init vendor/bin/behat -h
  5. vendor/bin/behat --init vendor/bin/behat
  6. default: extensions: Behat\MinkExtension: base_url: http://adam-bdd-with-behat.ngrok.io goutte: ~ selenium2: ~
  7. default: suites: default: contexts: - Behat\MinkExtension\Context\MinkContext - FeatureContext
  8. Vendor/bin/behat -dl
  9. Feature: A visitor can access the homepage In order to use the site As a site visitor I can access the website Scenario: Homepage loads When I go to the homepage Then I should see "Your Application's Landing Page. "
  10. Feature: User Registration In order to be a user As a visitor I can register for a user account Background: Given I am on "/register" Scenario: Proper fields register the user When I fill in the following: | Name | Adam | | E-Mail Address | test.email@launchkey.com | | Password | Password1 | | Confirm Password | Password1 | And I press "Register" Then I should be on the homepage And the response should contain "Logout"
  11. use Behat\Behat\Hook\Scope\BeforeScenarioScope; /** * @BeforeScenario */ public function cleanupUsers(BeforeScenarioScope $scope) { $this->mink = $scope->getEnvironment()->getContext('Behat\MinkExtension\Context\MinkContext'); $this->mink->visit(‘/delete-test-users’); }
  12. /** * @Then the :field field should have an error */ public function theFieldHasAnError($field) { $has = $this->mink->getSession() ->getPage() ->findField($field) ->getParent() ->has('css', 'span.help-block'); if ( ! $has) { throw new \Exception("Field \"{$field}\" has no error"); } }
  13. Behat\MinkExtension: browser_name: chrome goutte: ~ selenium2: ~