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