SlideShare ist ein Scribd-Unternehmen logo
1 von 57
Downloaden Sie, um offline zu lesen
Testing in Magento 2
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
1. Running Tests
2. Writing Tests
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Running all the tests
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
$ bin/magento dev:tests:run [all | unit | integration]
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Running specific tests
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Unit Tests
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
$ vendor/bin/phpunit 
--config "dev/tests/unit/phpunit.xml.dist" 
["app/code/My/Module/Test/Unit"]
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
$ alias unit-test="$(pwd)/vendor/bin/phpunit
-c $(pwd)/dev/tests/unit/phpunit.xml.dist"
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
$ unit-test
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
$ unit-test "app/code/My/Module/Test/Unit"
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Integration Test
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
What is the difference?
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Real Objects Interact
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Integration Tests need the
Runtime Environment
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Integration Test Framework Bootstrap:
1. If TESTS_CLEANUP is set
4 clear test environment cache
4 uninstall Magento
2. If Magento is not installed
4 install Magento & dump the DB
4 on consecutive runs:
import the dump before install
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Separate DB
cp dev/tests/integration/etc/install-config-mysql.php.dist 
dev/tests/integration/etc/install-config-mysql.php
vi dev/tests/integration/etc/install-config-mysql.php
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Tweak settings
cp dev/tests/integration/phpunit.xml.dist 
dev/tests/integration/phpunit.xml
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
dev/tests/integration/phpunit.xml.dist
<phpunit>
...
<php>
...
<const name="TESTS_CLEANUP" value="enabled"/>
<!--<const name="TESTS_EXTRA_VERBOSE_LOG" value="1"/>-->
...
</php>
...
</phpunit>
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
TESTS_CLEANUP == disabled
speeds things up
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
TESTS_CLEANUP == disabled
manual cleanup required
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Enable TESTS_EXTRA_VERBOSE_LOG
in phpunit.xml to see what is going on
during bootstrap.
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Every run gets it's own
etc, pub and var dirs
dev/tests/integration/tmp/sandbox-0-
b79c13eb842cf3211459b11c775bfbde/
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
rm -r integration/tmp/sandbox-*
fresh start!
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Executing Integration Tests
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Executing integration tests
!= unit tests
$ vendor/bin/phpunit -c dev/tests/integration/phpunit.xml
Could not read "dev/tests/integration/phpunit.xml".
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
$ cd dev/tests/integration
$ ../../../vendor/bin/phpunit
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Running Tests in
PHPStorm
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
1. Set up PHP interpreter
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
2. Set up PHPUnit (1/2)
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
3. Set up PHPUnit (2/2)
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
4. Create run configuration
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
5. Run tests with one of
^ F10
^ F9 (debug)
or click:
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Writing Tests
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Writing Unit Tests
Nothing Magento 2 specific
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Writing Integration Tests
Very Magento 2 specific
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Magento 2 Testing Framework
dev/tests/integration/framework
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
ObjectManager is a'okay!
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Test Framework ObjectManager
MagentoTestFrameworkObjectManager::getInstance()
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Fixtures
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Fixtures
Fix the system into a known state
before a test is executed.
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
/**
* @magentoDataFixture Magento/Sales/_files/order.php
* @magentoDataFixture Magento/Customer/_files/customer.php
* @magentoDataFixture myCustomFixture
*/
public function testSomethingWithAnOrderAndACustomer()
{
// ...
}
public static function myCustomFixture()
{
// ...
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Complex Fixtures:
(e.g. Sessions, Order Placement, Customer...)
https://github.com/tddwizard/magento2-fixtures
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Config Fixtures
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Store Scope
/**
* @magentoConfigFixture current_store catalog/price/scope 1
*/
public function testDoesSomeoneReadThisHelpMeLetMeOut()
{
// ...
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Global Scope
/**
* @magentoConfigFixture currency/options/allow USD
*/
public function testTastesLikeMashAndPie()
{
// ...
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Test Isolation
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
DataBase Isolation
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Transactions
/**
* @magentoDbIsolation enabled
*/
public function testWithSideEffects
{
// ...
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Transactions
/**
* @magentoDataFixture Magento/Foo/_files/bar.php
*/
public function testTheFixtureIsAppliedWithinATransaction
{
// ...
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Application Isolation
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Reset Magento after test
/**
* @magentoAppIsolation enabled
*/
public function testTestWithSingletons()
{
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Selecting a application area
/**
* @magentoAppArea frontend
*/
public function testRendersTheCustomerNameInWelcomeMessage()
{
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Most important!
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Choose the right test granularity based
on
4 Business Value
4 Personal Skill
4 Available Time
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Don't test for testing's sake
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Make the tests valuable
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Time for a sip of
☕
before we dive in!
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp

Weitere ähnliche Inhalte

Ähnlich wie Testing Magento 2

Ähnlich wie Testing Magento 2 (20)

Getting your Hands Dirty Testing Magento 2 (at London Meetup)
Getting your Hands Dirty Testing Magento 2 (at London Meetup)Getting your Hands Dirty Testing Magento 2 (at London Meetup)
Getting your Hands Dirty Testing Magento 2 (at London Meetup)
 
Writing Testable Code (for Magento 1 and 2)
Writing Testable Code (for Magento 1 and 2)Writing Testable Code (for Magento 1 and 2)
Writing Testable Code (for Magento 1 and 2)
 
Writing testable Code (MageTitans Mini 2016)
Writing testable Code (MageTitans Mini 2016)Writing testable Code (MageTitans Mini 2016)
Writing testable Code (MageTitans Mini 2016)
 
The journey of mastering Magento 2 for Magento 1 developers
The journey of mastering Magento 2 for Magento 1 developersThe journey of mastering Magento 2 for Magento 1 developers
The journey of mastering Magento 2 for Magento 1 developers
 
Secure development environment @ Meet Magento Croatia 2017
Secure development environment @ Meet Magento Croatia 2017Secure development environment @ Meet Magento Croatia 2017
Secure development environment @ Meet Magento Croatia 2017
 
Automated tests types on Magento 2 example
Automated tests types on Magento 2 exampleAutomated tests types on Magento 2 example
Automated tests types on Magento 2 example
 
ClojureScript in Magento 2 - PHPUGMRN
ClojureScript in Magento 2 - PHPUGMRNClojureScript in Magento 2 - PHPUGMRN
ClojureScript in Magento 2 - PHPUGMRN
 
Issues and solutions for Magento upgrade(1.8.0.1)
Issues and solutions for Magento upgrade(1.8.0.1)Issues and solutions for Magento upgrade(1.8.0.1)
Issues and solutions for Magento upgrade(1.8.0.1)
 
Magento 2 development
Magento 2 developmentMagento 2 development
Magento 2 development
 
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
 
Vinai Kopp - How i develop M2 modules
Vinai Kopp - How i develop M2 modules Vinai Kopp - How i develop M2 modules
Vinai Kopp - How i develop M2 modules
 
Meet Magento DE 2016 - Kristof Ringleff - Growing up with Magento
Meet Magento DE 2016 - Kristof Ringleff - Growing up with MagentoMeet Magento DE 2016 - Kristof Ringleff - Growing up with Magento
Meet Magento DE 2016 - Kristof Ringleff - Growing up with Magento
 
Prepara tu entorno para Magento 2
Prepara tu entorno para Magento 2Prepara tu entorno para Magento 2
Prepara tu entorno para Magento 2
 
Make implementation of third party elements in magento 2 in 5-times easier
Make implementation of third party elements in magento 2 in 5-times easierMake implementation of third party elements in magento 2 in 5-times easier
Make implementation of third party elements in magento 2 in 5-times easier
 
How to Install Magento 2 [Latest Version]
How to Install Magento 2 [Latest Version]How to Install Magento 2 [Latest Version]
How to Install Magento 2 [Latest Version]
 
Contribution Day Guide - MM19JP
Contribution Day Guide - MM19JPContribution Day Guide - MM19JP
Contribution Day Guide - MM19JP
 
MidwestPHP - Getting Started with Magento 2
MidwestPHP - Getting Started with Magento 2MidwestPHP - Getting Started with Magento 2
MidwestPHP - Getting Started with Magento 2
 
Faster Magento Integration Tests
Faster Magento Integration TestsFaster Magento Integration Tests
Faster Magento Integration Tests
 
SOS UiComponents
SOS UiComponentsSOS UiComponents
SOS UiComponents
 
Magento2 From Setup To Deployment. Automate Everything
Magento2 From Setup To Deployment. Automate EverythingMagento2 From Setup To Deployment. Automate Everything
Magento2 From Setup To Deployment. Automate Everything
 

Mehr von vinaikopp

Mehr von vinaikopp (11)

Building Mage-OS - MageTitans 2023
Building Mage-OS - MageTitans 2023Building Mage-OS - MageTitans 2023
Building Mage-OS - MageTitans 2023
 
Hyvä: Compatibility Modules
Hyvä: Compatibility ModulesHyvä: Compatibility Modules
Hyvä: Compatibility Modules
 
Hyvä from a developer perspective
Hyvä from a developer perspectiveHyvä from a developer perspective
Hyvä from a developer perspective
 
Property Based Testing in PHP
Property Based Testing in PHPProperty Based Testing in PHP
Property Based Testing in PHP
 
Property based testing - MageTestFest 2019
Property based testing - MageTestFest 2019Property based testing - MageTestFest 2019
Property based testing - MageTestFest 2019
 
ClojureScript in Magento 2 - MageTitansMCR 2017
ClojureScript in Magento 2 - MageTitansMCR 2017ClojureScript in Magento 2 - MageTitansMCR 2017
ClojureScript in Magento 2 - MageTitansMCR 2017
 
Lizards & Pumpkins Catalog Replacement at mm17de
Lizards & Pumpkins Catalog Replacement at mm17deLizards & Pumpkins Catalog Replacement at mm17de
Lizards & Pumpkins Catalog Replacement at mm17de
 
Stories from the other side
Stories from the other sideStories from the other side
Stories from the other side
 
Architecture in-the-small-slides
Architecture in-the-small-slidesArchitecture in-the-small-slides
Architecture in-the-small-slides
 
Modern Module Architecture
Modern Module ArchitectureModern Module Architecture
Modern Module Architecture
 
The beautiful Magento module - MageTitans 2014
The beautiful Magento module - MageTitans 2014The beautiful Magento module - MageTitans 2014
The beautiful Magento module - MageTitans 2014
 

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Testing Magento 2

  • 1. Testing in Magento 2 Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 2. 1. Running Tests 2. Writing Tests Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 3. Running all the tests Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 4. $ bin/magento dev:tests:run [all | unit | integration] Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 5. Running specific tests Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 6. Unit Tests Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 7. $ vendor/bin/phpunit --config "dev/tests/unit/phpunit.xml.dist" ["app/code/My/Module/Test/Unit"] Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 8. $ alias unit-test="$(pwd)/vendor/bin/phpunit -c $(pwd)/dev/tests/unit/phpunit.xml.dist" Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 9. $ unit-test Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 10. $ unit-test "app/code/My/Module/Test/Unit" Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 11. Integration Test Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 12. What is the difference? Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 13. Real Objects Interact Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 14. Integration Tests need the Runtime Environment Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 15. Integration Test Framework Bootstrap: 1. If TESTS_CLEANUP is set 4 clear test environment cache 4 uninstall Magento 2. If Magento is not installed 4 install Magento & dump the DB 4 on consecutive runs: import the dump before install Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 16. Separate DB cp dev/tests/integration/etc/install-config-mysql.php.dist dev/tests/integration/etc/install-config-mysql.php vi dev/tests/integration/etc/install-config-mysql.php Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 17. Tweak settings cp dev/tests/integration/phpunit.xml.dist dev/tests/integration/phpunit.xml Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 18. dev/tests/integration/phpunit.xml.dist <phpunit> ... <php> ... <const name="TESTS_CLEANUP" value="enabled"/> <!--<const name="TESTS_EXTRA_VERBOSE_LOG" value="1"/>--> ... </php> ... </phpunit> Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 19. TESTS_CLEANUP == disabled speeds things up Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 20. TESTS_CLEANUP == disabled manual cleanup required Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 21. Enable TESTS_EXTRA_VERBOSE_LOG in phpunit.xml to see what is going on during bootstrap. Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 22. Every run gets it's own etc, pub and var dirs dev/tests/integration/tmp/sandbox-0- b79c13eb842cf3211459b11c775bfbde/ Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 23. rm -r integration/tmp/sandbox-* fresh start! Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 24. Executing Integration Tests Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 25. Executing integration tests != unit tests $ vendor/bin/phpunit -c dev/tests/integration/phpunit.xml Could not read "dev/tests/integration/phpunit.xml". Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 26. $ cd dev/tests/integration $ ../../../vendor/bin/phpunit Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 27. Running Tests in PHPStorm Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 28. 1. Set up PHP interpreter Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 29. 2. Set up PHPUnit (1/2) Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 30. 3. Set up PHPUnit (2/2) Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 31. 4. Create run configuration Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 32. 5. Run tests with one of ^ F10 ^ F9 (debug) or click: Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 33. Writing Tests Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 34. Writing Unit Tests Nothing Magento 2 specific Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 35. Writing Integration Tests Very Magento 2 specific Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 36. Magento 2 Testing Framework dev/tests/integration/framework Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 37. ObjectManager is a'okay! Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 38. Test Framework ObjectManager MagentoTestFrameworkObjectManager::getInstance() Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 39. Fixtures Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 40. Fixtures Fix the system into a known state before a test is executed. Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 41. /** * @magentoDataFixture Magento/Sales/_files/order.php * @magentoDataFixture Magento/Customer/_files/customer.php * @magentoDataFixture myCustomFixture */ public function testSomethingWithAnOrderAndACustomer() { // ... } public static function myCustomFixture() { // ... Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 42. Complex Fixtures: (e.g. Sessions, Order Placement, Customer...) https://github.com/tddwizard/magento2-fixtures Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 43. Config Fixtures Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 44. Store Scope /** * @magentoConfigFixture current_store catalog/price/scope 1 */ public function testDoesSomeoneReadThisHelpMeLetMeOut() { // ... Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 45. Global Scope /** * @magentoConfigFixture currency/options/allow USD */ public function testTastesLikeMashAndPie() { // ... Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 46. Test Isolation Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 47. DataBase Isolation Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 48. Transactions /** * @magentoDbIsolation enabled */ public function testWithSideEffects { // ... Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 49. Transactions /** * @magentoDataFixture Magento/Foo/_files/bar.php */ public function testTheFixtureIsAppliedWithinATransaction { // ... Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 50. Application Isolation Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 51. Reset Magento after test /** * @magentoAppIsolation enabled */ public function testTestWithSingletons() { Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 52. Selecting a application area /** * @magentoAppArea frontend */ public function testRendersTheCustomerNameInWelcomeMessage() { Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 53. Most important! Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 54. Choose the right test granularity based on 4 Business Value 4 Personal Skill 4 Available Time Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 55. Don't test for testing's sake Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 56. Make the tests valuable Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 57. Time for a sip of ☕ before we dive in! Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp