SlideShare a Scribd company logo
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

More Related Content

What's hot

Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
Dzmitry Ivashutsin
 
Drupal 8 Services
Drupal 8 ServicesDrupal 8 Services
Drupal 8 Services
Philip Norton
 
購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介
Jace Ju
 
Owl: The New Odoo UI Framework
Owl: The New Odoo UI FrameworkOwl: The New Odoo UI Framework
Owl: The New Odoo UI Framework
Odoo
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
Frank de Jonge
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
Ignacio Martín
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2
zfconfua
 
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 Strategies
CiaranMcNulty
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
Michelangelo 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 Caching
Erick Hitter
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
Eyal Vardi
 
AngularJS Basics with Example
AngularJS Basics with ExampleAngularJS Basics with Example
AngularJS Basics with Example
Sergey Bolshchikov
 
50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
Azim Kurt
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
Kacper Gunia
 
Advanced Django
Advanced DjangoAdvanced Django
Advanced Django
Simon Willison
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
Michelangelo van Dam
 

What's hot (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
 

Similar to Using of TDD practices for Magento

PHP Unit Testing
PHP Unit TestingPHP Unit Testing
PHP Unit Testing
Tagged Social
 
Symfony 1, mi viejo amigo
Symfony 1, mi viejo amigoSymfony 1, mi viejo amigo
Symfony 1, mi viejo amigo
Jose Antonio Pio
 
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
Wim Godden
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
Lean Teams Consultancy
 
PHPUnit testing to Zend_Test
PHPUnit testing to Zend_TestPHPUnit testing to Zend_Test
PHPUnit testing to Zend_Test
Michelangelo van Dam
 
Curso Symfony - Clase 2
Curso Symfony - Clase 2Curso Symfony - Clase 2
Curso Symfony - Clase 2
Javier Eguiluz
 
Clean tests good tests
Clean tests   good testsClean tests   good tests
Clean tests good tests
Shopsys Framework
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
Javier Eguiluz
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
Michelangelo van Dam
 
Growing up with Magento
Growing up with MagentoGrowing up with Magento
Growing up with Magento
Kristof Ringleff
 
PHPSpec BDD Framework
PHPSpec BDD FrameworkPHPSpec BDD Framework
PHPSpec BDD Framework
Marcello Duarte
 
Jasmine with JS-Test-Driver
Jasmine with JS-Test-DriverJasmine with JS-Test-Driver
Jasmine with JS-Test-Driver
Devesh Chanchlani
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
ciklum_ods
 
Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13
Jason Lotito
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
Michelangelo 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 tek11
Michelangelo 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 Magento
Kristof Ringleff
 
Continously delivering
Continously deliveringContinously delivering
Continously delivering
James Cowie
 

Similar to Using of TDD practices for Magento (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
 

Recently uploaded

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 

Recently uploaded (20)

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 

Using of TDD practices for Magento

  • 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/