SlideShare a Scribd company logo
1 of 51
Download to read offline
SPEC BDD
IN PHP
@cakper
13/06/13 GliwiceSpec BDD IN PHP
Software Engineer @SensioLabsUK
Silesia PHP User Group // Spug.pl
#symfony-pl // Symfonylab.pl
@CAKPER
13/06/13 GliwiceSpec BDD IN PHP
WHAT IS TEST?
13/06/13 GliwiceSpec BDD IN PHP
WHY DO WE TEST?
13/06/13 GliwiceSpec BDD IN PHP
HOW DO WE TEST?
13/06/13 GliwiceSpec BDD IN PHP
WE MAKE MISTAKES
SO WE HAVE TO TEST
13/06/13 GliwiceSpec BDD IN PHP
TEST
DRIVEN
DEVELOPMENT
Kent Beck // 2003
Extreme Programming // 1999
13/06/13 GliwiceSpec BDD IN PHP
PROBLEM #1
How to test something that
does not exist?
13/06/13 GliwiceSpec BDD IN PHP
PROBLEM #1
TEST == Specification
Driven
Development
13/06/13 GliwiceSpec BDD IN PHP
PROBLEM #1
Communication
is our ProblemNot testing itself
13/06/13 GliwiceSpec BDD IN PHP
BEHAVIOUR
DRIVEN
DEVELOPMENT
Dan North // 2006
13/06/13 GliwiceSpec BDD IN PHP
BDD
Naming
ConvenTions
tools
Better
{
13/06/13 GliwiceSpec BDD IN PHP
BDD
= TDD v2.0‘TDD DONE RIGHT’
13/06/13 GliwiceSpec BDD IN PHP
PROBLEM #2
Writing specifications
takes time
Time is a cost
13/06/13 GliwiceSpec BDD IN PHP
you can learn it
13/06/13 GliwiceSpec BDD IN PHP
DELIBERATE PRACTICE
Pair Programming
Code Kata
Code Club
Code Retreat
13/06/13 GliwiceSpec BDD IN PHP
PROBLEM #3
Why are you sure that your
test is correct?
13/06/13 GliwiceSpec BDD IN PHP
TDD CYCLE
RED
GREENREFACTOR
13/06/13 GliwiceSpec BDD IN PHP
3 LAWS OF TDD
1.You are not allowed to write any production
code unless it is to make a failing unit test pass.
2.You are not allowed to write any more of a unit
test than is sufficient to fail; and compilation
failures are failures.
3.You are not allowed to write any more
production code than is sufficient to pass the one
failing unit test.
13/06/13 GliwiceSpec BDD IN PHP
PROBLEM #4
When and how to Refactor?
13/06/13 GliwiceSpec BDD IN PHP
‘Refactoring w/o tests
= Refucktoring’
PROBLEM #4
13/06/13 GliwiceSpec BDD IN PHP
4 RULES OF SIMPLE DESING
1.Passes all the tests.
2.Express every idea we need to express.
3.Contains no duplication.
4.Minimized the number of classes,
methods and other moving parts.
13/06/13 GliwiceSpec BDD IN PHP
PROBLEM #5
How to test dependencies?
13/06/13 GliwiceSpec BDD IN PHP
DO NOT TEST...
13/06/13 GliwiceSpec BDD IN PHP
TEST DOUBLES
DUMMies
STUBS
MOCKS
SPIES
13/06/13 GliwiceSpec BDD IN PHP
Mocking should be easy
very easy
13/06/13 GliwiceSpec BDD IN PHP
PROBLEM #6
Code Coverage
13/06/13 GliwiceSpec BDD IN PHP
PROBLEM #6
Useful to
find dead code ;)
13/06/13 GliwiceSpec BDD IN PHP
PROBLEM #7
STORY BDD
vs
Spec BDD
13/06/13 GliwiceSpec BDD IN PHP
STORY BDD
description of
business-targeted
application behavior
13/06/13 GliwiceSpec BDD IN PHP
SPEC BDD
specification for
low-level implementation
13/06/13 GliwiceSpec BDD IN PHP
PROBLEM #8
PHP UNIT
By Sebastian Bergmann©
13/06/13 GliwiceSpec BDD IN PHP
PHP Spec 2
13/06/13 GliwiceSpec BDD IN PHP
PHP SPEC 2
Framework Spec BDD
@_md & @everzet
Prophecy
13/06/13 GliwiceSpec BDD IN PHP
PHP SPEC 2
EASY to use
TDD-Cycle oriented
Behaviour focused
13/06/13 GliwiceSpec BDD IN PHP
PHP SPEC 2
Test Case
Specification
13/06/13 GliwiceSpec BDD IN PHP
PHP SPEC 2
Test
example
13/06/13 GliwiceSpec BDD IN PHP
PHP SPEC 2
Assert
Expectation
13/06/13 GliwiceSpec BDD IN PHP
PHP SPEC 2
class MarkdownSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Markdown');
}
}
13/06/13 GliwiceSpec BDD IN PHP
MATCHERS
Identity (===):
shouldReturn()
shouldBe()
shouldEqual()
shouldBeEqualTo()
13/06/13 GliwiceSpec BDD IN PHP
MATCHERS
Comparison (==):
shouldBeLike()
13/06/13 GliwiceSpec BDD IN PHP
MATCHERS
Throw:
shouldThrow(‘Exception’)
->duringSomeMethod()
13/06/13 GliwiceSpec BDD IN PHP
MATCHERS
Type:
shouldBeAnInstanceOf()
shouldReturnAnInstanceOf()
shouldHaveType()
13/06/13 GliwiceSpec BDD IN PHP
MATCHERS
Object State:
shouldHave**()
13/06/13 GliwiceSpec BDD IN PHP
TEST DOUBLES
/**
* @param MarkdownStream $stream
*/
function it_adds_a_end_of_list_to_markup($stream)
{
$stream->getNextLine()->willReturn("");
$this->format(" * Hi, there", $stream)
->shouldReturn("</li></ul>");
}
13/06/13 GliwiceSpec BDD IN PHP
LET & LETGO
function let($die)
{
$die->beADoubleOf('Die');
$this->beConstructedWith($die);
}
function it_live_and_let_die($die)
{
$this->liveAndLet()->shouldReturn($die);
}
function letgo(){}
13/06/13 GliwiceSpec BDD IN PHP
PHP SPEC 2
{
"require-dev": {
"phpspec/phpspec": "2.0.*@dev"
},
"config": {
"bin-dir": "bin"
},
"autoload": {"psr-0": {"": "src"}}
}
13/06/13 GliwiceSpec BDD IN PHP
Demo
13/06/13 GliwiceSpec BDD IN PHP
Questions?
13/06/13 GliwiceSpec BDD IN PHP
WE ARE HIRING!
Software Engineer
Front-end Engineer
Software Engineer in test
PRoject manager
Business analyst
www.sensiolabs.co.uk
www.inviqa.com
THANK YOU!
@cakper

More Related Content

Viewers also liked

Viewers also liked (9)

PhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examplesPhpSpec 2.0 ilustrated by examples
PhpSpec 2.0 ilustrated by examples
 
PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)
PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)
PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)
 
Emergent design with phpspec
Emergent design with phpspecEmergent design with phpspec
Emergent design with phpspec
 
Object Calisthenics Applied to PHP
Object Calisthenics Applied to PHPObject Calisthenics Applied to PHP
Object Calisthenics Applied to PHP
 
Mocking Demystified
Mocking DemystifiedMocking Demystified
Mocking Demystified
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
 
AngularJS 2, version 1 and ReactJS
AngularJS 2, version 1 and ReactJSAngularJS 2, version 1 and ReactJS
AngularJS 2, version 1 and ReactJS
 
PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersPHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4Developers
 
TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016
 

Similar to SpecBDD in PHP

NodeWay in my project & sails.js
NodeWay in my project & sails.jsNodeWay in my project & sails.js
NodeWay in my project & sails.js
Dmytro Ovcharenko
 
Cross Platform Mobile Development for Business Applications
Cross Platform Mobile Development for Business ApplicationsCross Platform Mobile Development for Business Applications
Cross Platform Mobile Development for Business Applications
David Karlsson
 
Puppet Camp Amsterdam 2015: Improving In Production Puppet Code Without Break...
Puppet Camp Amsterdam 2015: Improving In Production Puppet Code Without Break...Puppet Camp Amsterdam 2015: Improving In Production Puppet Code Without Break...
Puppet Camp Amsterdam 2015: Improving In Production Puppet Code Without Break...
Puppet
 

Similar to SpecBDD in PHP (20)

PhpStorm for WordPress
PhpStorm for WordPressPhpStorm for WordPress
PhpStorm for WordPress
 
Code Dojo
Code DojoCode Dojo
Code Dojo
 
Writing Performant Front-end Code
Writing Performant Front-end CodeWriting Performant Front-end Code
Writing Performant Front-end Code
 
NodeWay in my project & sails.js
NodeWay in my project & sails.jsNodeWay in my project & sails.js
NodeWay in my project & sails.js
 
apidays LIVE Hong Kong - Let's get started development of API client library ...
apidays LIVE Hong Kong - Let's get started development of API client library ...apidays LIVE Hong Kong - Let's get started development of API client library ...
apidays LIVE Hong Kong - Let's get started development of API client library ...
 
Droidcon Italy 2014 on Train
Droidcon Italy 2014 on TrainDroidcon Italy 2014 on Train
Droidcon Italy 2014 on Train
 
Cross Platform Mobile Development for Business Applications
Cross Platform Mobile Development for Business ApplicationsCross Platform Mobile Development for Business Applications
Cross Platform Mobile Development for Business Applications
 
Phpers day 2019
Phpers day 2019Phpers day 2019
Phpers day 2019
 
Feedback from an eclipse plugin developer to provide support to large set of ...
Feedback from an eclipse plugin developer to provide support to large set of ...Feedback from an eclipse plugin developer to provide support to large set of ...
Feedback from an eclipse plugin developer to provide support to large set of ...
 
Atlassian: The latest and greatest - May/June 2013
Atlassian: The latest and greatest - May/June 2013Atlassian: The latest and greatest - May/June 2013
Atlassian: The latest and greatest - May/June 2013
 
Rise of the Nodebots
Rise of the NodebotsRise of the Nodebots
Rise of the Nodebots
 
Bow
BowBow
Bow
 
Puppet Camp Amsterdam 2015: Improving In Production Puppet Code Without Break...
Puppet Camp Amsterdam 2015: Improving In Production Puppet Code Without Break...Puppet Camp Amsterdam 2015: Improving In Production Puppet Code Without Break...
Puppet Camp Amsterdam 2015: Improving In Production Puppet Code Without Break...
 
Beginners guide-to-reverse-engineering-android-apps-pau-oliva-fora-viaforensi...
Beginners guide-to-reverse-engineering-android-apps-pau-oliva-fora-viaforensi...Beginners guide-to-reverse-engineering-android-apps-pau-oliva-fora-viaforensi...
Beginners guide-to-reverse-engineering-android-apps-pau-oliva-fora-viaforensi...
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystem
 
Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...
Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...
Frontend Performance: Beginner to Expert to Crazy Person (San Diego Web Perf ...
 
Montreal.rb ruby debugging basics - march 20th 2012
Montreal.rb   ruby debugging basics - march 20th 2012Montreal.rb   ruby debugging basics - march 20th 2012
Montreal.rb ruby debugging basics - march 20th 2012
 
Flutter beers and pizza
Flutter beers and pizzaFlutter beers and pizza
Flutter beers and pizza
 
Pwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreakPwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreak
 
Measuring Code Quality in WTF/min.
Measuring Code Quality in WTF/min. Measuring Code Quality in WTF/min.
Measuring Code Quality in WTF/min.
 

More from Kacper Gunia

More from Kacper Gunia (14)

How a large corporation used Domain-Driven Design to replace a loyalty system
How a large corporation used Domain-Driven Design to replace a loyalty systemHow a large corporation used Domain-Driven Design to replace a loyalty system
How a large corporation used Domain-Driven Design to replace a loyalty system
 
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learned
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learnedRebuilding Legacy Apps with Domain-Driven Design - Lessons learned
Rebuilding Legacy Apps with Domain-Driven Design - Lessons learned
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
 
The top 10 things that any pro PHP developer should be doing
The top 10 things that any pro PHP developer should be doingThe top 10 things that any pro PHP developer should be doing
The top 10 things that any pro PHP developer should be doing
 
Embrace Events and let CRUD die
Embrace Events and let CRUD dieEmbrace Events and let CRUD die
Embrace Events and let CRUD die
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
 
Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!
Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!
Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!
 
OmniFocus - the #1 ‘Getting Things Done’ tool
OmniFocus - the #1 ‘Getting Things Done’ toolOmniFocus - the #1 ‘Getting Things Done’ tool
OmniFocus - the #1 ‘Getting Things Done’ tool
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
 
Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
 
November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2
 
Dependency Injection in PHP
Dependency Injection in PHPDependency Injection in PHP
Dependency Injection in PHP
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

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
 
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)
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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?
 
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
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

SpecBDD in PHP