SlideShare a Scribd company logo
1 of 83
Download to read offline
by@_md
emergentdesignwith
Iworkhere
Icontributehere
Itweethere @_md
MarcelloDuarte
it’s2007
@padraicb
@tswicegood
aportforrspec
!==
http://earthymoon.deviantart.com/art/Elephant-png-122633500 http://sonylisation.deviantart.com/art/Ruby-Nr-2-207831683
bowling.score.should eq(0)
inrubyeverythingisanobject
andallobjectsareopen
bowling.score.should eq(0)
inrubyeverythingisanobject
andallobjectsareopen
http://www.flickr.com/photos/owenbooth/126288240/
bowling.score.should eq(0)
inrubyeverythingisanobject
andallobjectsareopen
http://www.flickr.com/photos/owenbooth/126288240/
bowling.score.should eq(0)
$this->spec($bowling->getScore())
->shouldEqual(0);
PHPSPECEARLYSYNTAXEXAMPLE
http://www.flickr.com/photos/jamesrbowe/8403688026/
amber... red... green...
md@bossa:tests $ phpunit .
PHPUnit 3.7.14 by Sebastian Bergmann.
PHP Fatal error: Class 'Customer' not found
in /Users/mduarte/Documents/NoSync/Lab/phpunit/
tests/CustomerTest.php on line 8
Fatal error: Class 'Customer' not found in /
Users/mduarte/Documents/NoSync/Lab/phpunit/
tests/CustomerTest.php on line 8
yougottabemockingme!
public function testUpdateWithEqualTypes()
{
$installer = $this->createInstallerMock();
$manager = new InstallationManager('vendor');
$manager->addInstaller($installer);
$initial = $this->createPackageMock();
$target = $this->createPackageMock();
$operation = new UpdateOperation($initial, $target, 'test');
$initial
->expects($this->once())
->method('getType')
->will($this->returnValue('library'));
$target
->expects($this->once())
->method('getType')
->will($this->returnValue('library'));
$installer
->expects($this->once())
->method('supports')
->with('library')
->will($this->returnValue(true));
$installer
->expects($this->once())
->method('update')
->with($this->repository, $initial, $target);
@_md
@everzet
goals
{
funtoworkwith
goals
{developmenttool
funtoworkwith
goals
{developmenttool
let’snotgetintheway
funtoworkwith
goals
{enforce(mockist)TDD
developmenttool
let’snotgetintheway
funtoworkwith
goals
{enforce(mockist)TDD
doitthePHPway
developmenttool
let’snotgetintheway
funtoworkwith
{
"require-dev": {
"phpspec/phpspec": "2.0.*@dev"
},
"config": {
"bin-dir": "bin"
},
"autoload": {
"psr-0": {
"": "src"
}
}
}
$ bin/phpspec describe Some/Class$ bin/phpspec describe Some/Class
$ bin/phpspec describe Some/Class
$ bin/phpspec run
$ bin/phpspec describe Some/Class
$ bin/phpspec run
$ bin/phpspec describe Some/Class
$ bin/phpspec run
phpspec generators
$ bin/phpspec describe Some/Class
$ bin/phpspec run
phpspec generators
$ bin/phpspec describe Some/Class
$ bin/phpspec run
$ editor_of_choice . phpspec generators
$ bin/phpspec describe Some/Class
$ bin/phpspec run
$ editor_of_choice . phpspec generators
$ bin/phpspec describe Some/Class
$ bin/phpspec run
$ editor_of_choice . phpspec generators
$ bin/phpspec describe Some/Class
$ bin/phpspec run
$ editor_of_choice . phpspec generators
$ bin/phpspec describe Some/Class
$ bin/phpspec run
$ editor_of_choice . phpspec generators
$ bin/phpspec describe Some/Class
$ bin/phpspec run
$ editor_of_choice . phpspec generators
littledemo
emergentdesign
designemergeiterativelydrivenbytests
design
is
...
designsoftware
is
...
designsoftware
is
todescribehowwe’resolvingaproblem
calculatecostvarianceforaperiod
calculatecostvarianceforaperiod
Period
firstlearndesign,thenemergentdesign
“Key in making great and growable systems is to
design how its modules communicate
[andnot]whattheirpropertiesandbehavioursshouldbe.”
Messaging
ViewpointsResearchInstituteSource-BonnieMacbirdURL-http://www.vpri.org
messaging
$this->person->getCar()->getEngine()->ignite();
focusonmessaging
makesthecodeflexible
$this->person->startCar();
describinghowobjectsinteracttosolveproblems
whichroles,responsibilitiesandmessages
designsoftware
is
bigdesignupfront
IT’SHARDTOCHANGELATER.
WENEEDTOTHINKABOUTTHINGSBEFOREDEVELOPING.
WENEEDTOMAKESUREWEDON’TMISSANYTHING.
THISISJUSTTHEWAYWEDOIT.
relativecostofrepaircost
time
analysis design code test deploy rework
$
yagni
61%
oftherequestedfeaturesareactuallydelivered
[Standish Group Report 06]
27%
ofrequestedfeaturesareactuallyused
5% to 10%
areresponsibleforrealisingthebenefitsenvisioned
designforthehighpriorityitems
andmakeiteasytochangelater
describinghowobjectsinteracttosolveproblems
whichroles,responsibilitiesandmessages
inachange-friendlyway
designsoftwareinagile
is
easiersaidthandone?
test
coderefactor
usesimpledesignrulestorefactor
1.Alltestsrunandpass
2.Removeduplication
3.Removeopacity
4.Removecomplexity
resultsincode
1.Testable
2.Modular
3.Expressive
4.Simple
lackoftestsbreaksinnerquality
1.Viscosity
2.Immobility,Rigidity,Fragility
3.Unreadable
4.Complex
simpledesignisgreattodetectsmells
simpledesign
1.Alltestsrunandpass
2.Removeduplication
3.Removeopacity
4.Removecomplexity
smells
1. Anytestssmells?
2.AnyDRYsmells?
3.Anyopacitysmells?
4.Anycomplexitysmells?
TestSmells
• Lackoftests
• Testsarenotunitary
• Setupistoocomplex
• Unclearexercise
• Morethanoneexpectationina
test
• Noexpectation
• Toomanypaths
DrySmells
• Simpleduplication
• Logicduplication
• Duplicationofconstant
• Alternativeclasseswithdifferentinterfaces
OpacitySmells
• Namenotfromdomain
• Namenotexpressingintent
• Featureenvy
• Methoddoesmorethanone
thing
• Methodtoolong
• Primitiveobsession
• Commentsinthecode
• MiddleMan
ComplexitySmells
• Unnecessaryelse
• Unnecessaryif
• Unnecessaryswitch
• Toomanyargumentspassed
• InappropriateIntimacy
• Workinconstruction
• Staticcontext
usedesignpatternstorefactor
creational?behavioural?structural?
whatcanhappeninamethod?
returnavalue
modifystate
printsomething
throwanexception
delegate
{methods
returnavalue
modifystate
printsomething
throwanexception
delegate
{methods
notthefinal
behaviour
returnavalue
printsomething
throwanexception
delegate{methods
weshouldprobably
delegatethattoo
returnavalue
throwanexception
delegate{methods
designdelegationwithmocks
startbydefiningbehaviour
internallydelegatetoanothermethod
Finally
• Definenewrole
• Extractcollaboratorsusingmocks
• Movebehaviourdefinitiontonewcollaboratortest
phpspec
emergentdesign
simpledesignandsmells
designingcompositionwithmocks
MarcelloDuarte
Iworkhere
Icontributehere
Itweethere @_md
Thankyou!
QuestionsorComments?
wanttolearnmore?bitly.com/inviqa-bdd-training
@_md joind.in/8459

More Related Content

Viewers also liked

Neal Ford Emergent Design And Evolutionary Architecture
Neal Ford Emergent Design And Evolutionary ArchitectureNeal Ford Emergent Design And Evolutionary Architecture
Neal Ford Emergent Design And Evolutionary Architecture
Thoughtworks
 

Viewers also liked (16)

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
 
Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
 
How to switch stack without downtime
How to switch stack without downtimeHow to switch stack without downtime
How to switch stack without downtime
 
BDD in open source projects - Is it really beneficial?
BDD in open source projects - Is it really beneficial?BDD in open source projects - Is it really beneficial?
BDD in open source projects - Is it really beneficial?
 
SpecBDD in PHP
SpecBDD in PHPSpecBDD in PHP
SpecBDD in PHP
 
Software Testing & PHPSpec
Software Testing & PHPSpecSoftware Testing & PHPSpec
Software Testing & PHPSpec
 
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)
 
Story and Emergent Design
Story and Emergent DesignStory and Emergent Design
Story and Emergent Design
 
Driving Design with PhpSpec
Driving Design with PhpSpecDriving Design with PhpSpec
Driving Design with PhpSpec
 
TDD with PhpSpec
TDD with PhpSpecTDD with PhpSpec
TDD with PhpSpec
 
Hexagonal symfony
Hexagonal symfonyHexagonal symfony
Hexagonal symfony
 
Mocking Demystified
Mocking DemystifiedMocking Demystified
Mocking Demystified
 
Continuous Architecture and Emergent Design: Disciplined Agile Strategies
Continuous Architecture and Emergent Design: Disciplined Agile StrategiesContinuous Architecture and Emergent Design: Disciplined Agile Strategies
Continuous Architecture and Emergent Design: Disciplined Agile Strategies
 
Neal Ford Emergent Design And Evolutionary Architecture
Neal Ford Emergent Design And Evolutionary ArchitectureNeal Ford Emergent Design And Evolutionary Architecture
Neal Ford Emergent Design And Evolutionary Architecture
 
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
 
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
 

More from Marcello Duarte

More from Marcello Duarte (12)

Functional Structures in PHP
Functional Structures in PHPFunctional Structures in PHP
Functional Structures in PHP
 
Empathy from Agility
Empathy from AgilityEmpathy from Agility
Empathy from Agility
 
Introducing Eager Design
Introducing Eager DesignIntroducing Eager Design
Introducing Eager Design
 
Understanding Craftsmanship SwanseaCon2015
Understanding Craftsmanship SwanseaCon2015Understanding Craftsmanship SwanseaCon2015
Understanding Craftsmanship SwanseaCon2015
 
Barely Enough Design
Barely Enough DesignBarely Enough Design
Barely Enough Design
 
Transitioning to Agile
Transitioning to AgileTransitioning to Agile
Transitioning to Agile
 
Understanding craftsmanship
Understanding craftsmanshipUnderstanding craftsmanship
Understanding craftsmanship
 
The framework as an implementation detail
The framework as an implementation detailThe framework as an implementation detail
The framework as an implementation detail
 
Pair Programming, TDD and other impractical things
Pair Programming, TDD and other impractical thingsPair Programming, TDD and other impractical things
Pair Programming, TDD and other impractical things
 
Deliberate practice
Deliberate practiceDeliberate practice
Deliberate practice
 
BDD For Zend Framework With PHPSpec
BDD For Zend Framework With PHPSpecBDD For Zend Framework With PHPSpec
BDD For Zend Framework With PHPSpec
 
PHPSpec BDD Framework
PHPSpec BDD FrameworkPHPSpec BDD Framework
PHPSpec BDD Framework
 

Recently uploaded

Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 

Recently uploaded (20)

Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 

Emergent design with phpspec