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

Emergent design with phpspec