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

Mais conteúdo relacionado

Mais procurados

購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介Jace Ju
 
Owl: The New Odoo UI Framework
Owl: The New Odoo UI FrameworkOwl: The New Odoo UI Framework
Owl: The New Odoo UI FrameworkOdoo
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projectsIgnacio Martín
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2zfconfua
 
Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片cfc
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsAlessandro Molina
 
Building a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesBuilding a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesCiaranMcNulty
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09Michelangelo van Dam
 
Caching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment CachingCaching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment CachingErick Hitter
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS DirectivesEyal Vardi
 
50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 MinutesAzim Kurt
 

Mais procurados (20)

Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
 
Drupal 8 Services
Drupal 8 ServicesDrupal 8 Services
Drupal 8 Services
 
購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介
 
Owl: The New Odoo UI Framework
Owl: The New Odoo UI FrameworkOwl: The New Odoo UI Framework
Owl: The New Odoo UI Framework
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2
 
Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
 
Basic JSTL
Basic JSTLBasic JSTL
Basic JSTL
 
Building a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesBuilding a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing Strategies
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
 
Caching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment CachingCaching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment Caching
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
AngularJS Basics with Example
AngularJS Basics with ExampleAngularJS Basics with Example
AngularJS Basics with Example
 
50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
 
Framework
FrameworkFramework
Framework
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
 
Advanced Django
Advanced DjangoAdvanced Django
Advanced Django
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
 

Semelhante a TDD Practices for Magento Using EcomDev PHPUnit

From typing the test to testing the type
From typing the test to testing the typeFrom typing the test to testing the type
From typing the test to testing the typeWim Godden
 
Curso Symfony - Clase 2
Curso Symfony - Clase 2Curso Symfony - Clase 2
Curso Symfony - Clase 2Javier Eguiluz
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4Javier Eguiluz
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitMichelangelo van Dam
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Jason Lotito
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxMichelangelo van Dam
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitPeter Wilcsinszky
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11Michelangelo van Dam
 
Best Practice Testing with Lime 2
Best Practice Testing with Lime 2Best Practice Testing with Lime 2
Best Practice Testing with Lime 2Bernhard Schussek
 
Meet Magento DE 2016 - Kristof Ringleff - Growing up with Magento
Meet Magento DE 2016 - Kristof Ringleff - Growing up with MagentoMeet Magento DE 2016 - Kristof Ringleff - Growing up with Magento
Meet Magento DE 2016 - Kristof Ringleff - Growing up with MagentoKristof Ringleff
 
Continously delivering
Continously deliveringContinously delivering
Continously deliveringJames Cowie
 

Semelhante a TDD Practices for Magento Using EcomDev PHPUnit (20)

PHP Unit Testing
PHP Unit TestingPHP Unit Testing
PHP Unit Testing
 
Symfony 1, mi viejo amigo
Symfony 1, mi viejo amigoSymfony 1, mi viejo amigo
Symfony 1, mi viejo amigo
 
From typing the test to testing the type
From typing the test to testing the typeFrom typing the test to testing the type
From typing the test to testing the type
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
 
PHPUnit testing to Zend_Test
PHPUnit testing to Zend_TestPHPUnit testing to Zend_Test
PHPUnit testing to Zend_Test
 
Curso Symfony - Clase 2
Curso Symfony - Clase 2Curso Symfony - Clase 2
Curso Symfony - Clase 2
 
Clean tests good tests
Clean tests   good testsClean tests   good tests
Clean tests good tests
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 
Growing up with Magento
Growing up with MagentoGrowing up with Magento
Growing up with Magento
 
PHPSpec BDD Framework
PHPSpec BDD FrameworkPHPSpec BDD Framework
PHPSpec BDD Framework
 
Jasmine with JS-Test-Driver
Jasmine with JS-Test-DriverJasmine with JS-Test-Driver
Jasmine with JS-Test-Driver
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnit
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
Best Practice Testing with Lime 2
Best Practice Testing with Lime 2Best Practice Testing with Lime 2
Best Practice Testing with Lime 2
 
Meet Magento DE 2016 - Kristof Ringleff - Growing up with Magento
Meet Magento DE 2016 - Kristof Ringleff - Growing up with MagentoMeet Magento DE 2016 - Kristof Ringleff - Growing up with Magento
Meet Magento DE 2016 - Kristof Ringleff - Growing up with Magento
 
Continously delivering
Continously deliveringContinously delivering
Continously delivering
 

Último

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Último (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

TDD Practices for Magento Using EcomDev PHPUnit

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