SlideShare une entreprise Scribd logo
1  sur  70
Télécharger pour lire hors ligne
Kamil Adryjanek <kamil@level7systems.pl>
TDD with BDD
in PHP and Symfony
Kamil Adryjanek <kamil@level7systems.pl>
Kamil AdryjanekKamil Adryjanek
Head of Development at
Level7Systems.pl
PHP / Symfony2 trainer
Blogger
KamilAdryjanek.com
Football amateur
Kamil Adryjanek <kamil@level7systems.pl>
Level 7 Systems LtdLevel 7 Systems Ltd
Level 7 Systems delivers business and residential communication
services based on the SIP technology.
VoIPstudio is a next generation communication platform tailored to a specific
business requirements
Powerful SIP Trunking solution for inbound and outbound calls aimed at
companies which have their own PBX.
Kamil Adryjanek <kamil@level7systems.pl>
We are hiring!We are hiring!
1)Junior PHP / Symfony2 developer
2)PHP / Symfony2 developer
Kamil Adryjanek <kamil@level7systems.pl>
AgendaAgenda
1) Why we should write tests?
2) What is TDD?
3) What is BDD?
4) StoryBDD with Behat
5) SpecBDD with PhpSpec
Kamil Adryjanek <kamil@level7systems.pl>
TestingTesting
„There are two types of programmers:
those who write tests,
and those who will be writing tests.”
Kamil Adryjanek <kamil@level7systems.pl>
TestingTesting
Why should we write tests?
Why don't we write tests?
Kamil Adryjanek <kamil@level7systems.pl>
TestingTesting
Kamil Adryjanek <kamil@level7systems.pl>
TestingTesting
How to write tests?
Kamil Adryjanek <kamil@level7systems.pl>
Test-Driven DevelopmentTest-Driven Development
Tests go first...
Kamil Adryjanek <kamil@level7systems.pl>
Test-Driven DevelopmentTest-Driven Development
Kamil Adryjanek <kamil@level7systems.pl>
Test-Driven DevelopmentTest-Driven Development
How to write tests for something that
does not exist?
Kamil Adryjanek <kamil@level7systems.pl>
The projectThe project
Kamil Adryjanek <kamil@level7systems.pl>
The project – customer needsThe project – customer needs
Kamil Adryjanek <kamil@level7systems.pl>
The projectThe project
The first step in every project is a discussion
about the behaviors of the software or feature
to be built.
Kamil Adryjanek <kamil@level7systems.pl>
Behaviour-Driven DevelopmentBehaviour-Driven Development
BDD is a methodology for developing software
through continuous example-based
communication between developers and a
business. This communication happens in a form
that both the business and developers can
clearly understand - examples
Kamil Adryjanek <kamil@level7systems.pl>
BDDBDD
Business Development
requirements
examples
Kamil Adryjanek <kamil@level7systems.pl>
BDDBDD
●
Better understanding of business
●
Better ideas
●
Developers can improve system
●
Developers can help business
Kamil Adryjanek <kamil@level7systems.pl>
TDD vs BDDTDD vs BDD
●
TDD focuses on the DEVELOPER's opinion
on how parts of the software should work
●
BDD focuses on the USERs’ opinion on how
they want your application to behave.
Kamil Adryjanek <kamil@level7systems.pl>
Evolution of TDDEvolution of TDD
StoryBDD ~ functional testing
SpecBDD ~ unit testing
Instead of writing tests you should think of
specifying behavior.
Kamil Adryjanek <kamil@level7systems.pl>
StoryBDDStoryBDD
Scenarios (examples) go first...
Kamil Adryjanek <kamil@level7systems.pl>
StoryBDDStoryBDD
StoryBDD helps ensuring that development team
has understanding of business on the same level
that client does
Kamil Adryjanek <kamil@level7systems.pl>
What is Behat?What is Behat?
● Open Source framwork
●
official BDD tool for PHP
● design tool (design by example)
● inspired by Ruby’s Cucumber project
●
easy integration with Symfony framework
Kamil Adryjanek <kamil@level7systems.pl>
BehatBehat
Is Behat a testing tool for business?
Kamil Adryjanek <kamil@level7systems.pl>
BehatBehat
No, Behat is about communication
between business and development.
Kamil Adryjanek <kamil@level7systems.pl>
Behat - installationBehat - installation
composer require --dev behat/behat
composer require --dev behat/mink
composer require --dev behat/mink-extension
Kamil Adryjanek <kamil@level7systems.pl>
Behat scenarioBehat scenario
Scenario: Some description of the scenario
Given some context
When some event
Then outcome
Kamil Adryjanek <kamil@level7systems.pl>
Behat scenarioBehat scenario
Scenario: Some description of the scenario
Given some context
And more context
When some event
And second event occurs
Then outcome
And another outcome
But another outcome
Kamil Adryjanek <kamil@level7systems.pl>
BehatBehat
How does it work?
Kamil Adryjanek <kamil@level7systems.pl>
Behat – context classBehat – context class
Kamil Adryjanek <kamil@level7systems.pl>
Behat – translationBehat – translation
Kamil Adryjanek <kamil@level7systems.pl>
FeatureFeature
I want to be able to log in with username and
password via login page
Kamil Adryjanek <kamil@level7systems.pl>
Behat featureBehat feature
In order to access admin dashboard
As user
I need to be able to log in
Kamil Adryjanek <kamil@level7systems.pl>
Scenario 1: login formScenario 1: login form
Scenario: login form
Given I am on the „homepage” page
When I press „Login”
Then I should be on the „Login” page
And I should see „email” field
And I should see „password” field
And I should see „Login” button
Kamil Adryjanek <kamil@level7systems.pl>
Scenario 2 – unsuccessful loginScenario 2 – unsuccessful login
Scenario: Login with empty data
Given I am on the „Login” page
When I press „Login”
Then I should still be on the „Login” page
And I should see „E-mail and/or password is required.”
Kamil Adryjanek <kamil@level7systems.pl>
Scenario 3 – successful loginScenario 3 – successful login
Scenario: successful login to admin panel
Given I am on the „Login” page
When I fill in "email" with: "user@example.com"
And I fill in "password" with: "$secret"
And I press „Login”
Then I should be on the „Dashboard” page
And I should see „Admin dashboard”
Kamil Adryjanek <kamil@level7systems.pl>
BehatBehat
What about „testing” REST API?
Kamil Adryjanek <kamil@level7systems.pl>
FeatureFeature
I want to be able to register customer account
via REST API
Kamil Adryjanek <kamil@level7systems.pl>
Behat featureBehat feature
In order to list my CDRs
As api user
I need to be able to register customer
Kamil Adryjanek <kamil@level7systems.pl>
Scenario 1 – invalid HTTP methodScenario 1 – invalid HTTP method
Scenario: register with invalid method
Given I am not authenticated
When I send GET request to „/customers”
Then the response status code should be 405
Kamil Adryjanek <kamil@level7systems.pl>
Scenario 2 – POST empty dataScenario 2 – POST empty data
Scenario: register customer with empty data
Given I am not authenticated
When I send POST request to „/customers”
Then the response status code should be 400
And only following properties should exist:
message
errors
And the „message” property should contain
„Validation errors.”
And the „errors” property should be array with „2”
elements
Kamil Adryjanek <kamil@level7systems.pl>
Scenario 3 – successful registrationScenario 3 – successful registration
Scenario: successful customer registration
Given I am not authenticated
When I send POST request to „/customers” with data:
email: user@example.com
password: $ecret
And the response status should be 201
And only following properties should exist:
data
links
Kamil Adryjanek <kamil@level7systems.pl>
Bug-Driven Development?
Kamil Adryjanek <kamil@level7systems.pl>
BehatBehat
1) Create scenario that will produce a „bug”
2) Run Behat scenario that will fail
3) Fix the bug / refactor
4) Go to step 2 until scenario passes
Kamil Adryjanek <kamil@level7systems.pl>
What about code specification?
Kamil Adryjanek <kamil@level7systems.pl>
SpecBDDSpecBDD
(Code) specifications go first...
Kamil Adryjanek <kamil@level7systems.pl>
What is PhpSpec?What is PhpSpec?
● Open Source framwork
● design tool (design by specification)
● allows to describe the behaviour of an object
you are about to write / create
● inspired by Ruby’s RSpec project
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpecPhpSpec
Create (design) simple class for storing tasks
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec - featurePhpSpec - feature
We are going to implement a class that:
● will store a collection of tasks;
● we can add a task to;
● can be marked as done.
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec - installationPhpSpec - installation
● create composer.json file:
● and install:
composer install
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – describePhpSpec – describe
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – runPhpSpec – run
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – treePhpSpec – tree
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – TaskCollectionSpecPhpSpec – TaskCollectionSpec
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – specifyPhpSpec – specify
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – runPhpSpec – run
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – runPhpSpec – run
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – runPhpSpec – run
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – TaskCollectionPhpSpec – TaskCollection
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – codePhpSpec – code
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – TaskCollectionPhpSpec – TaskCollection
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – specifyPhpSpec – specify
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – runPhpSpec – run
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – Task interfacePhpSpec – Task interface
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – runPhpSpec – run
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – runPhpSpec – run
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – codePhpSpec – code
Kamil Adryjanek <kamil@level7systems.pl>
PhpSpec – runPhpSpec – run
Kamil Adryjanek <kamil@level7systems.pl>
Sylius and Behat / PhpSpecSylius and Behat / PhpSpec
Kamil Adryjanek <kamil@level7systems.pl>
Thank you!

Contenu connexe

En vedette

Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2
Fabien Potencier
 

En vedette (18)

BDD in Symfony2
BDD in Symfony2BDD in Symfony2
BDD in Symfony2
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 
Programacion Web con Haskell
Programacion Web con HaskellProgramacion Web con Haskell
Programacion Web con Haskell
 
BDD, Behat & Drupal
BDD, Behat & DrupalBDD, Behat & Drupal
BDD, Behat & Drupal
 
Madison neighborhood conference, 2014
Madison neighborhood conference, 2014Madison neighborhood conference, 2014
Madison neighborhood conference, 2014
 
Symfony 3 est sorti! Forum PHP 2015
Symfony 3 est sorti! Forum PHP 2015Symfony 3 est sorti! Forum PHP 2015
Symfony 3 est sorti! Forum PHP 2015
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2
 
Test Driven Development for Embedded C
Test Driven Development for Embedded CTest Driven Development for Embedded C
Test Driven Development for Embedded C
 
TDD, BDD, RSpec
TDD, BDD, RSpecTDD, BDD, RSpec
TDD, BDD, RSpec
 
Double Loop: TDD & BDD Done Right!
Double Loop: TDD & BDD Done Right!Double Loop: TDD & BDD Done Right!
Double Loop: TDD & BDD Done Right!
 
Testing and symfony2
Testing and symfony2Testing and symfony2
Testing and symfony2
 
You Shall Not Pass - Security in Symfony
You Shall Not Pass - Security in SymfonyYou Shall Not Pass - Security in Symfony
You Shall Not Pass - Security in Symfony
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
 
TDD, BDD and mocks
TDD, BDD and mocksTDD, BDD and mocks
TDD, BDD and mocks
 
Test driven development in meteor
Test driven development in meteorTest driven development in meteor
Test driven development in meteor
 
BDD presentation
BDD presentationBDD presentation
BDD presentation
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
 

Similaire à TDD with BDD in PHP and Symfony

Onlne Retail Management By Jitendra
Onlne Retail Management By JitendraOnlne Retail Management By Jitendra
Onlne Retail Management By Jitendra
Jitendra
 
Create ABS Project In Twenty Minutes
Create ABS Project In Twenty MinutesCreate ABS Project In Twenty Minutes
Create ABS Project In Twenty Minutes
BENOIS Jérôme
 

Similaire à TDD with BDD in PHP and Symfony (20)

Onlne Retail Management By Jitendra
Onlne Retail Management By JitendraOnlne Retail Management By Jitendra
Onlne Retail Management By Jitendra
 
Using Clojure, NoSQL Databases and Functional-Style JavaScript to Write Gext-...
Using Clojure, NoSQL Databases and Functional-Style JavaScript to Write Gext-...Using Clojure, NoSQL Databases and Functional-Style JavaScript to Write Gext-...
Using Clojure, NoSQL Databases and Functional-Style JavaScript to Write Gext-...
 
Level Up Your Biml: Best Practices and Coding Techniques (SQLSaturday Minnesota)
Level Up Your Biml: Best Practices and Coding Techniques (SQLSaturday Minnesota)Level Up Your Biml: Best Practices and Coding Techniques (SQLSaturday Minnesota)
Level Up Your Biml: Best Practices and Coding Techniques (SQLSaturday Minnesota)
 
I Love APIs - Oct 2015
I Love APIs - Oct 2015I Love APIs - Oct 2015
I Love APIs - Oct 2015
 
Learn to build a CodeIgniter Login and Registration with source code.pdf
Learn to build a CodeIgniter Login and Registration with source code.pdfLearn to build a CodeIgniter Login and Registration with source code.pdf
Learn to build a CodeIgniter Login and Registration with source code.pdf
 
Afupday lille-2020
Afupday lille-2020Afupday lille-2020
Afupday lille-2020
 
C# with Renas
C# with RenasC# with Renas
C# with Renas
 
Aws Deployment Tools - Overview, Details, Implementation
Aws Deployment Tools - Overview, Details, ImplementationAws Deployment Tools - Overview, Details, Implementation
Aws Deployment Tools - Overview, Details, Implementation
 
Rebuilding our Foundation
Rebuilding our FoundationRebuilding our Foundation
Rebuilding our Foundation
 
Yii2 by Peter Jack Kambey
Yii2 by Peter Jack KambeyYii2 by Peter Jack Kambey
Yii2 by Peter Jack Kambey
 
Bridging the gap between business and technology - Behaviour Driven Developme...
Bridging the gap between business and technology - Behaviour Driven Developme...Bridging the gap between business and technology - Behaviour Driven Developme...
Bridging the gap between business and technology - Behaviour Driven Developme...
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
 
PHP CE 2018 - Building Symfony application with Ports and Adapters approach a...
PHP CE 2018 - Building Symfony application with Ports and Adapters approach a...PHP CE 2018 - Building Symfony application with Ports and Adapters approach a...
PHP CE 2018 - Building Symfony application with Ports and Adapters approach a...
 
Agile software architecture
Agile software architectureAgile software architecture
Agile software architecture
 
Level Up Your Biml: Best Practices and Coding Techniques (SQLDay 2018)
Level Up Your Biml: Best Practices and Coding Techniques (SQLDay 2018)Level Up Your Biml: Best Practices and Coding Techniques (SQLDay 2018)
Level Up Your Biml: Best Practices and Coding Techniques (SQLDay 2018)
 
ColdFusion 11 Overview - CFSummit 2013
ColdFusion 11 Overview - CFSummit 2013ColdFusion 11 Overview - CFSummit 2013
ColdFusion 11 Overview - CFSummit 2013
 
Create ABS Project In Twenty Minutes
Create ABS Project In Twenty MinutesCreate ABS Project In Twenty Minutes
Create ABS Project In Twenty Minutes
 
01 Introduction to programming
01 Introduction to programming01 Introduction to programming
01 Introduction to programming
 
Modular Web Applications With Netzke
Modular Web Applications With NetzkeModular Web Applications With Netzke
Modular Web Applications With Netzke
 
Web Components: back to the future
Web Components: back to the futureWeb Components: back to the future
Web Components: back to the future
 

Dernier

Dernier (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

TDD with BDD in PHP and Symfony