Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Using of TDD practices for Magento

9,027 views

Published on

My Presentation from MeetMagento NL 2011

Published in: Technology, Business
  • D0WNL0AD FULL ▶ ▶ ▶ ▶ http://1lite.top/ufISj ◀ ◀ ◀ ◀
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/qURD } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/qURD } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download doc Ebook here { https://soo.gd/qURD } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • great presentation (and great extension).
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Using of TDD practices for Magento

  1. 1. Using of Test Driven DevelopmentPractices for Magento<br />Ivan Chepurnyi<br />Magento Trainer / Lead Developer<br />
  2. 2. Short Overview<br />Meet Magento Netherlands<br />Write a test<br />Imaging how your feature should work and write a failing test<br />Write feature quickly for receiving passed test<br />Refactor your code and run the test again<br />Pass<br />Run the tests<br />Fail<br />Pass<br />Write the code<br />Fail<br />Run the tests<br />
  3. 3. Conventional Development<br />Meet Magento Netherlands<br />You need to write a full functionality for seeing the result<br />You think that your code works<br />Debugging<br />With every fixed issue you may produce a new one<br />Even if you write unit tests after implementation it doesn’t guarantee that you detect the defect.<br />
  4. 4. Test Driven Development<br />Meet Magento Netherlands<br />You don’t need to implement full functionality for seeing the result<br />Your colleagues can use your test as learning material<br />The test proofs that your code works and can be verified<br />Serious defects can be fixed on early state<br />
  5. 5. Defect Costs<br />Meet Magento Netherlands<br />Percentage from project development hours<br />< 1%<br />20%<br />> 40%<br />Defect found at the coding stage<br />Defect found during QA phase<br />Defect found after going live<br />
  6. 6. Type of Tests<br />Meet Magento Netherlands<br />Automated Test<br />Regression Test<br />Learning Test<br />Integration Test<br />
  7. 7. Meet Magento Netherlands<br />Test in Isolation<br />Make test simple<br />Test erroneous situations<br />Test Doubles (Fake heavy resources you don’t depend on)<br />Main Principles<br />
  8. 8. EcomDev_PHPUnit<br />Meet Magento Netherlands<br />Making possible isolation of your test<br />Easy test data loading via Yaml fixtures<br />Data providers and expectations for reusable tests<br />Easy way of testing configuration files<br />Easy way for Layouts & Controllers integration test<br />
  9. 9. Simple Test Case<br />Meet Magento Netherlands<br />class EcomDev_Example_Test_Model_Productextends EcomDev_PHPUnit_Test_Case<br />{<br /> /** * @test * @loadFixture * @dataProviderdataProvider */ public function priceCalculation($productId, $storeId) { $storeId = Mage::app()->getStore($storeId)->getId(); $product = Mage::getModel('catalog/product') ->setStoreId($storeId) ->load($productId); $expected = $this->expected('%s-%s', $productId, $storeId); $this->assertEquals($expected->getFinalPrice(), $product->getFinalPrice()); <br /> $this->assertEquals($expected->getPrice(), $product->getPrice()); <br /> }<br />}<br />Test Case Class<br />
  10. 10. Simple Test Case<br />Meet Magento Netherlands<br />eav:   <br />catalog_product:<br />     - entity_id: 1       <br />type_id: simple<br />       sku: book       <br />   website_ids:         <br /> - usa_website         <br /> - canada_website         <br /> price: 12.99       <br /> status: 1  # Enabled       <br /> visibility: 4  # Visible in Catalog & Search       <br /> /websites:  # Set different prices per website<br />         usa_website:           <br />special_price: 9.99         <br />german_website:           <br /> price: 9.99           <br />special_price: 5.99 <br />Yaml Fixture<br />
  11. 11. Simple Test Case<br />Meet Magento Netherlands<br />1-2: # Product=Book Store=USA<br />final_price: 9.99<br /> price: 12.99<br />1-3: # Product=Book Store=Canada<br />final_price: 12.99<br /> price: 12.99<br />Yaml Expectation<br />Yaml Data Provider<br />-<br /> - 1<br /> - usa<br />-<br /> - 1<br /> - canada<br />-<br /> - 1<br /> - germany<br />
  12. 12. Event Dispatch Check<br />Meet Magento Netherlands<br />class EcomDev_Example_Test_Model_Cms_Pageextends EcomDev_PHPUnit_Test_Case<br />{<br /> // …<br /> public function testAvailableStatuses() {<br /> Mage::getModel(‘cms/page’)->getAvailableStatuses();<br /> $this->assertEventDispatched(<br /> ‘cms_page_get_available_statuses’<br /> );<br /> }<br />}<br />Test Case<br />
  13. 13. Test Doubles<br />Meet Magento Netherlands<br />class EcomDev_PHPUnit_Tes_Case_Controllerextends EcomDev_PHPUnit_Test_Case<br />{<br /> protected function registerCookieStub()<br /> {<br /> $cookie = $this->getModelMock('core/cookie', array('set', 'delete'));<br /> $cookie->expects($this->any())<br /> ->method('set')<br /> ->will($this->returnCallback(array($this, 'setCookieCallback‘)));<br /> $cookie->expects($this->any())<br /> ->method('delete‘)<br /> ->will($this->returnCallback(array($this, 'deleteCookieCallback‘)));<br /> $this->replaceByMock('singleton', 'core/cookie', $cookie);<br /> return $this;<br /> }<br />}<br />Test Case<br />
  14. 14. Config Test Case<br />Meet Magento Netherlands<br />class EcomDev_Example_Test_Config_Main extends EcomDev_PHPUnit_Test_Case_Config<br />{<br /> //….<br /> public function testModuleVersion()<br /> {<br /> $this->assertModuleCodePool('local');<br /> $this->assertModuleDepends(‘Mage_Catalog’);<br /> $this->assertModuleVersionGreaterThan(‘0.1.0');<br /> }<br />}<br />Testing Module Nodes<br />
  15. 15. Config Test Case<br />Meet Magento Netherlands<br />class EcomDev_Example_Test_Config_Main extends EcomDev_PHPUnit_Test_Case_Config<br />{<br /> //….<br /> public function testClassAliasDefinitions()<br /> {<br /> $this->assertModelAlias('catalog/product', 'Mage_Catalog_Model_Product');<br /> $this->assertResourceModelAlias(<br /> 'catalog/product', <br /> ‘Mage_Catalog_Model_Resource_Eav_Mysql4_Product‘<br /> );<br /> $this->assertBlockAlias(<br /> 'catalog/product_list', <br /> 'Mage_Catalog_Block_Product_List‘<br /> );<br /> }<br />}<br />Testing Class Aliases<br />
  16. 16. Config Test Case<br />Meet Magento Netherlands<br />class EcomDev_Example_Test_Config_Main extends EcomDev_PHPUnit_Test_Case_Config<br />{<br /> //….<br /> public function testEventObservers()<br /> {<br /> $this->assertEventObserverDefined(<br /> 'frontend', 'customer_login', <br /> 'catalog/product_compare_item', <br /> 'bindCustomerLogin'<br /> );<br /> }<br />}<br />Testing Event Observer Definitions<br />
  17. 17. Controller Test Case<br />Meet Magento Netherlands<br />class EcomDev_Example_Test_Controller_Main extends EcomDev_PHPUnit_Test_Case_Controller<br />{<br /> public function testRequest()<br /> {<br /> $this->dispatch('cms');<br /> $this->assertRequestDispatched();<br /> $this->assertRequestNotForwarded();<br /> $this->assertRequestRoute('cms/index/index');<br /> $this->assertRequestRouteName('cms');<br /> $this->assertRequestControllerName('index');<br /> $this->assertRequestControllerModule('Mage_Cms');<br /> $this->assertRequestActionName('index');<br /> }<br />}<br />Testing Request<br />
  18. 18. Controller Test Case<br />Meet Magento Netherlands<br />class EcomDev_Example_Test_Controller_Main<br /> extends EcomDev_PHPUnit_Test_Case_Controller<br />{<br /> public function testLayout()<br /> {<br /> $this->dispatch('');<br /> $this->assertLayoutHandleLoaded('cms_index_index');<br /> $this->assertLayoutBlockCreated('right');<br /> $this->assertLayoutBlockRendered('content');<br /> $this->assertLayoutBlockActionNotInvoked(<br /> 'footer_links', 'addLink', '', array('Custom Title')<br /> );<br /> $this->assertLayoutBlockActionInvokedAtLeast(<br /> 'footer_links', 'addLink', 4, '‘<br /> );<br /> }<br />}<br />Testing Layouts<br />
  19. 19. What’s Next<br />Meet Magento Netherlands<br />Write automated tests for your moduleshttp://www.magentocommerce.com/magento-connect/Ecommerce%20Developers/extension/5717/ecomdev_phpunit<br />Keep project healthy during its lifecycle with Continuous Integration<br />Running Daily Builds<br />Running Unit Tests in 10 minutes after last commit<br />Hudson http://hudson-ci.org<br />phpUnderControlhttp://phpundercontrol.org/<br />
  20. 20. Questions?<br />ivan.chepurnyi@ecomdev.org<br />

×