SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Magento 2
Integration Tests
Dusan Lukic
@LDusan
http://www.dusanlukic.com
Magento 2
Magento 2 is a huge step forward
Magento 2 is a huge step forward
● Dependency injection
Magento 2 is a huge step forward
● Dependency injection
● Composer
Magento 2 is a huge step forward
● Dependency injection
● Composer
● Automated tests
What is testing?
Software testing is the process of validating and verifying that a
software program or application or product works as expected.
http://istqbexamcertification.com/what-is-a-software-testing/
Automated and manual tests
Automated testing vs manual testing
More info: http://www.base36.com/2013/03/automated-vs-manual-testing-the-pros-and-cons-of-each/
Automated testing Manual testing
Fast Slow
Costs less Costs more
Interesting Boring
Reusable
Improve code design
Integration tests
“Integration tests show that the major parts of a system work well
together”
- The Pragmatic Programmer Book
WHY?
Have you ever?
Have you ever?
● Installed a 3rd party module and it broke something else
on your project?
Have you ever?
● Installed a 3rd party module and it broke something else
on your project?
● Had a module that worked on local but not on production?
● Had 2 modules that have a conflict?
● Upgraded a project and it broke?
● Experienced problems with layout?
● Had an edge case?
Where do they fit?
Unit tests and integration tests difference
● Unit tests test the smallest units of code, integration tests test
how those units work together
● Integration tests touch more code
● Integration tests have less mocking and less isolation
● Unit tests are faster
● Unit tests are easier to debug
Functional tests and integration tests difference
● Functional tests compare against the specification
● Functional tests are slower
● Functional tests can tell us if something visible to the customer
broke
Integration tests in Magento 2
● Based on PHPUnit
● Can touch the database and filesystem
● Have separate database
● Deployed on close to real environment
● Separated into modules
● Magento core code is tested with integration tests
Setup
● bin/magento dev:test:run integration
● cd dev/tests/integration && phpunit -c phpunit.xml
● Separate database: dev/tests/integration/etc/install-config-mysql.php.dist
● Configuration in dev/tests/integration/phpunit.xml.dist
● TESTS_CLEANUP
● TESTS_MAGENTO_MODE
● TESTS_ERROR_LOG_LISTENER_LEVEL
Annotations
Annotations
/**
* Test something
*
* @magentoConfigFixture currency/options/allow USD
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*/
public function testSomething()
{
}
What are annotations
● Meta data used to inject some behaviour
● Placed in docblocks
● Change test behaviour
● PHPUnit_Framework_TestListener
● onTestStart, onTestSuccess, onTestFailure, etc
More info: http://dusanlukic.com/annotations-in-magento-2-integration-tests
@magentoDbIsolation
● when enabled wraps the test in a transaction
● enabled - makes sure that the tests don’t affect each other
● disabled - useful for debugging as data remains in database
● can be applied on class level and on method level
/**
* @magentoDbIsolation enabled
*/
@magentoConfigFixture
/**
* @magentoConfigFixture current_store sales_email/order/attachagreement 1
*/
● Sets the config value
@magentoDataFixture
/dev/tests/integration/testsuite/Magento/Catalog/_files/product_special_price.php
$product =
MagentoTestFrameworkHelperBootstrap::getObjectManager()
->create('MagentoCatalogModelProduct');
$product->setTypeId('simple')
->setAttributeSetId(4)
->setWebsiteIds([1])
->setName('Simple Product')
->setSku('simple')
->setPrice(10)
->setStockData(['use_config_manage_stock' => 0])
->save();
Rollback script
$product = MagentoTestFrameworkHelperBootstrap::getObjectManager()
->create('MagentoCatalogModelProduct');
$product->load(1);
if ($product->getId()) {
$product->delete();
}
/dev/tests/integration/testsuite/Magento/Catalog/_files/product_special_price_rollback.php
Some examples
Some examples
But first!
Some examples
Don’t test Magento framework in your tests, test your
own code
But first!
Test that non existing category goes to 404
class CategoryTest extends
MagentoTestFrameworkTestCaseAbstractController
{
/*...*/
public function testViewActionInactiveCategory()
{
$this->dispatch('catalog/category/view/id/8');
$this->assert404NotFound();
}
/*...*/
}
Save and load entity
$obj = MagentoTestFrameworkHelperBootstrap::getObjectManager()
->get('LDusanSampleModelExampleFactory')
->create();
$obj->setVar('value');
$obj->save();
$id = $obj->getId();
$repo = MagentoTestFrameworkHelperBootstrap::getObjectManager()
->get('LDusanSampleApiExampleRepositoryInterface');
$example = $repo->getById($id);
$this->assertSame($example->getVar(), 'value');
Real life example, Fooman_EmailAttachments
● Most of the stores have terms and agreement
● An email is sent to the customer after each successful order
● Goal: Attach terms and agreement to order success email
Send an email and check contents
/**
* @magentoDataFixture Magento/Sales/_files/order.php
* @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php
* @magentoConfigFixture current_store sales_email/order/attachagreement 1
*/
public function testWithHtmlTermsAttachment()
{
$orderSender = $this->objectManager->create('MagentoSalesModelOrderEmailSenderOrderSender');
$orderSender->send($order);
$termsAttachment = $this->getAttachmentOfType($this->getLastEmail(), 'text/html; charset=UTF-8');
$this->assertContains('Checkout agreement content', base64_decode($termsAttachment['Body']));
}
public function getLastEmail()
{
$this->mailhogClient->setUri(self::BASE_URL . 'v2/messages?limit=1');
$lastEmail = json_decode($this->mailhogClient->request()->getBody(), true);
$lastEmailId = $lastEmail['items'][0]['ID'];
$this->mailhogClient->setUri(self::BASE_URL . 'v1/messages/' . $lastEmailId);
return json_decode($this->mailhogClient->request()->getBody(), true);
}
The View
Goal: Insert a block into catalog product view page
<XML />
Layout
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configu
ration.xsd">
<body>
<referenceContainer name="content">
<block class="MagentoFrameworkViewElementTemplate" name="ldusan-
sample-block" template="LDusan_Sample::sample.phtml" />
</referenceContainer>
</body>
</page>
/app/code/LDusan/Sample/view/frontend/layout/catalog_product_view.xml
Template
<p>This should appear in catalog product view page!</p>
/app/code/LDusan/Sample/view/frontend/templates/sample.phtml
Test if block is added correctly
namespace LDusanSampleController;
class ActionTest extends MagentoTestFrameworkTestCaseAbstractController
{
/**
* @magentoDataFixture Magento/Catalog/_files/product_special_price.php
*/
public function testBlockAdded()
{
$this->dispatch('catalog/product/view/id/' . $product->getId());
$layout = MagentoTestFrameworkHelperBootstrap::getObjectManager()->get(
'MagentoFrameworkViewLayoutInterface'
);
$this->assertArrayHasKey('ldusan-sample-block', $layout->getAllBlocks());
}
}
At the end...
● Integration tests are not:
● The only tests that you should write
● Integration tests are:
● A way to check if something really works as expected
● Proof that our code works well with the environment
Thanks!
Slides on Twitter: @LDusan
Questions?
http://www.dusanlukic.com

Weitere ähnliche Inhalte

Was ist angesagt?

S313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringS313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringromanovfedor
 
Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Sam Becker
 
Software Testing
Software TestingSoftware Testing
Software TestingAdroitLogic
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Hazem Saleh
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Jay Friendly
 
Write testable code in java, best practices
Write testable code in java, best practicesWrite testable code in java, best practices
Write testable code in java, best practicesMarian Wamsiedel
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JSMichael Haberman
 
Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Christian Johansen
 
Illia Seleznov - Integration tests for Spring Boot application
Illia Seleznov - Integration tests for Spring Boot applicationIllia Seleznov - Integration tests for Spring Boot application
Illia Seleznov - Integration tests for Spring Boot applicationAnna Shymchenko
 
How to test models using php unit testing framework?
How to test models using php unit testing framework?How to test models using php unit testing framework?
How to test models using php unit testing framework?satejsahu
 
Acceptance testing in php with Codeception - Techmeetup Edinburgh
Acceptance testing in php with Codeception - Techmeetup EdinburghAcceptance testing in php with Codeception - Techmeetup Edinburgh
Acceptance testing in php with Codeception - Techmeetup EdinburghEngineor
 
Automated UI testing done right (DDDSydney)
Automated UI testing done right (DDDSydney)Automated UI testing done right (DDDSydney)
Automated UI testing done right (DDDSydney)Mehdi Khalili
 

Was ist angesagt? (20)

S313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringS313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discovering
 
Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Testing In Java
Testing In JavaTesting In Java
Testing In Java
 
Frontend training
Frontend trainingFrontend training
Frontend training
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012
 
Unit testing, principles
Unit testing, principlesUnit testing, principles
Unit testing, principles
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
 
Write testable code in java, best practices
Write testable code in java, best practicesWrite testable code in java, best practices
Write testable code in java, best practices
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JS
 
Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)
 
Illia Seleznov - Integration tests for Spring Boot application
Illia Seleznov - Integration tests for Spring Boot applicationIllia Seleznov - Integration tests for Spring Boot application
Illia Seleznov - Integration tests for Spring Boot application
 
Write readable tests
Write readable testsWrite readable tests
Write readable tests
 
SWTBot Tutorial
SWTBot TutorialSWTBot Tutorial
SWTBot Tutorial
 
How to test models using php unit testing framework?
How to test models using php unit testing framework?How to test models using php unit testing framework?
How to test models using php unit testing framework?
 
Acceptance testing in php with Codeception - Techmeetup Edinburgh
Acceptance testing in php with Codeception - Techmeetup EdinburghAcceptance testing in php with Codeception - Techmeetup Edinburgh
Acceptance testing in php with Codeception - Techmeetup Edinburgh
 
Testing 101
Testing 101Testing 101
Testing 101
 
Factory pattern in Java
Factory pattern in JavaFactory pattern in Java
Factory pattern in Java
 
Automated UI testing done right (DDDSydney)
Automated UI testing done right (DDDSydney)Automated UI testing done right (DDDSydney)
Automated UI testing done right (DDDSydney)
 

Andere mochten auch

[freespace] @ IFTF for EDRT - 5.13.15
[freespace] @ IFTF for EDRT - 5.13.15[freespace] @ IFTF for EDRT - 5.13.15
[freespace] @ IFTF for EDRT - 5.13.15Michael Zuckerman
 
Discovering St. Eustatius, The Caribbean
Discovering St. Eustatius, The CaribbeanDiscovering St. Eustatius, The Caribbean
Discovering St. Eustatius, The CaribbeanSteve Gillick
 
Dbpl bioproducts for sustainable farming
Dbpl bioproducts for sustainable farmingDbpl bioproducts for sustainable farming
Dbpl bioproducts for sustainable farmingSHIVA CSG PVT LTD
 
Dissertation_FULL-DRAFT-Revised
Dissertation_FULL-DRAFT-RevisedDissertation_FULL-DRAFT-Revised
Dissertation_FULL-DRAFT-RevisedFranklin Allaire
 
Part Two -In Hunan the Heat is On: Natural Wonders
Part Two -In Hunan the Heat is On:  Natural WondersPart Two -In Hunan the Heat is On:  Natural Wonders
Part Two -In Hunan the Heat is On: Natural WondersSteve Gillick
 
מצגת מדיה חברתית
מצגת מדיה חברתיתמצגת מדיה חברתית
מצגת מדיה חברתיתAlon Zakai
 
Imp drishti farm to fork club
Imp drishti farm to fork clubImp drishti farm to fork club
Imp drishti farm to fork clubSHIVA CSG PVT LTD
 
Service profile shiva finance
Service profile shiva financeService profile shiva finance
Service profile shiva financeSHIVA CSG PVT LTD
 
Discovering Abitibi-Témiscamingue
Discovering Abitibi-TémiscamingueDiscovering Abitibi-Témiscamingue
Discovering Abitibi-TémiscamingueSteve Gillick
 
Shiva consultancy textech general proposal
Shiva consultancy textech general proposalShiva consultancy textech general proposal
Shiva consultancy textech general proposalSHIVA CSG PVT LTD
 
Tagetik Solvency II introduction
Tagetik Solvency II introductionTagetik Solvency II introduction
Tagetik Solvency II introductionEntrepreneur
 
Skills needed-for-a-job-in-accessibility
Skills needed-for-a-job-in-accessibilitySkills needed-for-a-job-in-accessibility
Skills needed-for-a-job-in-accessibilityelianna james
 

Andere mochten auch (17)

Final 9 7-13
Final 9 7-13Final 9 7-13
Final 9 7-13
 
[freespace] @ IFTF for EDRT - 5.13.15
[freespace] @ IFTF for EDRT - 5.13.15[freespace] @ IFTF for EDRT - 5.13.15
[freespace] @ IFTF for EDRT - 5.13.15
 
Service profile scsg mining
Service profile scsg miningService profile scsg mining
Service profile scsg mining
 
Discovering St. Eustatius, The Caribbean
Discovering St. Eustatius, The CaribbeanDiscovering St. Eustatius, The Caribbean
Discovering St. Eustatius, The Caribbean
 
Dbpl bioproducts for sustainable farming
Dbpl bioproducts for sustainable farmingDbpl bioproducts for sustainable farming
Dbpl bioproducts for sustainable farming
 
Hokkaido 2012
Hokkaido 2012Hokkaido 2012
Hokkaido 2012
 
Dissertation_FULL-DRAFT-Revised
Dissertation_FULL-DRAFT-RevisedDissertation_FULL-DRAFT-Revised
Dissertation_FULL-DRAFT-Revised
 
Part Two -In Hunan the Heat is On: Natural Wonders
Part Two -In Hunan the Heat is On:  Natural WondersPart Two -In Hunan the Heat is On:  Natural Wonders
Part Two -In Hunan the Heat is On: Natural Wonders
 
מצגת מדיה חברתית
מצגת מדיה חברתיתמצגת מדיה חברתית
מצגת מדיה חברתית
 
Imp drishti farm to fork club
Imp drishti farm to fork clubImp drishti farm to fork club
Imp drishti farm to fork club
 
Service profile shiva finance
Service profile shiva financeService profile shiva finance
Service profile shiva finance
 
Poisonous plants of world
Poisonous plants of worldPoisonous plants of world
Poisonous plants of world
 
Discovering Abitibi-Témiscamingue
Discovering Abitibi-TémiscamingueDiscovering Abitibi-Témiscamingue
Discovering Abitibi-Témiscamingue
 
Mango crop protection
Mango crop protectionMango crop protection
Mango crop protection
 
Shiva consultancy textech general proposal
Shiva consultancy textech general proposalShiva consultancy textech general proposal
Shiva consultancy textech general proposal
 
Tagetik Solvency II introduction
Tagetik Solvency II introductionTagetik Solvency II introduction
Tagetik Solvency II introduction
 
Skills needed-for-a-job-in-accessibility
Skills needed-for-a-job-in-accessibilitySkills needed-for-a-job-in-accessibility
Skills needed-for-a-job-in-accessibility
 

Ähnlich wie Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016

Magento 2 integration tests
Magento 2 integration testsMagento 2 integration tests
Magento 2 integration testsDusan Lukic
 
Introduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe CommerceIntroduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe CommerceBartosz Górski
 
Introduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe CommerceIntroduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe CommerceBartosz Górski
 
Code igniter unittest-part1
Code igniter unittest-part1Code igniter unittest-part1
Code igniter unittest-part1Albert Rosa
 
Zepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalZepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalMax Pronko
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosFlutter Agency
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Appschrisb206 chrisb206
 
Testing your application on Google App Engine
Testing your application on Google App EngineTesting your application on Google App Engine
Testing your application on Google App EngineInphina Technologies
 
Testing Your Application On Google App Engine
Testing Your Application On Google App EngineTesting Your Application On Google App Engine
Testing Your Application On Google App EngineIndicThreads
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsDECK36
 
Audit your reactive applications
Audit your reactive applicationsAudit your reactive applications
Audit your reactive applicationsOCTO Technology
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullySpringPeople
 
Quality of life through Unit Testing
Quality of life through Unit TestingQuality of life through Unit Testing
Quality of life through Unit TestingSian Lerk Lau
 
Angular Intermediate
Angular IntermediateAngular Intermediate
Angular IntermediateLinkMe Srl
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Scott Keck-Warren
 
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...Ondřej Machulda
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Ukraine
 
Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Yves Hoppe
 
Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django ApplicationsGareth Rushgrove
 

Ähnlich wie Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016 (20)

Magento 2 integration tests
Magento 2 integration testsMagento 2 integration tests
Magento 2 integration tests
 
Introduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe CommerceIntroduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe Commerce
 
Introduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe CommerceIntroduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe Commerce
 
Code igniter unittest-part1
Code igniter unittest-part1Code igniter unittest-part1
Code igniter unittest-part1
 
Zepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalZepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_Final
 
Php unit (eng)
Php unit (eng)Php unit (eng)
Php unit (eng)
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
 
Testing your application on Google App Engine
Testing your application on Google App EngineTesting your application on Google App Engine
Testing your application on Google App Engine
 
Testing Your Application On Google App Engine
Testing Your Application On Google App EngineTesting Your Application On Google App Engine
Testing Your Application On Google App Engine
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
Audit your reactive applications
Audit your reactive applicationsAudit your reactive applications
Audit your reactive applications
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
Quality of life through Unit Testing
Quality of life through Unit TestingQuality of life through Unit Testing
Quality of life through Unit Testing
 
Angular Intermediate
Angular IntermediateAngular Intermediate
Angular Intermediate
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023
 
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
 
Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016
 
Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django Applications
 

Kürzlich hochgeladen

Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.soniya singh
 
SEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization SpecialistSEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization SpecialistKHM Anwar
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Radiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsRadiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsstephieert
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsThierry TROUIN ☁
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...aditipandeya
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 
Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...
Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...
Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...sonatiwari757
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Sheetaleventcompany
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Servicegwenoracqe6
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Call Girls in Nagpur High Profile
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607dollysharma2066
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 

Kürzlich hochgeladen (20)

Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
SEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization SpecialistSEO Growth Program-Digital optimization Specialist
SEO Growth Program-Digital optimization Specialist
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Radiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girlsRadiant Call girls in Dubai O56338O268 Dubai Call girls
Radiant Call girls in Dubai O56338O268 Dubai Call girls
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with Flows
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
VIP 7001035870 Find & Meet Hyderabad Call Girls Dilsukhnagar high-profile Cal...
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...
Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...
Call Girls in Mayur Vihar ✔️ 9711199171 ✔️ Delhi ✔️ Enjoy Call Girls With Our...
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
 
Call Girls In Noida 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In Noida 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In Noida 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In Noida 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 

Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016

  • 1. Magento 2 Integration Tests Dusan Lukic @LDusan http://www.dusanlukic.com
  • 3. Magento 2 is a huge step forward
  • 4. Magento 2 is a huge step forward ● Dependency injection
  • 5. Magento 2 is a huge step forward ● Dependency injection ● Composer
  • 6. Magento 2 is a huge step forward ● Dependency injection ● Composer ● Automated tests
  • 7. What is testing? Software testing is the process of validating and verifying that a software program or application or product works as expected. http://istqbexamcertification.com/what-is-a-software-testing/
  • 9. Automated testing vs manual testing More info: http://www.base36.com/2013/03/automated-vs-manual-testing-the-pros-and-cons-of-each/ Automated testing Manual testing Fast Slow Costs less Costs more Interesting Boring Reusable Improve code design
  • 11. “Integration tests show that the major parts of a system work well together” - The Pragmatic Programmer Book
  • 12.
  • 13. WHY?
  • 15. Have you ever? ● Installed a 3rd party module and it broke something else on your project?
  • 16. Have you ever? ● Installed a 3rd party module and it broke something else on your project? ● Had a module that worked on local but not on production? ● Had 2 modules that have a conflict? ● Upgraded a project and it broke? ● Experienced problems with layout? ● Had an edge case?
  • 18.
  • 19. Unit tests and integration tests difference ● Unit tests test the smallest units of code, integration tests test how those units work together ● Integration tests touch more code ● Integration tests have less mocking and less isolation ● Unit tests are faster ● Unit tests are easier to debug
  • 20. Functional tests and integration tests difference ● Functional tests compare against the specification ● Functional tests are slower ● Functional tests can tell us if something visible to the customer broke
  • 21. Integration tests in Magento 2 ● Based on PHPUnit ● Can touch the database and filesystem ● Have separate database ● Deployed on close to real environment ● Separated into modules ● Magento core code is tested with integration tests
  • 22. Setup ● bin/magento dev:test:run integration ● cd dev/tests/integration && phpunit -c phpunit.xml ● Separate database: dev/tests/integration/etc/install-config-mysql.php.dist ● Configuration in dev/tests/integration/phpunit.xml.dist ● TESTS_CLEANUP ● TESTS_MAGENTO_MODE ● TESTS_ERROR_LOG_LISTENER_LEVEL
  • 24. Annotations /** * Test something * * @magentoConfigFixture currency/options/allow USD * @magentoAppIsolation enabled * @magentoDbIsolation enabled */ public function testSomething() { }
  • 25. What are annotations ● Meta data used to inject some behaviour ● Placed in docblocks ● Change test behaviour ● PHPUnit_Framework_TestListener ● onTestStart, onTestSuccess, onTestFailure, etc More info: http://dusanlukic.com/annotations-in-magento-2-integration-tests
  • 26. @magentoDbIsolation ● when enabled wraps the test in a transaction ● enabled - makes sure that the tests don’t affect each other ● disabled - useful for debugging as data remains in database ● can be applied on class level and on method level /** * @magentoDbIsolation enabled */
  • 27. @magentoConfigFixture /** * @magentoConfigFixture current_store sales_email/order/attachagreement 1 */ ● Sets the config value
  • 29. Rollback script $product = MagentoTestFrameworkHelperBootstrap::getObjectManager() ->create('MagentoCatalogModelProduct'); $product->load(1); if ($product->getId()) { $product->delete(); } /dev/tests/integration/testsuite/Magento/Catalog/_files/product_special_price_rollback.php
  • 32. Some examples Don’t test Magento framework in your tests, test your own code But first!
  • 33. Test that non existing category goes to 404 class CategoryTest extends MagentoTestFrameworkTestCaseAbstractController { /*...*/ public function testViewActionInactiveCategory() { $this->dispatch('catalog/category/view/id/8'); $this->assert404NotFound(); } /*...*/ }
  • 34. Save and load entity $obj = MagentoTestFrameworkHelperBootstrap::getObjectManager() ->get('LDusanSampleModelExampleFactory') ->create(); $obj->setVar('value'); $obj->save(); $id = $obj->getId(); $repo = MagentoTestFrameworkHelperBootstrap::getObjectManager() ->get('LDusanSampleApiExampleRepositoryInterface'); $example = $repo->getById($id); $this->assertSame($example->getVar(), 'value');
  • 35. Real life example, Fooman_EmailAttachments ● Most of the stores have terms and agreement ● An email is sent to the customer after each successful order ● Goal: Attach terms and agreement to order success email
  • 36. Send an email and check contents /** * @magentoDataFixture Magento/Sales/_files/order.php * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php * @magentoConfigFixture current_store sales_email/order/attachagreement 1 */ public function testWithHtmlTermsAttachment() { $orderSender = $this->objectManager->create('MagentoSalesModelOrderEmailSenderOrderSender'); $orderSender->send($order); $termsAttachment = $this->getAttachmentOfType($this->getLastEmail(), 'text/html; charset=UTF-8'); $this->assertContains('Checkout agreement content', base64_decode($termsAttachment['Body'])); } public function getLastEmail() { $this->mailhogClient->setUri(self::BASE_URL . 'v2/messages?limit=1'); $lastEmail = json_decode($this->mailhogClient->request()->getBody(), true); $lastEmailId = $lastEmail['items'][0]['ID']; $this->mailhogClient->setUri(self::BASE_URL . 'v1/messages/' . $lastEmailId); return json_decode($this->mailhogClient->request()->getBody(), true); }
  • 37. The View Goal: Insert a block into catalog product view page <XML />
  • 38. Layout <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configu ration.xsd"> <body> <referenceContainer name="content"> <block class="MagentoFrameworkViewElementTemplate" name="ldusan- sample-block" template="LDusan_Sample::sample.phtml" /> </referenceContainer> </body> </page> /app/code/LDusan/Sample/view/frontend/layout/catalog_product_view.xml
  • 39. Template <p>This should appear in catalog product view page!</p> /app/code/LDusan/Sample/view/frontend/templates/sample.phtml
  • 40. Test if block is added correctly namespace LDusanSampleController; class ActionTest extends MagentoTestFrameworkTestCaseAbstractController { /** * @magentoDataFixture Magento/Catalog/_files/product_special_price.php */ public function testBlockAdded() { $this->dispatch('catalog/product/view/id/' . $product->getId()); $layout = MagentoTestFrameworkHelperBootstrap::getObjectManager()->get( 'MagentoFrameworkViewLayoutInterface' ); $this->assertArrayHasKey('ldusan-sample-block', $layout->getAllBlocks()); } }
  • 41. At the end... ● Integration tests are not: ● The only tests that you should write ● Integration tests are: ● A way to check if something really works as expected ● Proof that our code works well with the environment
  • 42. Thanks! Slides on Twitter: @LDusan Questions? http://www.dusanlukic.com