Slide 1

Slide 1 text

Test Driven Development PHPUnit  

Slide 2

Slide 2 text

Testing Practices •  During  Development   •  During  Debugging    

Slide 3

Slide 3 text

Starting a Suite •  phpunit.xml   •  Logging   •  Directory  Structure   •  Package  Groups   •  Providers   – Comment  based  providers   – Protected  method  providers  

Slide 4

Slide 4 text

Types of Tests •  ExcepAons   –  Monitors  tests  for  expected  thrown  excepAons   •  Mocks   –  Observable  expectaAons  through  the  use  of  mocks   •  Errors   –  Watch  for  a  specific  error     •  AsserAons   –  Comparison  of  actual  and  expected  condiAons   –  Most  common  used  

Slide 5

Slide 5 text

During Development •  Behavior  Driven   – Define  what  this  package  does.   – Use  doc  tags  to  define  input  and  expected  output   – Generate  Test  Skeletons  once  completed   •  Test  Driven   – Create  the  tests  and  define  the  Class  and  methods   – Generate  your  classes  from  the  tests  once   complete  

Slide 6

Slide 6 text

DocBlock Assertions

Slide 7

Slide 7 text

Creating a Docblock

Slide 8

Slide 8 text

Docblock Assertions

Slide 9

Slide 9 text

Example of Test-Driven Development

Slide 10

Slide 10 text

Example of Test-Driven Development

Slide 11

Slide 11 text

During Debugging •  Duplicate  the  complaint   •  Write  a  test-­‐case  that  duplicates  the   complaint   •  Write  a  test-­‐case  that  should  break  but   doesn’t   •  Write  a  test-­‐case  that  should  not  break   •  When  all  test-­‐case  pass  the  bug  is  fixed   •  All  bug  related  tests  should  idenAfy  the  Acket  

Slide 12

Slide 12 text

Mocks and Stubs •  Why  have  mocks,  what  do  I  get  from  them?   – Ability  to  control  the  returns   – Test  the  number  of  Ames  a  method  is  used   – Test  how  a  mock  is  used.   – Eliminate  dependency  on  outside  methods  and   data  sources.   –  While  tesAng  the  return  of  an  outside  source  is  necessary  at   Ames  by  definiAon  a  ‘unit  test’  is  a  test  on  a  ‘Unit  of  Work’   and  fall  outside  the  scope  of  this  discussion.  

Slide 13

Slide 13 text

Testing, where to begin •  Your  next  customer  complaint.   •  New  development.   •  Troublesome  pieces  of  code.   •  Code  you  make  changes  to:   •  Make  a  test  to  validate  its  current  operaAon   •  Make  a  test  for  expected  change  performance   •  Make  your  changes,  test  and  repeat  All  it  works.  

Slide 14

Slide 14 text

Continuous Integration •  A  verificaAon  that  each  commit  (integraAon)   works   •  Validate  rules  adherence   •  It  is  only  as  good  as  the  tests!  

Slide 15

Slide 15 text

The Next Steps •  Zend_Test_PHPUnit_Db   •  Zend_Test_PHPUnit_Controller   •  Selenium   •  PHPUnit_Db  

Slide 16

Slide 16 text

Resources •  h"p://www.phpunit.de/   •  Test  Driven  Development.  David  Astels.   Copyright  ©  23.  PrenAce  Hall.  ISBN  0131016490.   •  xUnit  Test  Pa"erns:  Refactoring  Test  Code.   Gerard  Meszaros.  Copyright  ©  2007.  Addison-­‐ Wesley.  ISBN  978-­‐0131495050.   •  Test  Driven  Development  by  Example.  Kent   Beck.  Copyright  ©  2002.  Addison-­‐Wesley.  ISBN   0-­‐321-­‐14653-­‐0.