SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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)
 

Destaque

[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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...SUHANI PANDEY
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtrahman018755
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...SUHANI PANDEY
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...SUHANI PANDEY
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Delhi Call girls
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...Escorts Call Girls
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirtrahman018755
 
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...SUHANI PANDEY
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)Delhi Call girls
 
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...SUHANI PANDEY
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...nilamkumrai
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...tanu pandey
 
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls DubaiEscorts Call Girls
 
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
 

Último (20)

Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
 
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls Dubai
 
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
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.
 

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