SlideShare a Scribd company logo
U N I T T E S T I N G I N P H P A N D
L A R A V E L F R A M E W O R K
‣ LE MAI VIEN
‣ 28 years old
‣ Asian Tech Inc.
‣ Technical Leader
‣ Backend developer
‣ 5 years of experiences
A B O U T M E
W H A T I S H I G H Q U A L I T Y
C O D E ? ? ?
I T ’ S
G O O D ? ? ?
W H A T I S H I G H Q U A L I T Y
C O D E ? ? ?
S E L F E XP L A I N I N G D O C U M E N T A T I O N
C L E A R - R E A D A B L E
A R C H I T E C T U R E D E S I G N
D E S I G N P A T T E R N
T E S T C O D E
E A S E O F
E XT E N S I B I L I T Y
‣ Test by human
‣ Create test cases
‣ Repeat many times
‣ Difficult to check affection
‣ Take a lot of time and efforts
M A N U A L T E S T I N G
W H A T D O D E V E L O P E R S D O W H E N
T H E Y I M P L E M E N T
C O D E T E S T
Switch
Y O U A L R E A D Y T E S T Y O U R
C O D E
S U B M I T A F O R M , C H E C K D B
C O N S O L E . L O G ( )
D U M P V A R I A B L E S
L O G T O F I L E
C H R O M E D E B U G T O O L
…
W R I T E C O D E T O T E S T Y O U R
C O D E
‣ Check code by code
‣ Can reuse many time
‣ There are many kinds of
test code
W H Y N O T ?
T E S T I N G M E T H O D S
‣ Unit testing
‣ Integration testing
‣ Functional testing
‣ Acceptance testing
‣ E2E testing
W H Y D E V E L O P E R H A V E T O W R I T E
C O D E T O T E S T T H E I R C O D E
‣ Quality of code
‣ Find bugs early
‣ Facilitates changes simplifies integration
‣ Provide document
‣ Debugging process
‣ Design
‣ Reduce cost
U N I T T E S T I N G
‣ Test a smallest piece of testable code
‣ Check the Code is working as expected
‣ Testing in isolation
‣ Tests should not be order-dependent
U N I T T E S T I N G
Unit tests
Production code
3 steps of a Unit test
1. Arrange
2. Act
3. Assert
1 0 0 1 R E A S O N S T O S K I P U N I T
T E S T
‣ I don’t have time
‣ Deadline is too short
‣ I don’t know how to do
‣ Client doesn’t want to write UT
‣ …
A L L J U S T E X C U S E , L E T W R I T E U N I T T E S T
U N I T T E S T I S I M P O R T A N T , I S N ’ T
I T ?
[DevDay2018] Unit testing in PHP and Laravel Framework - Unit testing in PHP and Laravel Framework
C O D E C O V E R A G E
T e s t e d
T e s t e d
C r e a t e m o c k
o b j e c t
M O C K E R Y
ple yet flexible PHP mock object framework for use in unit te
S E T E X P E C T A T I O N S T O M O C K
O B J E C T
T h i s m e t h o d
m u s t b e c a l l e d
e x a c t l y 1 t i m e
Mock vs Stub
Setup
Exercise
Verify state
Teardown
Setup data
Setup Expectations
Exercise
Verify expectations
Verify state
Teardown
U N I T T E S T I N G
‣ Test a smallest piece of code
‣ Testing in isolation
‣ Code coverage
‣ Stub and mock
H O W A B O U T
L A R A V E L ?
I t ’ s n o t u n i t t e s t i n g
I t ’ s f u n c t i o n a l t e s t i n g
L A R A V E L H T T P T E S T
L A R A V E L T E S T J S O N A P I
S U M M A R Y
‣ Manual test
‣ Benefit of writing code to test your code
‣ Phpunit
‣ Unit testing
‣ Code coverage
‣ Another testing methods
T H A N K Y O U F O R L I S T E N I N G
http://asiantech.vn/en/careers

More Related Content

PDF
Test Driven Development en Go con Ginkgo y Gomega
PDF
Seven Fundamentals of a Successful Testing Team
ODP
Assorted TDD tips
PDF
DRAFT - Root Cause Analysis (RCA) Template - RCA
PPTX
Rise of the Heisenbug
PDF
Unit testing - An introduction
PPTX
Testing 101
KEY
Unit Testing Your Application
Test Driven Development en Go con Ginkgo y Gomega
Seven Fundamentals of a Successful Testing Team
Assorted TDD tips
DRAFT - Root Cause Analysis (RCA) Template - RCA
Rise of the Heisenbug
Unit testing - An introduction
Testing 101
Unit Testing Your Application

Similar to [DevDay2018] Unit testing in PHP and Laravel Framework - Unit testing in PHP and Laravel Framework (20)

PDF
Unit testing (Exploring the other side as a tester)
PPTX
An Introduction to unit testing
PDF
What is Unit Testing_ - A Complete Guide.pdf
PDF
Systematic Unit Testing
PDF
Writing Tests Effectively
PPTX
Unit testing & TDD concepts with best practice guidelines.
PDF
DSR Testing (Part 1)
PPTX
Unit Testing talk
PDF
Unit Testing
PDF
Introduction of unit test to management
PDF
Testing untestable code - ConFoo13
PPTX
Writing testable code
PDF
Treat Your Unit Tests As Production Code - DARGO - Amadeus - Soirée du Test L...
PPTX
UNIT TESTING PPT
PDF
What is Unit Testing? - A Complete Guide
PPTX
The Test way
PPTX
Test in action – week 1
PPTX
Developer Testing
PPTX
Unit Testing Full@
PPTX
Regression Testing with Symfony
Unit testing (Exploring the other side as a tester)
An Introduction to unit testing
What is Unit Testing_ - A Complete Guide.pdf
Systematic Unit Testing
Writing Tests Effectively
Unit testing & TDD concepts with best practice guidelines.
DSR Testing (Part 1)
Unit Testing talk
Unit Testing
Introduction of unit test to management
Testing untestable code - ConFoo13
Writing testable code
Treat Your Unit Tests As Production Code - DARGO - Amadeus - Soirée du Test L...
UNIT TESTING PPT
What is Unit Testing? - A Complete Guide
The Test way
Test in action – week 1
Developer Testing
Unit Testing Full@
Regression Testing with Symfony
Ad

More from DevDay Da Nang (20)

PDF
[DevDay2019] Lean UX - By Bryant Castro, Bryant Castro at Wizeline
PPT
[DevDay2019] Why you'll lose without UX Design - By Szilard Toth, CTO at e·pi...
PDF
[DevDay2019] Things i wish I knew when I was a 23-year-old Developer - By Chr...
PDF
[DevDay2019] Designing design teams - Christopher Nguyen, UX Manager at Wizeline
PDF
[DevDay2019] Growth Hacking - How to double the benefits of your startup with...
PDF
[DevDay2019] Collaborate or die: The designers’ guide to working with develop...
PPTX
[DevDay2019] How AI is changing the future of Software Testing? - By Vui Nguy...
PPTX
[DevDay2019] Hands-on Machine Learning on Google Cloud Platform - By Thanh Le...
PPTX
[DevDay2019] Micro Frontends Architecture - By Thang Pham, Senior Software En...
PPTX
[DevDay2019] Power of Test Automation and DevOps combination - One click savi...
PPTX
[DevDay2019] How do I test AI models? - By Minh Hoang, Senior QA Engineer at KMS
PPTX
[DevDay2019] How to quickly become a Senior Engineer - By Tran Anh Minh, CEO ...
PPTX
[Devday2019] Dev start-up - By Le Trung, Founder & CEO at Hifiveplus and Edu...
PDF
[DevDay2019] Web Development In 2019 - A Practical Guide - By Hoang Nhu Vinh,...
PDF
[DevDay2019] Opportunities and challenges for human resources during the digi...
PPTX
[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...
PPTX
[DevDay2019] Do you dockerize? Are your containers safe? - By Pham Hong Khanh...
PPTX
[DevDay2019] Develop a web application with Kubernetes - By Nguyen Xuan Phong...
PPTX
[DevDay2019] Paradigm shift towards effective Scrum - By Tam Doan, Agile Coac...
PDF
[DevDay2019] JAM Stack - By Ngo Thi Ni, Web Developer at Agility IO
[DevDay2019] Lean UX - By Bryant Castro, Bryant Castro at Wizeline
[DevDay2019] Why you'll lose without UX Design - By Szilard Toth, CTO at e·pi...
[DevDay2019] Things i wish I knew when I was a 23-year-old Developer - By Chr...
[DevDay2019] Designing design teams - Christopher Nguyen, UX Manager at Wizeline
[DevDay2019] Growth Hacking - How to double the benefits of your startup with...
[DevDay2019] Collaborate or die: The designers’ guide to working with develop...
[DevDay2019] How AI is changing the future of Software Testing? - By Vui Nguy...
[DevDay2019] Hands-on Machine Learning on Google Cloud Platform - By Thanh Le...
[DevDay2019] Micro Frontends Architecture - By Thang Pham, Senior Software En...
[DevDay2019] Power of Test Automation and DevOps combination - One click savi...
[DevDay2019] How do I test AI models? - By Minh Hoang, Senior QA Engineer at KMS
[DevDay2019] How to quickly become a Senior Engineer - By Tran Anh Minh, CEO ...
[Devday2019] Dev start-up - By Le Trung, Founder & CEO at Hifiveplus and Edu...
[DevDay2019] Web Development In 2019 - A Practical Guide - By Hoang Nhu Vinh,...
[DevDay2019] Opportunities and challenges for human resources during the digi...
[DevDay2019] Python Machine Learning with Jupyter Notebook - By Nguyen Huu Th...
[DevDay2019] Do you dockerize? Are your containers safe? - By Pham Hong Khanh...
[DevDay2019] Develop a web application with Kubernetes - By Nguyen Xuan Phong...
[DevDay2019] Paradigm shift towards effective Scrum - By Tam Doan, Agile Coac...
[DevDay2019] JAM Stack - By Ngo Thi Ni, Web Developer at Agility IO
Ad

Recently uploaded (20)

PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
Modernising the Digital Integration Hub
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPT
What is a Computer? Input Devices /output devices
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
OMC Textile Division Presentation 2021.pptx
PPTX
1. Introduction to Computer Programming.pptx
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
August Patch Tuesday
PPTX
TLE Review Electricity (Electricity).pptx
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Web App vs Mobile App What Should You Build First.pdf
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Group 1 Presentation -Planning and Decision Making .pptx
1 - Historical Antecedents, Social Consideration.pdf
Modernising the Digital Integration Hub
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
What is a Computer? Input Devices /output devices
DP Operators-handbook-extract for the Mautical Institute
NewMind AI Weekly Chronicles – August ’25 Week III
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
A contest of sentiment analysis: k-nearest neighbor versus neural network
A novel scalable deep ensemble learning framework for big data classification...
Hindi spoken digit analysis for native and non-native speakers
OMC Textile Division Presentation 2021.pptx
1. Introduction to Computer Programming.pptx
Enhancing emotion recognition model for a student engagement use case through...
August Patch Tuesday
TLE Review Electricity (Electricity).pptx
WOOl fibre morphology and structure.pdf for textiles
Web App vs Mobile App What Should You Build First.pdf
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx

[DevDay2018] Unit testing in PHP and Laravel Framework - Unit testing in PHP and Laravel Framework

  • 1. U N I T T E S T I N G I N P H P A N D L A R A V E L F R A M E W O R K
  • 2. ‣ LE MAI VIEN ‣ 28 years old ‣ Asian Tech Inc. ‣ Technical Leader ‣ Backend developer ‣ 5 years of experiences A B O U T M E
  • 3. W H A T I S H I G H Q U A L I T Y C O D E ? ? ? I T ’ S G O O D ? ? ?
  • 4. W H A T I S H I G H Q U A L I T Y C O D E ? ? ? S E L F E XP L A I N I N G D O C U M E N T A T I O N C L E A R - R E A D A B L E A R C H I T E C T U R E D E S I G N D E S I G N P A T T E R N T E S T C O D E E A S E O F E XT E N S I B I L I T Y
  • 5. ‣ Test by human ‣ Create test cases ‣ Repeat many times ‣ Difficult to check affection ‣ Take a lot of time and efforts M A N U A L T E S T I N G
  • 6. W H A T D O D E V E L O P E R S D O W H E N T H E Y I M P L E M E N T C O D E T E S T Switch
  • 7. Y O U A L R E A D Y T E S T Y O U R C O D E S U B M I T A F O R M , C H E C K D B C O N S O L E . L O G ( ) D U M P V A R I A B L E S L O G T O F I L E C H R O M E D E B U G T O O L …
  • 8. W R I T E C O D E T O T E S T Y O U R C O D E ‣ Check code by code ‣ Can reuse many time ‣ There are many kinds of test code W H Y N O T ?
  • 9. T E S T I N G M E T H O D S ‣ Unit testing ‣ Integration testing ‣ Functional testing ‣ Acceptance testing ‣ E2E testing
  • 10. W H Y D E V E L O P E R H A V E T O W R I T E C O D E T O T E S T T H E I R C O D E ‣ Quality of code ‣ Find bugs early ‣ Facilitates changes simplifies integration ‣ Provide document ‣ Debugging process ‣ Design ‣ Reduce cost
  • 11. U N I T T E S T I N G ‣ Test a smallest piece of testable code ‣ Check the Code is working as expected ‣ Testing in isolation ‣ Tests should not be order-dependent
  • 12. U N I T T E S T I N G Unit tests Production code
  • 13. 3 steps of a Unit test 1. Arrange 2. Act 3. Assert
  • 14. 1 0 0 1 R E A S O N S T O S K I P U N I T T E S T ‣ I don’t have time ‣ Deadline is too short ‣ I don’t know how to do ‣ Client doesn’t want to write UT ‣ … A L L J U S T E X C U S E , L E T W R I T E U N I T T E S T
  • 15. U N I T T E S T I S I M P O R T A N T , I S N ’ T I T ?
  • 17. C O D E C O V E R A G E
  • 18. T e s t e d T e s t e d
  • 19. C r e a t e m o c k o b j e c t M O C K E R Y ple yet flexible PHP mock object framework for use in unit te
  • 20. S E T E X P E C T A T I O N S T O M O C K O B J E C T T h i s m e t h o d m u s t b e c a l l e d e x a c t l y 1 t i m e
  • 21. Mock vs Stub Setup Exercise Verify state Teardown Setup data Setup Expectations Exercise Verify expectations Verify state Teardown
  • 22. U N I T T E S T I N G ‣ Test a smallest piece of code ‣ Testing in isolation ‣ Code coverage ‣ Stub and mock
  • 23. H O W A B O U T L A R A V E L ?
  • 24. I t ’ s n o t u n i t t e s t i n g I t ’ s f u n c t i o n a l t e s t i n g L A R A V E L H T T P T E S T
  • 25. L A R A V E L T E S T J S O N A P I
  • 26. S U M M A R Y ‣ Manual test ‣ Benefit of writing code to test your code ‣ Phpunit ‣ Unit testing ‣ Code coverage ‣ Another testing methods
  • 27. T H A N K Y O U F O R L I S T E N I N G http://asiantech.vn/en/careers