Successfully reported this slideshow.
Your SlideShare is downloading. ×

Emergent design with phpspec

Emergent design with phpspec

Download to read offline

Where does design fit in agile projects? What is refactoring and what isn't refactoring? What is the relationship between design and refactoring, and design and architecture? In this talk we will clarify these and other questions around emergent design and how a TDD/BDD tool like phpspec can help you with the process. We will look into how phpspec helps uncover smelly code and point in the direction of refactoring techniques to guide the design of flexible, testable and easy to extend object oriented PHP code – enabling developers to focus on what’s more valuable for the customer at all times and re-steer the direction of the product.

Where does design fit in agile projects? What is refactoring and what isn't refactoring? What is the relationship between design and refactoring, and design and architecture? In this talk we will clarify these and other questions around emergent design and how a TDD/BDD tool like phpspec can help you with the process. We will look into how phpspec helps uncover smelly code and point in the direction of refactoring techniques to guide the design of flexible, testable and easy to extend object oriented PHP code – enabling developers to focus on what’s more valuable for the customer at all times and re-steer the direction of the product.

Advertisement
Advertisement

More Related Content

Advertisement

Related Books

Free with a 30 day trial from Scribd

See all

Emergent design with phpspec

  1. 1. by@_md emergentdesignwith
  2. 2. Iworkhere Icontributehere Itweethere @_md MarcelloDuarte
  3. 3. it’s2007
  4. 4. @padraicb @tswicegood
  5. 5. aportforrspec
  6. 6. !== http://earthymoon.deviantart.com/art/Elephant-png-122633500 http://sonylisation.deviantart.com/art/Ruby-Nr-2-207831683
  7. 7. bowling.score.should eq(0)
  8. 8. inrubyeverythingisanobject andallobjectsareopen bowling.score.should eq(0)
  9. 9. inrubyeverythingisanobject andallobjectsareopen http://www.flickr.com/photos/owenbooth/126288240/ bowling.score.should eq(0)
  10. 10. inrubyeverythingisanobject andallobjectsareopen http://www.flickr.com/photos/owenbooth/126288240/ bowling.score.should eq(0)
  11. 11. $this->spec($bowling->getScore()) ->shouldEqual(0); PHPSPECEARLYSYNTAXEXAMPLE
  12. 12. http://www.flickr.com/photos/jamesrbowe/8403688026/ amber... red... green...
  13. 13. 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
  14. 14. yougottabemockingme!
  15. 15. 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);
  16. 16. @_md @everzet
  17. 17. goals { funtoworkwith
  18. 18. goals {developmenttool funtoworkwith
  19. 19. goals {developmenttool let’snotgetintheway funtoworkwith
  20. 20. goals {enforce(mockist)TDD developmenttool let’snotgetintheway funtoworkwith
  21. 21. goals {enforce(mockist)TDD doitthePHPway developmenttool let’snotgetintheway funtoworkwith
  22. 22. { "require-dev": { "phpspec/phpspec": "2.0.*@dev" }, "config": { "bin-dir": "bin" }, "autoload": { "psr-0": { "": "src" } } }
  23. 23. $ bin/phpspec describe Some/Class$ bin/phpspec describe Some/Class
  24. 24. $ bin/phpspec describe Some/Class $ bin/phpspec run $ bin/phpspec describe Some/Class $ bin/phpspec run
  25. 25. $ bin/phpspec describe Some/Class $ bin/phpspec run phpspec generators $ bin/phpspec describe Some/Class $ bin/phpspec run phpspec generators
  26. 26. $ 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
  27. 27. $ 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
  28. 28. $ 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
  29. 29. littledemo
  30. 30. emergentdesign
  31. 31. designemergeiterativelydrivenbytests
  32. 32. design is ...
  33. 33. designsoftware is ...
  34. 34. designsoftware is todescribehowwe’resolvingaproblem
  35. 35. calculatecostvarianceforaperiod
  36. 36. calculatecostvarianceforaperiod Period
  37. 37. firstlearndesign,thenemergentdesign
  38. 38. “Key in making great and growable systems is to design how its modules communicate [andnot]whattheirpropertiesandbehavioursshouldbe.” Messaging ViewpointsResearchInstituteSource-BonnieMacbirdURL-http://www.vpri.org
  39. 39. messaging
  40. 40. $this->person->getCar()->getEngine()->ignite();
  41. 41. focusonmessaging makesthecodeflexible
  42. 42. $this->person->startCar();
  43. 43. describinghowobjectsinteracttosolveproblems whichroles,responsibilitiesandmessages designsoftware is
  44. 44. bigdesignupfront
  45. 45. IT’SHARDTOCHANGELATER.
  46. 46. WENEEDTOTHINKABOUTTHINGSBEFOREDEVELOPING.
  47. 47. WENEEDTOMAKESUREWEDON’TMISSANYTHING.
  48. 48. THISISJUSTTHEWAYWEDOIT.
  49. 49. relativecostofrepaircost time analysis design code test deploy rework $
  50. 50. yagni
  51. 51. 61% oftherequestedfeaturesareactuallydelivered [Standish Group Report 06]
  52. 52. 27% ofrequestedfeaturesareactuallyused
  53. 53. 5% to 10% areresponsibleforrealisingthebenefitsenvisioned
  54. 54. designforthehighpriorityitems andmakeiteasytochangelater
  55. 55. describinghowobjectsinteracttosolveproblems whichroles,responsibilitiesandmessages inachange-friendlyway designsoftwareinagile is
  56. 56. easiersaidthandone?
  57. 57. test coderefactor
  58. 58. usesimpledesignrulestorefactor 1.Alltestsrunandpass 2.Removeduplication 3.Removeopacity 4.Removecomplexity
  59. 59. resultsincode 1.Testable 2.Modular 3.Expressive 4.Simple
  60. 60. lackoftestsbreaksinnerquality 1.Viscosity 2.Immobility,Rigidity,Fragility 3.Unreadable 4.Complex
  61. 61. simpledesignisgreattodetectsmells
  62. 62. simpledesign 1.Alltestsrunandpass 2.Removeduplication 3.Removeopacity 4.Removecomplexity smells 1. Anytestssmells? 2.AnyDRYsmells? 3.Anyopacitysmells? 4.Anycomplexitysmells?
  63. 63. TestSmells • Lackoftests • Testsarenotunitary • Setupistoocomplex • Unclearexercise • Morethanoneexpectationina test • Noexpectation • Toomanypaths
  64. 64. DrySmells • Simpleduplication • Logicduplication • Duplicationofconstant • Alternativeclasseswithdifferentinterfaces
  65. 65. OpacitySmells • Namenotfromdomain • Namenotexpressingintent • Featureenvy • Methoddoesmorethanone thing • Methodtoolong • Primitiveobsession • Commentsinthecode • MiddleMan
  66. 66. ComplexitySmells • Unnecessaryelse • Unnecessaryif • Unnecessaryswitch • Toomanyargumentspassed • InappropriateIntimacy • Workinconstruction • Staticcontext
  67. 67. usedesignpatternstorefactor
  68. 68. creational?behavioural?structural?
  69. 69. whatcanhappeninamethod?
  70. 70. returnavalue modifystate printsomething throwanexception delegate {methods
  71. 71. returnavalue modifystate printsomething throwanexception delegate {methods notthefinal behaviour
  72. 72. returnavalue printsomething throwanexception delegate{methods weshouldprobably delegatethattoo
  73. 73. returnavalue throwanexception delegate{methods
  74. 74. designdelegationwithmocks
  75. 75. startbydefiningbehaviour
  76. 76. internallydelegatetoanothermethod
  77. 77. Finally • Definenewrole • Extractcollaboratorsusingmocks • Movebehaviourdefinitiontonewcollaboratortest
  78. 78. phpspec emergentdesign simpledesignandsmells designingcompositionwithmocks
  79. 79. MarcelloDuarte Iworkhere Icontributehere Itweethere @_md
  80. 80. Thankyou!
  81. 81. QuestionsorComments? wanttolearnmore?bitly.com/inviqa-bdd-training @_md joind.in/8459

×