SlideShare una empresa de 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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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)
 

Destacado

[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
 

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

Similar 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
 

Similar 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

best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...kajalverma014
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasDigicorns Technologies
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfJOHNBEBONYAP1
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsPriya Reddy
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...gajnagarg
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdfMatthew Sinclair
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"growthgrids
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrHenryBriggs2
 
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
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsMonica Sydney
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理F
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoilmeghakumariji156
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdfMatthew Sinclair
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制pxcywzqs
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样ayvbos
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Roommeghakumariji156
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdfMatthew Sinclair
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsMonica Sydney
 

Último (20)

best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
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
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 

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