(don't worry about all the complexity) All features are tested You reduce bugs and regressions rate Your code stays clean Your code is documented And last but not least, you're more confident in making changes!
hell c l a s s V e n d o r _ M o d u l e _ M o d e l _ S o m e t h i n g e x t e n d s M a g e _ C o r e _ M o d e l _ A b s t r a c t { p u b l i c f u n c t i o n d o S o m e t h i n g W i t h P r o d u c t ( $ p r o d u c t I d ) { $ p r o d u c t = M a g e : : g e t M o d e l ( ' c a t a l o g / p r o d u c t ' ) - > l o a d ( $ p r o d u c t I d ) ; / / d o s o m e t h i n g w i t h $ p r o d u c t } }
with dependency injection… c l a s s V e n d o r _ M o d u l e _ M o d e l _ S o m e t h i n g e x t e n d s M a g e _ C o r e _ M o d e l _ A b s t r a c t { p r o t e c t e d $ p r o d u c t M o d e l ; p u b l i c f u n c t i o n s e t P r o d u c t M o d e l ( M a g e _ C a t a l o g _ M o d e l _ P r o d u c t $ p r o d u c t M o d e l ) { $ t h i s - > p r o d u c t M o d e l = $ p r o d u c t M o d e l ; } p u b l i c f u n c t i o n d o S o m e t h i n g W i t h P r o d u c t ( $ p r o d u c t I d ) { $ p r o d u c t = $ t h i s - > p r o d u c t M o d e l - > l o a d ( $ p r o d u c t I d ) ; / / d o s o m e t h i n g w i t h $ p r o d u c t } }
with something like this: c l a s s V e n d o r _ M o d u l e _ T e s t s _ U n i t _ S o m e t h i n g T e s t e x t e n d s \ P H P U n i t _ F r a m e w o r k _ T e s t C a s e { p u b l i c f u n c t i o n t e s t D o S o m e t h i n g W i t h P r o d u c t ( ) { $ p r o d u c t M o d e l M o c k = $ t h i s - > g e t M o c k ( ' M a g e _ C a t a l o g _ M o d e l _ P r o d u c t ' ) ; $ p r o d u c t M o d e l M o c k - > e x p e c t s ( $ t h i s - > o n c e ( ) ) - > m e t h o d ( ' l o a d ' ) - > w i t h ( 1 ) - > w i l l ( $ t h i s - > r e t u r n V a l u e ( n e w M a g e _ C a t a l o g _ M o d e l _ P r o d u c t ( ) ) ) ; $ s o m e t h i n g M o d e l = n e w V e n d o r _ M o d u l e _ M o d e l _ S o m e t h i n g ( ) ; $ s o m e t h i n g M o d e l - > s e t P r o d u c t M o d e l ( $ p r o d u c t M o d e l M o c k ) ; $ s o m e t h i n g M o d e l - > d o S o m e t h i n g W i t h P r o d u c t ( 1 ) ; / / a s s e r t t h a t s o m e t h i n g h a s b e e n d o n e } }
a p p / c o d e / l o c a l / V e n d o r / M o d u l e / e t c / c o n f i g . x m l - - > < p h p u n i t > < s u i t e > < m o d u l e s > < V e n d o r _ M o d u l e / > < / m o d u l e s > < / s u i t e > < / p h p u n i t >
models, blocks and helpers EcomDev_PHPUnit_Test_Case_Config is for testing your module configuration EcomDev_PHPUnit_Test_Case_Controller is for testing your controller actions and layout rendering process
by EcomDev ( ): github.com/EcomDev/MageCI $ m a g e - c i i n s t a l l $ m a g e _ d i r $ m a g e _ v e r s i o n $ d b n a m e - u $ d b u s e r - p $ d b p a s s \ - o - c - t - r h t t p : / / m a g e - c i . e c o m d e v . o r g $ m a g e - c i i n s t a l l - m o d u l e $ m a g e _ d i r . $ m a g e - c i i n s t a l l - m o d u l e $ m a g e _ d i r \ h t t p s : / / g i t h u b . c o m / E c o m D e v / E c o m D e v _ P H P U n i t . g i t $ m a g e - c i p h p u n i t $ m a g e _ d i r