SlideShare a Scribd company logo
1 of 223
Advanced Test Driven-
Development
Scott Keck-Warren
php[tek] 2024
scottKeckWarren@phpc.social https://tinyurl.com/tdd-tek-2024
Simplicity
Create a Class That Adds Two
Numbers
Send an SMS Message to User
When Tasks Is Completed
Events
APIs
Databases
Bugs
Complexity
Complexity
Simplicity
Advanced Test Driven-
Development
Agenda
• A Brief Overview Of Test Driven-Development (TDD)
• Test Automation Pyramid
• Picking What To Test
• Events In TDD Environment
• APIs in TDD Environment
• Databases in TDD Environment
• Bugs in TDD Environment
Objective
Give you:
1. Tools
2. Techniques
3. Know How
Scott Keck-Warren
Director of Technology
@ WeCare Connect
Scott Keck-Warren
PHP Developer
Scott Keck-Warren
Director of Technology
@ WeCare Connect
Scott Keck-Warren
Content Creator
php[architect] YouTube Channel
Community Corner Podcast
A Brief Overview Of Test Driven-
Development (TDD)
What is TDD?
• Abbreviated TDD
• Test-first software development process
• Create suite of automated tests
What is TDD?
• Short cycles of 5 phases (<5 minutes)
• Hundreds of cycles each day
Add A
New Test
Run All Tests to
See Failures
Make a change
Run Tests to
See Success
Refactor
Add A
New Test
Run All Tests
New Test
Run All Tests
to See Failures
Make a change
un Tests to
ee Success
Make a chan
Run Tests to
See Success
New Test
Refactor
Add A
New Test
Run All Tests to
See Failures
Make a change
Run Tests to
See Success
Refactor
What Is the Benefit of TDD?
TDD Gives Us Confidence
Confidence to Make Changes
Confidence Changes Won’t
Break Production
What is the benefit of TDD?
• TDD -> Generate automated tests
• Automated Tests are infinitely repeatable
Test Automation Pyramid
Test Automation Pyramid
(Scott’s Version)
Manual Testing
Manual Testing
• Tests how all components work together
• “Sanity” Checking
• Does everything look “right"
• Does it flow correctly
Manual Testing
• Use a checklist or design document
• VERY slow and error prone
• Can never get completely away from this
• Ideally this is smallest part of test suite
End-to-End Tests
End-to-End Tests
• Generally involves headless browser or full API requests
• Multi-step processes
• Checkout process
• Sign-up process
End-to-End Tests
• Automated using testing framework like PHPUnit/Pest/Cypress
• Faster than manual testing AND less error prone
• Brittle due to large number of components
Integration Tests
Integrations Tests
• Tests how classes work when integrated together
• Controllers + forms + views + models to gether
Integrations Tests
• Automated using testing framework like PHPUnit/Pest
• Faster than manual and end-to-end testing AND less error prone
• Less brittle
Unit Tests
Unit Tests
• Test how one class operates in isolation
• “Gold Standard”
• Test as much as possible here
Unit Tests
• Automated using testing framework like PHPUnit/Pest
• VERY fast
Unit
Manual
End-To-End
Integration
Unit
Manual
End-To-End
Integration
Unit
End-To-End
Integration
Manual
Unit
Manual
Integration
Manual
End-To-End
Manual
Unit
Integration
Manual
Unit
End-To-End
Feature
Manual
Picking What To Test
As a standard user, when a task is completed
send an SMS message the user who
delegated the task
As a standard user, when a task is
completed send an SMS message the user
who delegated the task
Goal: Small Bite Sized Pieces
User Navigates to Task
User Logs Into System
User Logs Into System
User Navigates to Task
User Clicks “Complete”
Button
User Navigates to Task
User Clicks “Complete”
Button
Browser requests
/tasks/#/complete
User Clicks “Complete”
Button
Browser requests
/tasks/#/complete
Router routes request
Browser requests
/tasks/#/complete
Router routes request
Permissions Are Checked
Router routes request
Permissions Are Checked
TaskCompleted Event is
Raised
Permissions Are Checked
TaskCompleted Event is
Raised
Event is Handled
TaskCompleted Event is
Raised
Event is Handled
Listener is Found and Run
Event is Handled
Listener is Found and Run
Message is Generated To
Original User
Listener is Found and Run
Message is Generated To
Original User
Message is Sent to SMS
Service
Message is Generated To
Original User
Message is Sent to SMS
Service
User Logs Into System
User Navigates to Task
User Clicks “Complete” Button
Browser requests /tasks/#/complete
Router routes request
Permissions Are Checked
TaskCompleted Event is Raised
Event is Handled
Listener is Found and Run
Message is Generated To Original
User
Message is Sent to SMS Service
User Logs Into System
User Navigates to Task
User Clicks “Complete” Button
Browser requests /tasks/#/complete
Router routes request
Permissions Are Checked
TaskCompleted Event is Raised
Event is Handled
Listener is Found and Run
Message is Generated To Original
User
Message is Sent to SMS Service
Router routes request
Permissions Are Checked
TaskCompleted Event is Raised
Event is Handled
Listener is Found and Run
Message is Generated To Original
User
Message is Sent to SMS Service
How Do We Make This Simpler?
Remove External Dependencies
Dependency: Relationships
Between Software Components
External
Dependencies: From 3rd Party
Internal
Dependencies: From Team
Don’t Worry About
Dependencies
Don’t Worry About
Code You Didn’t Write!
Assume Others Are Testing
Their Own Code
Router routes request
Permissions Are Checked
TaskCompleted Event is Raised
Event is Handled
Listener is Found and Run
Message is Generated To Original
User
Message is Sent to SMS Service
Message is Generated To Original
User
Message is Sent to SMS Service
TaskCompleted Event is Raised
Message is Generated To Original
User
Message is Sent to SMS Service
TaskCompleted Event is Raised
Events In TDD Environment
Unit
Test Doubles
and
Dependency Injection (DI)
Test Doubles
“[O]bjects or procedures that look
and behave like their release-
intended counterparts, but are
actually simplified versions that
reduce the complexity and
facilitate testing” - wikipedia
Test Doubles
Test Doubles
?
?
Test Doubles
?
Mocking
Mocking
“[M]ock objects are simulated
objects that mimic the behaviour
of real objects in controlled
ways”
- wikipedia
Mock
Spy
Test Doubles
?
Mocking
Mock Spy
Test Doubles
Stubbing
Mocking
Mock Spy
Stubbing
“[T]est stubs are programs that
simulate the behaviours of
software component … [t]est
stubs provide canned answers to
calls made during the test” -
Wikipedia
Stub
Dummy
Fake
Test Doubles
Stubbing
Dummy
Fake
Stub
Mocking
Mock Spy
Test Doubles
Stubbing(Incoming)
Dummy
Fake
Stub
Mocking(Outgoing)
Mock Spy
Creating Test Doubles
Mockery_2_League_Event_EventDispatcher
Using Mockery
LeagueEventEventDispatcher
dispatch()
subscribeTo()
dispatch()
Creating Test Doubles
Creating Test Doubles
Creating Test Doubles
Creating Test Doubles
1. Use Mockery to generate them
1. Mockery does the assertions
2. Write reusable classes
1. We do the assertions in tests
Dependency Injection (DI)
Dependency
Injection (DI)
“[D]ependency injection is a
programming technique in which
an object or function receives
other objects or functions that it
requires, as opposed to creating
them internally” - wikipedia
Dependency Injection (DI)
Dependency Injection (DI)
Dependency Injection (DI)
Dependency Injection (DI)
Dependency Injection (DI)
Dependency Injection (DI)
Dependency Injection (DI)
Dependency Injection (DI)
Dependency Injection (DI)
TaskCompleted Event is Raised
tests/Unit/Controllers/TaskControllerTest.php
tests/Unit/Controllers/TaskControllerTest.php
tests/Unit/Controllers/TaskControllerTest.php
tests/Unit/Controllers/TaskControllerTest.php
tests/Unit/Controllers/TaskControllerTest.php
src/Controllers/TaskController.php
tests/Unit/Controllers/TaskControllerTest.php
tests/Unit/Controllers/TaskControllerTest.php
tests/Unit/Controllers/TaskControllerTest.php
tests/Unit/Controllers/TaskControllerTest.php
tests/Unit/Controllers/TaskControllerTest.php
tests/Unit/Controllers/TaskControllerTest.php
src/Controllers/TaskController.php
src/Controllers/TaskController.php
src/Events/TaskCompleted.php
tests/Unit/Controllers/TaskControllerTest.php
Events
Test Doubles
Stubbing(Incoming)
Dummy
Fake
Stub
Mocking(Outgoing)
Mock Spy
Message is Generated To Original
User
Message is Sent to SMS Service
TaskCompleted Event is Raised
Message is Generated To Original
User
Message is Sent to SMS Service
TaskCompleted Event is Raised
Message is Generated To Original
User
Message is Sent to SMS Service
TaskCompleted Event is Raised
APIs in TDD Environment
Message is Sent to SMS Service
Message is Sent to SMS Service
1. Costs money every time we send SMS message
2. Hard to check SMS messages have been sent
Using TDD To Learn
3rd Party Code
Using TDD To Learn a 3rd Party Code
• Need to learn API (new to me)
• Going to create own suite of tools for 3rd party API
• Build a service to abstract -> easier to create a test double
Using TDD To Learn a 3rd Party Code
• Going to use TDD
• Need to manually check results
• Or build tool to check results
End-To-End
tests/Services/SmsServiceTest.php
phpunit.xml
phpunit.xml
phpunit.xml
tests/Services/SmsServiceTest.php
tests/Services/SmsServiceTest.php
tests/Services/SmsServiceTest.php
tests/Services/SmsServiceTest.php
tests/Services/SmsServiceTest.php
./vendor/bin/pest tests/Services/SmsServiceTest.php
tests/Services/SmsServiceTest.php
.env
tests/Services/SmsServiceTest.php
tests/Services/SmsServiceTest.php
src/Services/SmsService.php
src/Services/SmsService.php
tests/Services/SmsServiceTest.php
tests/Services/SmsServiceTest.php
tests/Services/SmsServiceTest.php
src/Services/SmsService.php
src/Services/SmsService.php
Message is Generated To Original
User
Message is Sent to SMS Service
TaskCompleted Event is Raised
Message is Generated To Original
User
Message is Sent to SMS Service
TaskCompleted Event is Raised
Databases in TDD Environment
Databases
As a standard user, generate a report of all completed tasks in the past
week.
Databases
1. Don’t Test It
2. Doubles
3. Use the actual database
Change a Column Name
tasks.name
->
tasks.description
Databases
1. Don’t Test It -> missed because it’s not tested
2. Doubles -> missed because it’s not using real data
3. Use the actual database -> caught
Databases
1. Once you start doing this hard to stop
2. Other tests may impact each other
3. Need to worry about polluting DB
Databases
1. Reset DB at start of every test
1. Can be slow as DB structure changes over time
2. Hard to generate test data because it erases
2. Reset DB at start of test run
1. Generate “test” information to pull
2. Keep everything in known good state
Keep Everything in Known Good State?
Keep Everything in Known Good State?
Bugs in TDD Environment
1. Replicate the problem
2. Form a hypothesis
3. Test the hypothesis
4. Repeat until the bug is “fixed”
Bugs
Bugs
Bugs
Bugs
1. Replicate the problem
2. Form a hypothesis
3. Test the hypothesis
4. Repeat until the bug is “fixed”
Bugs
Bugs
1. Replicate the problem
2. Form a hypothesis
3. Test the hypothesis
4. Repeat until the bug is “fixed”
5. Revert the change (git stash)
6. TDD to the fix
What To Tests?
1. Reported Bug: User::getDisplayName()
2. Root Cause: Str::append()?
3. Both?
What You Need to Know
Add A
New Test
Run All Tests to
See Failures
Make a change
Run Tests to
See Success
Refactor
Unit
Manual
End-To-End
Integration
“The Perfect Is the Enemy Of
the Good”
Use Testing Doubles and DI To
Create “Testable” Code
Test Doubles
Stubbing(Incoming)
Dummy
Fake
Stub
Mocking(Outgoing)
Mock Spy
Dependency Injection
3rd Party APIs
1. Can use TDD to learn APIs/libraries
1. Come back to when things break in the future
2. Run separately to avoid costs
Databases
1. Other tests may impact each other
2. Need to worry about polluting DB
1. Reset DB
2. Transactions
3. Helper functions
Bugs
1. Replicate the problem
2. Form a hypothesis
3. Test the hypothesis
4. Repeat until the bug is “fixed”
5. Revert the change (git stash)
6. TDD to the fix
Thank The Speakers
Questions/Follow Me
• Questions?
• Please rate the talk
• https://tinyurl.com/tdd-tek-2024
• @scottKeckWarren@phpc.social

More Related Content

Similar to Advanced Test Driven-Development @ php[tek] 2024

varun JENKINS.pptx
varun JENKINS.pptxvarun JENKINS.pptx
varun JENKINS.pptxVgPolampalli
 
Anatomy of a Build Pipeline
Anatomy of a Build PipelineAnatomy of a Build Pipeline
Anatomy of a Build PipelineSamuel Brown
 
Automated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and ChallengesAutomated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and ChallengesTao Xie
 
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...Postman
 
Getting Started with Test-Driven Development at PHPtek 2023
Getting Started with Test-Driven Development at PHPtek 2023Getting Started with Test-Driven Development at PHPtek 2023
Getting Started with Test-Driven Development at PHPtek 2023Scott Keck-Warren
 
Application Lifecycle Management
Application Lifecycle ManagementApplication Lifecycle Management
Application Lifecycle ManagementAmazon Web Services
 
AfterTest Madrid March 2016 - DevOps and Testing Introduction
AfterTest Madrid March 2016 - DevOps and Testing IntroductionAfterTest Madrid March 2016 - DevOps and Testing Introduction
AfterTest Madrid March 2016 - DevOps and Testing IntroductionPeter Marshall
 
Agile Engineering Best Practices by Richard Cheng
Agile Engineering Best Practices by Richard ChengAgile Engineering Best Practices by Richard Cheng
Agile Engineering Best Practices by Richard ChengExcella
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Scott Keck-Warren
 
Automation Testing with Test Complete
Automation Testing with Test CompleteAutomation Testing with Test Complete
Automation Testing with Test CompleteVartika Saxena
 
(Agile) engineering best practices - What every project manager should know
(Agile) engineering best practices - What every project manager should know(Agile) engineering best practices - What every project manager should know
(Agile) engineering best practices - What every project manager should knowRichard Cheng
 
Open Source Software Testing Tools
Open Source Software Testing ToolsOpen Source Software Testing Tools
Open Source Software Testing ToolsVaruna Harshana
 
Writing better tests for your java script app
Writing better tests for your java script appWriting better tests for your java script app
Writing better tests for your java script appJakeGinnivan
 
The Continuous delivery value - Funaro
The Continuous delivery value - FunaroThe Continuous delivery value - Funaro
The Continuous delivery value - FunaroCodemotion
 
The Continuous delivery Value @ codemotion 2014
The Continuous delivery Value @ codemotion 2014The Continuous delivery Value @ codemotion 2014
The Continuous delivery Value @ codemotion 2014David Funaro
 
Testing and DevOps Culture: Lessons Learned
Testing and DevOps Culture: Lessons LearnedTesting and DevOps Culture: Lessons Learned
Testing and DevOps Culture: Lessons LearnedLB Denker
 

Similar to Advanced Test Driven-Development @ php[tek] 2024 (20)

varun JENKINS.pptx
varun JENKINS.pptxvarun JENKINS.pptx
varun JENKINS.pptx
 
Anatomy of a Build Pipeline
Anatomy of a Build PipelineAnatomy of a Build Pipeline
Anatomy of a Build Pipeline
 
Automated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and ChallengesAutomated Developer Testing: Achievements and Challenges
Automated Developer Testing: Achievements and Challenges
 
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
 
Getting Started with Test-Driven Development at PHPtek 2023
Getting Started with Test-Driven Development at PHPtek 2023Getting Started with Test-Driven Development at PHPtek 2023
Getting Started with Test-Driven Development at PHPtek 2023
 
Application Lifecycle Management
Application Lifecycle ManagementApplication Lifecycle Management
Application Lifecycle Management
 
AfterTest Madrid March 2016 - DevOps and Testing Introduction
AfterTest Madrid March 2016 - DevOps and Testing IntroductionAfterTest Madrid March 2016 - DevOps and Testing Introduction
AfterTest Madrid March 2016 - DevOps and Testing Introduction
 
Agile Engineering Best Practices by Richard Cheng
Agile Engineering Best Practices by Richard ChengAgile Engineering Best Practices by Richard Cheng
Agile Engineering Best Practices by Richard Cheng
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023
 
Build Time Hacking
Build Time HackingBuild Time Hacking
Build Time Hacking
 
Automation Testing with Test Complete
Automation Testing with Test CompleteAutomation Testing with Test Complete
Automation Testing with Test Complete
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test automation proposal
Test automation proposalTest automation proposal
Test automation proposal
 
(Agile) engineering best practices - What every project manager should know
(Agile) engineering best practices - What every project manager should know(Agile) engineering best practices - What every project manager should know
(Agile) engineering best practices - What every project manager should know
 
Open Source Software Testing Tools
Open Source Software Testing ToolsOpen Source Software Testing Tools
Open Source Software Testing Tools
 
Writing better tests for your java script app
Writing better tests for your java script appWriting better tests for your java script app
Writing better tests for your java script app
 
The Continuous delivery value - Funaro
The Continuous delivery value - FunaroThe Continuous delivery value - Funaro
The Continuous delivery value - Funaro
 
The Continuous delivery Value @ codemotion 2014
The Continuous delivery Value @ codemotion 2014The Continuous delivery Value @ codemotion 2014
The Continuous delivery Value @ codemotion 2014
 
Testing and DevOps Culture: Lessons Learned
Testing and DevOps Culture: Lessons LearnedTesting and DevOps Culture: Lessons Learned
Testing and DevOps Culture: Lessons Learned
 
DevOps on AWS
DevOps on AWSDevOps on AWS
DevOps on AWS
 

Recently uploaded

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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 educationjfdjdjcjdnsjd
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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...Drew Madelung
 
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...Miguel Araújo
 
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...Neo4j
 
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 Takeoffsammart93
 
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.pdfUK Journal
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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...
 
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...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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...
 
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
 
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
 

Advanced Test Driven-Development @ php[tek] 2024

Editor's Notes

  1. (50 min)
  2. At it’s core TDD thrives on it’s <slide> But that has a downside
  3. When we (including me) explain it to people earlier in their journey Do them a horrible disservice End up with examples that just add two numbers together
  4. Take this knowledge back to work Open project management tool and find
  5. Give Up
  6. All that is <slide> <slide> that TDD I haven’t given them the tools to attack
  7. My goal in the next 50 minutes is to give you some tools, techniques, and know how Get rid of the complexity and back to <click>
  8. Goal:give you tools to tackle even the hardest TDD problem Very example heavy
  9. For those of you who haven’t met me my name is …
  10. Professional PHP Developer for 16 years // team lead/CTO role for 11 of those 16
  11. Currently Director of Technology at WeCare Connect Survey solutions to improve employee and resident retention at skilled nursing facilities Use PHP for our backend Also …
  12. TDD is a test-first software development process that uses short development cycles to write very specific test cases and then modify our code so the tests pass.
  13. TDD consists of five phases that we will repeat as we modify our code. Each of the phases happens very quickly and we might go through all five phases in less than a minute.
  14. The first thing we're going to do is write a failing test. We'll use this failing test to help determine when we've achieved our expected functionality.
  15. In this step, we're going to run the test to make sure our test fails before we move on to the next phase. It's very easy to write a test that doesn't fail so we **always** run our test to verify it's failing before moving to the next phase.
  16. 3. Make a little change Now our goal is to change the smallest amount of code possible to get that test to pass. We don't want to change any more than is necessary because that extra bit of change wasn't made using TDD and is potentially not tested. We don't need perfect code in this phase we just need code that makes the test pass. It's very easy to get caught up in making sure everything is perfect but that's not the goal here. Perfect comes later.
  17. 4. Run all tests and see them all succeed Now that we've made our change we can run our test and see that it passes new test and any other tests. If it doesn't then we just jump back to phase #3 and keep making small changes until it does.
  18. Now that we have our tests passing we're going to take a break and inspect both our test code and our code under test to see where we can make changes so it's easier for future developers to read, understand, and maintain.
  19. Could also be red/green/refactor
  20. When I mentor new team members I tell them our application has four types of tests
  21. General cost increases upwards why we want mostly bulk at bottom If you’re test suite doesn’t look like this don’t stress
  22. This is my idea but You and your team have to pick what works for you “The Perfect is the Enemy of The Good” It’s better to have some
  23. What you don’t want is Hard to work in this environment Burn out is real
  24. My goal is to break this into small enough chunks I can complete it
  25. Seems a little complex Makes you want to throw your hands up and say this is impossible! This is where TDD “falls” down
  26. Seems a little complex Makes you want to throw your hands up and say this is impossible! This is where TDD “falls” down
  27. Seems a little complex Makes you want to throw your hands up and say this is impossible! This is where TDD “falls” down
  28. Seems a little complex Makes you want to throw your hands up and say this is impossible! This is where TDD “falls” down
  29. Seems a little complex Makes you want to throw your hands up and say this is impossible! This is where TDD “falls” down
  30. Seems a little complex Makes you want to throw your hands up and say this is impossible! This is where TDD “falls” down
  31. Seems a little complex Makes you want to throw your hands up and say this is impossible! This is where TDD “falls” down
  32. Seems a little complex Makes you want to throw your hands up and say this is impossible! This is where TDD “falls” down
  33. Seems a little complex Makes you want to throw your hands up and say this is impossible! This is where TDD “falls” down
  34. Seems a little complex Makes you want to throw your hands up and say this is impossible! This is where TDD “falls” down
  35. Seems a little complex Makes you want to throw your hands up and say this is impossible! This is where TDD “falls” down
  36. Seems a little complex Makes you want to throw your hands up and say this is impossible! This is where TDD “falls” down
  37. What if we simplify this? First 4 items are browser -> ignore those
  38. Makes it a lot smaller still a lot though right?
  39. Several types of dependencies
  40. Software your team didn’t write Looking at our chart we have 3rd party api And maybe events
  41. Software your team did write Fun thing about internal dependencies -> from your perspective external dependency
  42. When doing TDD on your code you {slide}
  43. Remove all external pieces
  44. Left with just a few pieces easier to handle Two major pieces left seems like something we could tackle Both of which we can handle with unit tests
  45. A finished solutions Problem: hard to test
  46. Goal in unit testing range Two things we need to discuss to fix
  47. Test doubles are the superheroes of unit testing, allowing us to replace real components with stand-ins during tests that mimic their behavior. This replacement fosters isolation, testing components separately from their dependencies.
  48. Two main branches of test doubles
  49. A mock object is an object that meticulously records method calls and takes pride in asserting whether expected interactions took place. Mocks excel when your mission is to validate the interactions between the real object being under test and its collaborators.
  50. A spy is an implementation to verify a specific behavior.
  51. A stub provides predetermined responses to calls made during a test. It’s ideal for scenarios when you’re more concerned with the behavior of the object under test than its interactions with other components. Think of it as a scripted actor playing a role during testing.
  52. A stub is the simplest implementation with a hardcoded behavior.
  53. A dummy is a just simple implementation that does nothing.
  54. A fake is a simplified implementation to simulate the original behavior.
  55. Mocks -> Useful for seeing what’s coming out of your code Stubbing -> useful for when you need incoming
  56. Use tool (Mockery) to generate them and have it do the assertions
  57. Write reusable classes and assert results in our tests
  58. Both valid I start out
  59. Creating testable code -> requires architecture decision We want to use DI
  60. Without DI Example class Problem: code is written to specific implementation of dependency Hard to swap out These are simple but could be complicated
  61. With DI Example class Pass dependencies as a parameter (either function or class constructor)
  62. Downside to this: Have to define how things are created This example uses PHP-DI
  63. Phase 1: Write a little test Specify explicitly what you are testing
  64. Kinda wordy
  65. // Arrange: Bring the system under test in the desired state. Prepare dependencies, arguments and finally construct the SUT. // Act: Invoke a tested element. // Assert: Verify the result, the final state, or the communication with collaborators.
  66. // Arrange: Bring the system under test in the desired state. Prepare dependencies, arguments and finally construct the SUT. // Act: Invoke a tested element. // Assert: Verify the result, the final state, or the communication with collaborators.
  67. // Arrange: Bring the system under test in the desired state. Prepare dependencies, arguments and finally construct the SUT. // Act: Invoke a tested element. // Assert: Verify the result, the final state, or the communication with collaborators.
  68. Phase 2
  69. Phase 3
  70. Phase 4 and 5 - see how fast that was?
  71. Back to phase 1
  72. That’s how to test events but we can test so much more now
  73. You now have a bunch of tools to create unit tests for any kind of interactions between classes
  74. Leads into our next topic <slide>
  75. Picked SMS messages two reasons because Vonage is a sponsor Hard to test because <click>
  76. Goal in unit testing range Two things we need to discuss to fix
  77. Don’t want it running every time because cost
  78. Don’t want it running every time because cost
  79. You may have noticed I never had a failing test In this case: didn’t even know what that would be
  80. notice: copy and paste and not cut and paste
  81. notice: copy and paste and not cut and paste
  82. notice: copy and paste and not cut and paste
  83. notice: copy and paste and not cut and paste
  84. Purists say never use the DB but that hides problems
  85. Much less plan and more figure it out
  86. What I expect is to have the getDisplayName() return my name but it returns my last name only
  87. This broke once Might brake again
  88. Much less plan and more figure it out
  89. Bugs are a different beast Have to “invert” our process a little
  90. I’m really belt and suspenders here I do both gives us extra coverage (plus someone must have not done it before)
  91. General cost increases upwards why we want mostly bulk at bottom
  92. Bugs are a different beast Have to “invert” our process a little
  93. Thank the sponsors