14. WHAT IS THE
DIFFERENCE?
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
15. REAL OBJECTS INTERACT
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
16. INTEGRATION TESTS NEED THE
RUNTIME ENVIRONMENT
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
17. A failing unit test tells me
exactly where my code is broken.
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
18. A failing integration test only
tells me that something is broken.
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
20. $ vendor/bin/phpunit -c dev/tests/integration/phpunit.xml
Could not read "dev/tests/integration/phpunit.xml".
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
21. $ cd dev/tests/integration
$ ../../../vendor/bin/phpunit
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
22. Every run gets it's own
etc, pub and var dirs
dev/tests/integration/tmp/
sandbox-0-b79c13eb842cf3211459b11c775bfbde/
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
24. WHAT IS TDD?
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
25. THE 3 RULES
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
26. I. No production code without
a failing unit test
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
27. II. Once there is a failing unit test,
stop and make it pass
by writing production code
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
28. III. Once the test passes,
stop writing production code
until you have a failing unit test again
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
29. TDD FOR MAGENTO 2
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
30. NO DIFFERENCE
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
32. To learn more about TDD,
check out the Clean Coders
Videos from Robert C. Martin
http://cleancoders.com
(or do a training)
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
33. INTEGRATION TESTS
FOR MAGENTO 2
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
34. VERY SPECIFIC
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
39. BUZZWORD IV
FIXTURES
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
40. Fix the system into a known state
before a test is executed.
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
41. Simple PHP Scripts
Relative to
dev/tests/integration/testsuite
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
42. /**
* @magentoDataFixture Magento/Sales/_files/order.php
* @magentoDataFixture Magento/Customer/_files/customer.php
*/
public function testSomethingWithAnOrderAndACustomer()
{
// ...
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
44. Store Scope
/**
* @magentoConfigFixture current_store catalog/price/scope 1
*/
public function testDoesSomeoneReadThisHelpMeLetMeOut()
{
// ...
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
45. Global Scope
/**
* @magentoConfigFixture currency/options/allow USD
*/
public function testHowMashAndPieTastes()
{
// ...
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
46. BUZZWORD V
TEST ISOLATION
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
47. FRESH INSTALL
FOR EACH TEST RUN
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
61. RESET MAGENTO AFTER TEST
/**
* @magentoAppIsolation enabled
*/
public function testTestWithSingletons()
{
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
62. Controller Tests: Automatic reset
class FooBarIndexActionTest extends
MagentoTestFrameworkTestCaseAbstractController
{
public function testTheLayoutIsRendered()
{
$this->dispatch('foo/bar/index');
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
63. REMEMBER
THIS
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
64. ISOLATE
YOUR TESTS
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
65. AND ALL WILL BE
GOOD
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
83. II. TESTING THE OBSERVER
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
84. O_0(NOTHING TO TEST)
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
85. III. INTEGRATION TEST
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
86. Our observer has no side effects.
We have to improvise...
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
87. /**
* @magentoDataFixture Magento/Sales/_files/order.php
*/
public function testSalesOrderPlaceAfterObserverIsCalled()
{
$this->injectMockObserverWithExpectation();
$order = $this->getOrderFixture();
$this->objectManager
->create(OrderManagementInterface::class)
->place($order);
}
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp
88. public function injectMockObserverWithExpectation()
{
$mockObserver = $this->getMock(SalesOrderPlaceAfter::class);
$mockObserver->expects($this->once())->method('execute');
$this->registerObserverTestDouble($mockObserver);
}
Getting your hands dirty Testing Magento 2 - Magento London Meetup, Feb. 2016 - ! - contact@vinaikopp.com - twitter://@VinaiKopp