SlideShare a Scribd company logo
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

PDF
Introduction to API
DOCX
Mesh Topology Design in Cisco Packet Tracer
PPTX
Spring jdbc
PDF
WordPress REST API hacking
PDF
Route Leak Prevension with BGP Community
PPTX
REST API Design & Development
PDF
Eigrp
PPT
Juniper mpls best practice part 2
Introduction to API
Mesh Topology Design in Cisco Packet Tracer
Spring jdbc
WordPress REST API hacking
Route Leak Prevension with BGP Community
REST API Design & Development
Eigrp
Juniper mpls best practice part 2

What's hot (20)

PPTX
MPLS L3 VPN Tutorial, by Nurul Islam Roman [APNIC 38]
PPTX
CCNA 200-301 IPv6 addressing and subnetting MCQs Collection
 
PPTX
BGP Traffic Engineering / Routing Optimisation
PDF
REST APIs with Spring
PPTX
Dynamic ARP Inspection (DAI)
PPTX
Spring & hibernate
PPTX
Introduction JavaEE
PDF
Scalable Service-Oriented Middleware over IP
PDF
Web develop in flask
PPTX
CCNP ROUTE V7 CH7
PPTX
Cisco-Protocolos de Enrutamiento
DOCX
Content Delivery Network – CDN
PPT
Mpls L3_vpn
PDF
CCNA - Switching Concepts made easy
PPTX
Port Security
PPTX
CCNA 1 Routing and Switching v5.0 Chapter 2
DOCX
Uart
PDF
Next Gen Monitoring with INT
PDF
UVM ARCHITECTURE FOR VERIFICATION
PPT
MPLS L3 VPN Tutorial, by Nurul Islam Roman [APNIC 38]
CCNA 200-301 IPv6 addressing and subnetting MCQs Collection
 
BGP Traffic Engineering / Routing Optimisation
REST APIs with Spring
Dynamic ARP Inspection (DAI)
Spring & hibernate
Introduction JavaEE
Scalable Service-Oriented Middleware over IP
Web develop in flask
CCNP ROUTE V7 CH7
Cisco-Protocolos de Enrutamiento
Content Delivery Network – CDN
Mpls L3_vpn
CCNA - Switching Concepts made easy
Port Security
CCNA 1 Routing and Switching v5.0 Chapter 2
Uart
Next Gen Monitoring with INT
UVM ARCHITECTURE FOR VERIFICATION
Ad

Viewers also liked (9)

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

Similar to SpecBDD in PHP (20)

PDF
It's all about behaviour, also in php - phpspec
PDF
PHPSpec BDD Framework
PDF
November Camp - Spec BDD with PHPSpec 2
PDF
Intro to PHP Testing
ODP
Tdd in php a brief example
PDF
Software Testing & PHPSpec
ODP
TDD in PHP - Memphis PHP 2011-08-25
PDF
TDD with PhpSpec
PDF
Behavioural Driven Development in Zf2
PDF
It should! - BDD in practice
PDF
New Features PHPUnit 3.3 - Sebastian Bergmann
 
ODP
PhpSpec: practical introduction
PDF
TDD with phpspec2
KEY
Developer testing 201: When to Mock and When to Integrate
PDF
BDD in open source projects - Is it really beneficial?
PPT
Getting Started with Test-Driven Development at Midwest PHP 2021
PPTX
BDD in my team: how we do it
KEY
PHPSpec BDD for PHP
PDF
BDD API Tests with Gherkin and Behat
PDF
Phpers day 2019
It's all about behaviour, also in php - phpspec
PHPSpec BDD Framework
November Camp - Spec BDD with PHPSpec 2
Intro to PHP Testing
Tdd in php a brief example
Software Testing & PHPSpec
TDD in PHP - Memphis PHP 2011-08-25
TDD with PhpSpec
Behavioural Driven Development in Zf2
It should! - BDD in practice
New Features PHPUnit 3.3 - Sebastian Bergmann
 
PhpSpec: practical introduction
TDD with phpspec2
Developer testing 201: When to Mock and When to Integrate
BDD in open source projects - Is it really beneficial?
Getting Started with Test-Driven Development at Midwest PHP 2021
BDD in my team: how we do it
PHPSpec BDD for PHP
BDD API Tests with Gherkin and Behat
Phpers day 2019

More from Kacper Gunia (14)

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

Recently uploaded (20)

PDF
Mushroom cultivation and it's methods.pdf
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Tartificialntelligence_presentation.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Machine Learning_overview_presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
Mushroom cultivation and it's methods.pdf
1. Introduction to Computer Programming.pptx
Programs and apps: productivity, graphics, security and other tools
NewMind AI Weekly Chronicles - August'25-Week II
Tartificialntelligence_presentation.pptx
Unlocking AI with Model Context Protocol (MCP)
Encapsulation_ Review paper, used for researhc scholars
A comparative analysis of optical character recognition models for extracting...
Group 1 Presentation -Planning and Decision Making .pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Network Security Unit 5.pdf for BCA BBA.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Machine Learning_overview_presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Assigned Numbers - 2025 - Bluetooth® Document
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Building Integrated photovoltaic BIPV_UPV.pdf

SpecBDD in PHP