Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
98
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
220
Other Decks in Programming
See All in Programming
Serena MCPのすすめ
wadakatu
4
1k
チームの境界をブチ抜いていけ
tokai235
0
180
株式会社 Sun terras カンパニーデック
sunterras
0
310
Web フロントエンドエンジニアに開かれる AI Agent プロダクト開発 - Vercel AI SDK を観察して AI Agent と仲良くなろう! #FEC余熱NIGHT
izumin5210
3
530
Flutterで分数(Fraction)を表示する方法
koukimiura
0
130
overlayPreferenceValue で実現する ピュア SwiftUI な AdMob ネイティブ広告
uhucream
0
180
あなたとKaigi on Rails / Kaigi on Rails + You
shimoju
0
160
What's new in Spring Modulith?
olivergierke
1
150
2分台で1500examples完走!爆速CIを支える環境構築術 - Kaigi on Rails 2025
falcon8823
3
3.6k
iOSエンジニア向けの英語学習アプリを作る!
yukawashouhei
0
190
CSC509 Lecture 05
javiergs
PRO
0
300
開発生産性を上げるための生成AI活用術
starfish719
3
1k
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.6k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
45
2.5k
Leading Effective Engineering Teams in the AI Era
addyosmani
5
420
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.5k
Rebuilding a faster, lazier Slack
samanthasiow
84
9.2k
A better future with KSS
kneath
239
18k
For a Future-Friendly Web
brad_frost
180
9.9k
Visualization
eitanlees
149
16k
RailsConf 2023
tenderlove
30
1.2k
Done Done
chrislema
185
16k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
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!