SlideShare a Scribd company logo
TDD Katas in Magento 2
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Code Kata
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Code Kata?
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
We practice our craft.
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
We train like
athletes do.
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
What do we train in a code kata?
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
The Mind
→ The 3 phases of TDD
→ Working in small units
→ Recognizing patterns
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
The Body
→ Keyboard shortcuts
→ Efficient grouping of actions
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Framework Knowledge
→ Memorizing framework sections
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Katas are usually done
multiple times
over a
period of time.
E.g. once per day over 1 week,
once per week over 3 months,
...
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Time Limit:
15 - 30 minutes
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Today is just a
Demo
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
An impression how
TDD in Magento
can look.
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
To inspire you to
start doing katas
as soon as you are back!
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Today's Kata:
Magento 2 Total Model
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Total Models
A flexible system to calculate cart and cart
item prices and adjustments.
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
<!-- File: etc/sales.xml -->
<section name="quote">
<group name="totals">
<item name="subtotal" sort_order="100"
instance="MagentoQuoteModelQuoteAddressTotalSubtotal"/>
<item name="tax_subtotal" sort_order="200"
instance="MagentoTaxModelSalesTotalQuoteSubtotal"/>
<item name="shipping" sort_order="250"
instance="MagentoQuoteModelQuoteAddressTotalShipping"/>
<item name="discount" sort_order="400"
instance="MagentoSalesRuleModelQuoteDiscount"/>
<item name="tax" sort_order="450"
instance="MagentoTaxModelSalesTotalQuoteTax"/>
<item name="grand_total" sort_order="550"
instance="MagentoQuoteModelQuoteAddressTotalGrand" />
</group>
</section>
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Processed in order
→ First comes subtotal
Sets quote item prices & subtotal
→ Then all the others
shipping, discount, tax, ...
→ Last comes grand_total
Sums up all other total models
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Each one adds it's value on
ModelQuoteAddressTotal
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
The Kata Example code is
missing a custom total model.
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Training Module: Example_GiftItem
When a customer adds a product from the
sample data "Bags" attribute set,
to the cart, also add a free water bottle.
https://github.com/Vinai/module-example-giftitem
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Training Module: Example_GiftItem
The GiftItem total model is responsible
for setting the price of gift items to zero
and adjusting the subtotal.
https://github.com/Vinai/module-example-giftitem
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
What does this kata teach?
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
(1/2) Generic skills:
→ TDD Red-Green-Refactor process
→ Working with test doubles
→ Separating pure functions
from functions with side effects
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
(2/2) Magento skills:
→ Test driving Magento development
→ The totals architecture
→ Dealing with Law of Demeter violations
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Tomorrow
How you can get started:
# Create module dir
mkdir -p app/code/Example && cd app/code/Example
# Clone repo
git clone https://github.com/Vinai/module-example-giftitem.git GiftItem
cd GiftItem
# Check out git tag
git checkout beginning-of-kata
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Kata Task:
Use TDD to create the GiftItem total model
ModelTotalsGiftItemAddressTotal
Implement the collect() method.
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Target behavior: collect()
→ Subtract gift item row totals sum and
base row totals sum from the subtotal
→ Set calculation_price
and base_calculation_price
of every gift item to zero
→ Call calcRowTotal on each gift
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
Enjoy the session and
feel those reflexes
get sharper!
TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp

More Related Content

What's hot

Max Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & QualityMax Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & Quality
Meet Magento Italy
 
Imagine recap-devhub
Imagine recap-devhubImagine recap-devhub
Imagine recap-devhubMagento Dev
 
Ajax for PHP Developers
Ajax for PHP DevelopersAjax for PHP Developers
Ajax for PHP Developers
Michael Girouard
 
PHP Berkshire October 2015
PHP Berkshire October 2015PHP Berkshire October 2015
PHP Berkshire October 2015
David Yell
 
Igor Bondarenko - Process organization of the development modules specific to...
Igor Bondarenko - Process organization of the development modules specific to...Igor Bondarenko - Process organization of the development modules specific to...
Igor Bondarenko - Process organization of the development modules specific to...
Meet Magento Italy
 
Testing in Magento 2
Testing in Magento 2 Testing in Magento 2
Testing in Magento 2
Igor Miniailo
 
ASP.NET을 중심으로 한 웹 개발 기술의 발전과 마이크로소프트의 최근 동향
ASP.NET을 중심으로 한 웹 개발 기술의 발전과 마이크로소프트의 최근 동향ASP.NET을 중심으로 한 웹 개발 기술의 발전과 마이크로소프트의 최근 동향
ASP.NET을 중심으로 한 웹 개발 기술의 발전과 마이크로소프트의 최근 동향
명신 김
 
Architecture in-the-small-slides
Architecture in-the-small-slidesArchitecture in-the-small-slides
Architecture in-the-small-slides
vinaikopp
 
How To Install Magento 2 (updated for the latest version)
How To Install Magento 2 (updated for the latest version)How To Install Magento 2 (updated for the latest version)
How To Install Magento 2 (updated for the latest version)
Magestore
 
Magento 2 - An Intro to a Modern PHP-Based System - Northeast PHP 2015
Magento 2 - An Intro to a Modern PHP-Based System - Northeast PHP 2015Magento 2 - An Intro to a Modern PHP-Based System - Northeast PHP 2015
Magento 2 - An Intro to a Modern PHP-Based System - Northeast PHP 2015
Joshua Warren
 
Magento 2 development
Magento 2 developmentMagento 2 development
Magento 2 development
Olivia Williams
 
Magento 2 - An Intro to a Modern PHP-Based System - ZendCon 2015
Magento 2 - An Intro to a Modern PHP-Based System - ZendCon 2015Magento 2 - An Intro to a Modern PHP-Based System - ZendCon 2015
Magento 2 - An Intro to a Modern PHP-Based System - ZendCon 2015
Joshua Warren
 
Dependency Injection Extended: the way to advanced Magento 2 development
Dependency Injection Extended: the way to advanced Magento 2 developmentDependency Injection Extended: the way to advanced Magento 2 development
Dependency Injection Extended: the way to advanced Magento 2 development
Andreas von Studnitz
 
Lean frontend development
Lean frontend developmentLean frontend development
Lean frontend development
Matteo Guidotto
 
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]
M-Connect Media
 
Magento 2 Design Patterns
Magento 2 Design PatternsMagento 2 Design Patterns
Magento 2 Design Patterns
Max Pronko
 
2020 [pweb] 13 typescript
2020 [pweb] 13 typescript2020 [pweb] 13 typescript
2020 [pweb] 13 typescript
VICTOR JATOBÁ
 
Outlook on Magento 2
Outlook on Magento 2Outlook on Magento 2
Outlook on Magento 2
Matthias Glitzner-Zeis
 
MJML API @ Paris API
MJML API  @ Paris APIMJML API  @ Paris API
MJML API @ Paris API
Julien Ernewein
 
Magento 2 Modules are Easy!
Magento 2 Modules are Easy!Magento 2 Modules are Easy!
Magento 2 Modules are Easy!
Ben Marks
 

What's hot (20)

Max Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & QualityMax Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & Quality
 
Imagine recap-devhub
Imagine recap-devhubImagine recap-devhub
Imagine recap-devhub
 
Ajax for PHP Developers
Ajax for PHP DevelopersAjax for PHP Developers
Ajax for PHP Developers
 
PHP Berkshire October 2015
PHP Berkshire October 2015PHP Berkshire October 2015
PHP Berkshire October 2015
 
Igor Bondarenko - Process organization of the development modules specific to...
Igor Bondarenko - Process organization of the development modules specific to...Igor Bondarenko - Process organization of the development modules specific to...
Igor Bondarenko - Process organization of the development modules specific to...
 
Testing in Magento 2
Testing in Magento 2 Testing in Magento 2
Testing in Magento 2
 
ASP.NET을 중심으로 한 웹 개발 기술의 발전과 마이크로소프트의 최근 동향
ASP.NET을 중심으로 한 웹 개발 기술의 발전과 마이크로소프트의 최근 동향ASP.NET을 중심으로 한 웹 개발 기술의 발전과 마이크로소프트의 최근 동향
ASP.NET을 중심으로 한 웹 개발 기술의 발전과 마이크로소프트의 최근 동향
 
Architecture in-the-small-slides
Architecture in-the-small-slidesArchitecture in-the-small-slides
Architecture in-the-small-slides
 
How To Install Magento 2 (updated for the latest version)
How To Install Magento 2 (updated for the latest version)How To Install Magento 2 (updated for the latest version)
How To Install Magento 2 (updated for the latest version)
 
Magento 2 - An Intro to a Modern PHP-Based System - Northeast PHP 2015
Magento 2 - An Intro to a Modern PHP-Based System - Northeast PHP 2015Magento 2 - An Intro to a Modern PHP-Based System - Northeast PHP 2015
Magento 2 - An Intro to a Modern PHP-Based System - Northeast PHP 2015
 
Magento 2 development
Magento 2 developmentMagento 2 development
Magento 2 development
 
Magento 2 - An Intro to a Modern PHP-Based System - ZendCon 2015
Magento 2 - An Intro to a Modern PHP-Based System - ZendCon 2015Magento 2 - An Intro to a Modern PHP-Based System - ZendCon 2015
Magento 2 - An Intro to a Modern PHP-Based System - ZendCon 2015
 
Dependency Injection Extended: the way to advanced Magento 2 development
Dependency Injection Extended: the way to advanced Magento 2 developmentDependency Injection Extended: the way to advanced Magento 2 development
Dependency Injection Extended: the way to advanced Magento 2 development
 
Lean frontend development
Lean frontend developmentLean frontend development
Lean frontend development
 
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]
 
Magento 2 Design Patterns
Magento 2 Design PatternsMagento 2 Design Patterns
Magento 2 Design Patterns
 
2020 [pweb] 13 typescript
2020 [pweb] 13 typescript2020 [pweb] 13 typescript
2020 [pweb] 13 typescript
 
Outlook on Magento 2
Outlook on Magento 2Outlook on Magento 2
Outlook on Magento 2
 
MJML API @ Paris API
MJML API  @ Paris APIMJML API  @ Paris API
MJML API @ Paris API
 
Magento 2 Modules are Easy!
Magento 2 Modules are Easy!Magento 2 Modules are Easy!
Magento 2 Modules are Easy!
 

Similar to Magento 2 TDD Code Kata

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)
vinaikopp
 
Magento Commerce Global contribution day 2020
Magento Commerce Global contribution day 2020Magento Commerce Global contribution day 2020
Magento Commerce Global contribution day 2020
Slava Mankivski
 
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)
vinaikopp
 
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 Italy
 
20 Ideas On How To Improve Your Agile Board
20 Ideas On How To Improve Your Agile Board20 Ideas On How To Improve Your Agile Board
20 Ideas On How To Improve Your Agile Board
Marcus Hammarberg
 
SAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunnerSAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunner
Kumar Gupta
 
SAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunnerSAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunner
Kumar Gupta
 
MidwestPHP - Getting Started with Magento 2
MidwestPHP - Getting Started with Magento 2MidwestPHP - Getting Started with Magento 2
MidwestPHP - Getting Started with Magento 2
Mathew Beane
 
Most Advanced GTM Deployment. Ever!
Most Advanced GTM Deployment. Ever!Most Advanced GTM Deployment. Ever!
Most Advanced GTM Deployment. Ever!
Phil Pearce
 
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
Elena Kulbich
 
JS Fest 2019. Minko Gechev. Building Fast Angular Applications by Default
JS Fest 2019. Minko Gechev. Building Fast Angular Applications by DefaultJS Fest 2019. Minko Gechev. Building Fast Angular Applications by Default
JS Fest 2019. Minko Gechev. Building Fast Angular Applications by Default
JSFestUA
 
Big Decimal: Avoid Rounding Errors on Decimals in JavaScript
Big Decimal: Avoid Rounding Errors on Decimals in JavaScriptBig Decimal: Avoid Rounding Errors on Decimals in JavaScript
Big Decimal: Avoid Rounding Errors on Decimals in JavaScript
Igalia
 
Android studio tips and tricks
Android studio tips and tricksAndroid studio tips and tricks
Android studio tips and tricks
Oleg Mazhukin
 
Writing testable Code (MageTitans Mini 2016)
Writing testable Code (MageTitans Mini 2016)Writing testable Code (MageTitans Mini 2016)
Writing testable Code (MageTitans Mini 2016)
vinaikopp
 
Modern Module Architecture
Modern Module ArchitectureModern Module Architecture
Modern Module Architecture
vinaikopp
 
Awesome Architectures in Magento 2.3
Awesome Architectures in Magento 2.3Awesome Architectures in Magento 2.3
Awesome Architectures in Magento 2.3
Riccardo Tempesta
 
The usage and dependency resolving mechanism of go module
The usage and dependency resolving mechanism of go moduleThe usage and dependency resolving mechanism of go module
The usage and dependency resolving mechanism of go module
Lung-Hsuan Hung
 
Magento best practices
Magento best practicesMagento best practices
Magento best practices
Alessandro Ronchi
 
Contribution Day Guide - MM19JP
Contribution Day Guide - MM19JPContribution Day Guide - MM19JP
Contribution Day Guide - MM19JP
Oleksii Korshenko
 

Similar to Magento 2 TDD Code Kata (20)

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)
 
Magento Commerce Global contribution day 2020
Magento Commerce Global contribution day 2020Magento Commerce Global contribution day 2020
Magento Commerce Global contribution day 2020
 
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)
 
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
 
20 Ideas On How To Improve Your Agile Board
20 Ideas On How To Improve Your Agile Board20 Ideas On How To Improve Your Agile Board
20 Ideas On How To Improve Your Agile Board
 
SAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunnerSAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunner
 
SAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunnerSAP Performance Testing Using LoadRunner
SAP Performance Testing Using LoadRunner
 
MidwestPHP - Getting Started with Magento 2
MidwestPHP - Getting Started with Magento 2MidwestPHP - Getting Started with Magento 2
MidwestPHP - Getting Started with Magento 2
 
Geek git
Geek gitGeek git
Geek git
 
Most Advanced GTM Deployment. Ever!
Most Advanced GTM Deployment. Ever!Most Advanced GTM Deployment. Ever!
Most Advanced GTM Deployment. Ever!
 
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
 
JS Fest 2019. Minko Gechev. Building Fast Angular Applications by Default
JS Fest 2019. Minko Gechev. Building Fast Angular Applications by DefaultJS Fest 2019. Minko Gechev. Building Fast Angular Applications by Default
JS Fest 2019. Minko Gechev. Building Fast Angular Applications by Default
 
Big Decimal: Avoid Rounding Errors on Decimals in JavaScript
Big Decimal: Avoid Rounding Errors on Decimals in JavaScriptBig Decimal: Avoid Rounding Errors on Decimals in JavaScript
Big Decimal: Avoid Rounding Errors on Decimals in JavaScript
 
Android studio tips and tricks
Android studio tips and tricksAndroid studio tips and tricks
Android studio tips and tricks
 
Writing testable Code (MageTitans Mini 2016)
Writing testable Code (MageTitans Mini 2016)Writing testable Code (MageTitans Mini 2016)
Writing testable Code (MageTitans Mini 2016)
 
Modern Module Architecture
Modern Module ArchitectureModern Module Architecture
Modern Module Architecture
 
Awesome Architectures in Magento 2.3
Awesome Architectures in Magento 2.3Awesome Architectures in Magento 2.3
Awesome Architectures in Magento 2.3
 
The usage and dependency resolving mechanism of go module
The usage and dependency resolving mechanism of go moduleThe usage and dependency resolving mechanism of go module
The usage and dependency resolving mechanism of go module
 
Magento best practices
Magento best practicesMagento best practices
Magento best practices
 
Contribution Day Guide - MM19JP
Contribution Day Guide - MM19JPContribution Day Guide - MM19JP
Contribution Day Guide - MM19JP
 

More from vinaikopp

Building Mage-OS - MageTitans 2023
Building Mage-OS - MageTitans 2023Building Mage-OS - MageTitans 2023
Building Mage-OS - MageTitans 2023
vinaikopp
 
Property Based Testing in PHP
Property Based Testing in PHPProperty Based Testing in PHP
Property Based Testing in PHP
vinaikopp
 
Property based testing - MageTestFest 2019
Property based testing - MageTestFest 2019Property based testing - MageTestFest 2019
Property based testing - MageTestFest 2019
vinaikopp
 
SOS UiComponents
SOS UiComponentsSOS UiComponents
SOS UiComponents
vinaikopp
 
ClojureScript in Magento 2 - PHPUGMRN
ClojureScript in Magento 2 - PHPUGMRNClojureScript in Magento 2 - PHPUGMRN
ClojureScript in Magento 2 - PHPUGMRN
vinaikopp
 
ClojureScript in Magento 2 - MageTitansMCR 2017
ClojureScript in Magento 2 - MageTitansMCR 2017ClojureScript in Magento 2 - MageTitansMCR 2017
ClojureScript in Magento 2 - MageTitansMCR 2017
vinaikopp
 
Lizards & Pumpkins Catalog Replacement at mm17de
Lizards & Pumpkins Catalog Replacement at mm17deLizards & Pumpkins Catalog Replacement at mm17de
Lizards & Pumpkins Catalog Replacement at mm17de
vinaikopp
 
Stories from the other side
Stories from the other sideStories from the other side
Stories from the other side
vinaikopp
 
The beautiful Magento module - MageTitans 2014
The beautiful Magento module - MageTitans 2014The beautiful Magento module - MageTitans 2014
The beautiful Magento module - MageTitans 2014
vinaikopp
 

More from vinaikopp (9)

Building Mage-OS - MageTitans 2023
Building Mage-OS - MageTitans 2023Building Mage-OS - MageTitans 2023
Building Mage-OS - MageTitans 2023
 
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
 
SOS UiComponents
SOS UiComponentsSOS UiComponents
SOS UiComponents
 
ClojureScript in Magento 2 - PHPUGMRN
ClojureScript in Magento 2 - PHPUGMRNClojureScript in Magento 2 - PHPUGMRN
ClojureScript in Magento 2 - PHPUGMRN
 
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
 
The beautiful Magento module - MageTitans 2014
The beautiful Magento module - MageTitans 2014The beautiful Magento module - MageTitans 2014
The beautiful Magento module - MageTitans 2014
 

Recently uploaded

Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 

Recently uploaded (20)

Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 

Magento 2 TDD Code Kata

  • 1. TDD Katas in Magento 2 TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 2.
  • 3. Code Kata TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 4. Code Kata? TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 5. We practice our craft. TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 6. We train like athletes do. TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 7. What do we train in a code kata? TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 8. The Mind → The 3 phases of TDD → Working in small units → Recognizing patterns TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 9. The Body → Keyboard shortcuts → Efficient grouping of actions TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 10. Framework Knowledge → Memorizing framework sections TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 11. Katas are usually done multiple times over a period of time. E.g. once per day over 1 week, once per week over 3 months, ... TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 12. Time Limit: 15 - 30 minutes TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 13. Today is just a Demo TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 14. An impression how TDD in Magento can look. TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 15. To inspire you to start doing katas as soon as you are back! TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 16. Today's Kata: Magento 2 Total Model TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 17. Total Models A flexible system to calculate cart and cart item prices and adjustments. TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 18. <!-- File: etc/sales.xml --> <section name="quote"> <group name="totals"> <item name="subtotal" sort_order="100" instance="MagentoQuoteModelQuoteAddressTotalSubtotal"/> <item name="tax_subtotal" sort_order="200" instance="MagentoTaxModelSalesTotalQuoteSubtotal"/> <item name="shipping" sort_order="250" instance="MagentoQuoteModelQuoteAddressTotalShipping"/> <item name="discount" sort_order="400" instance="MagentoSalesRuleModelQuoteDiscount"/> <item name="tax" sort_order="450" instance="MagentoTaxModelSalesTotalQuoteTax"/> <item name="grand_total" sort_order="550" instance="MagentoQuoteModelQuoteAddressTotalGrand" /> </group> </section> TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 19. Processed in order → First comes subtotal Sets quote item prices & subtotal → Then all the others shipping, discount, tax, ... → Last comes grand_total Sums up all other total models TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 20. Each one adds it's value on ModelQuoteAddressTotal TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 21. The Kata Example code is missing a custom total model. TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 22. Training Module: Example_GiftItem When a customer adds a product from the sample data "Bags" attribute set, to the cart, also add a free water bottle. https://github.com/Vinai/module-example-giftitem TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 23. Training Module: Example_GiftItem The GiftItem total model is responsible for setting the price of gift items to zero and adjusting the subtotal. https://github.com/Vinai/module-example-giftitem TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 24. What does this kata teach? TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 25. (1/2) Generic skills: → TDD Red-Green-Refactor process → Working with test doubles → Separating pure functions from functions with side effects TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 26. (2/2) Magento skills: → Test driving Magento development → The totals architecture → Dealing with Law of Demeter violations TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 27. Tomorrow How you can get started: # Create module dir mkdir -p app/code/Example && cd app/code/Example # Clone repo git clone https://github.com/Vinai/module-example-giftitem.git GiftItem cd GiftItem # Check out git tag git checkout beginning-of-kata TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 28. Kata Task: Use TDD to create the GiftItem total model ModelTotalsGiftItemAddressTotal Implement the collect() method. TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 29. Target behavior: collect() → Subtract gift item row totals sum and base row totals sum from the subtotal → Set calculation_price and base_calculation_price of every gift item to zero → Call calcRowTotal on each gift TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp
  • 30. Enjoy the session and feel those reflexes get sharper! TDD Magento 2 Kata - contact@vinaikopp.com - twitter://vinaikopp