$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Pest: bring back the joy of testing in PHP
Search
Claudio La Barbera
June 01, 2023
Programming
0
100
Pest: bring back the joy of testing in PHP
A brief introduction to Pest: the new PHP testing framework with a focus on simplicity
Claudio La Barbera
June 01, 2023
Tweet
Share
More Decks by Claudio La Barbera
See All by Claudio La Barbera
Wordpress + Laravel Mix
thebatclaudio
0
230
Other Decks in Programming
See All in Programming
AWS CDKの推しポイントN選
akihisaikeda
1
220
関数の挙動書き換える
takatofukui
4
760
connect-python: convenient protobuf RPC for Python
anuraaga
0
320
Evolving NEWT’s TypeScript Backend for the AI-Driven Era
xpromx
0
210
sbt 2
xuwei_k
0
110
GeistFabrik and AI-augmented software development
adewale
PRO
0
220
知られているようで知られていない JavaScriptの仕様 4選
syumai
0
650
S3 VectorsとStrands Agentsを利用したAgentic RAGシステムの構築
tosuri13
4
220
dotfiles 式年遷宮 令和最新版
masawada
1
210
Microservices Platforms: When Team Topologies Meets Microservices Patterns
cer
PRO
1
700
Atomics APIを知る / Understanding Atomics API
ssssota
1
230
AIコードレビューがチームの"文脈"を 読めるようになるまで
marutaku
0
200
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.2k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.3k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
Typedesign – Prime Four
hannesfritz
42
2.9k
Java REST API Framework Comparison - PWX 2021
mraible
34
9k
Producing Creativity
orderedlist
PRO
348
40k
GitHub's CSS Performance
jonrohan
1032
470k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
The Cult of Friendly URLs
andyhume
79
6.7k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.3k
Transcript
Bring back the joy of testing in PHP Tech and
Beer #2, 31st May 2023 Sponsored by
{ “name”: “Claudio La Barbera”, “role”: “Full Stack Developer”, “company”:
“Angelini Consumer”, “linkedin”: “https://www.linkedin.com/in/claudio-la-barbera”, “github”: “https://github.com/thebatclaudio” }
What is PEST? Pest is a testing framework with a
focus on simplicity, meticulously designed to bring back the joy of testing in PHP. pestphp.com
PEST is built on top of PHPUnit! Your current PHPUnit
test suite will work flawlessly with Pest. No need to change a thing.
Installation composer require pestphp/pest --dev --with-all-dependencies First step: require Pest
as a “dev” dependency on your project: Second step: initialize Pest on your project: ./vendor/bin/pest --init Finally: you can run your tests: ./vendor/bin/pest php artisan test If you are using Laravel you can also run:
Installation Here is an example of the output in a
new Laravel project:
Installation Here is an example of the folder structure in
a new Laravel project:
From PHPUnit to Pest: PHPUnit
From PHPUnit to Pest: Pest
Writing tests
test() function
test() function
it() function
skip() function
skip() function
skip() function
Expectation API
Assert multiple conditions
Assert multiple conditions with expect() function
Datasets
Using datasets
Using datasets
Using datasets
Using datasets
Bound Datasets
Bound Datasets
Sharing Datasets
Sharing Datasets
Sharing Datasets
Sharing Datasets
Database
Using database
Using database
Using database
Using database
Demo We will integrate Pest on a simple Laravel project
that expose some APIs. https://github.com/thebatclaudio/bat-tasks
Testing API: example POST /api/tasks Payload: ONLY ADMIN CAN CREATE
TASKS!
Testing API: example
Testing API: example
Testing API: example
Testing API: example
Custom helpers
Custom helpers
Custom helpers
Custom helpers
Check coverage (--coverage option) ./vendor/bin/pest --coverage
Check coverage (--min option) ./vendor/bin/pest --coverage --min=50
Parallel Testing ./vendor/bin/pest --parallel
Parallel Testing ./vendor/bin/pest --parallel --processes=20
In conclusion, Pest: • is easy to use • is
easy to learn • is easy to read • make easy to migrate from PHPUnit • has a growing community and frequent updates
Some links: • https://pestphp.com/ • https://github.com/pestphp/pest • https://www.youtube.com/watch?v=MqiGA34ZrQU • https://laravel.com/docs/10.x/readme
Thank you!