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
97
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
MCPでVibe Working。そして、結局はContext Eng(略)/ Working with Vibe on MCP And Context Eng
rkaga
5
2.3k
AI Coding Agentのセキュリティリスク:PRの自己承認とメルカリの対策
s3h
0
200
Azure SRE Agentで運用は楽になるのか?
kkamegawa
0
2.2k
AIでLINEスタンプを作ってみた
eycjur
1
230
アプリの "かわいい" を支えるアニメーションツールRiveについて
uetyo
0
260
AWS発のAIエディタKiroを使ってみた
iriikeita
1
180
開発チーム・開発組織の設計改善スキルの向上
masuda220
PRO
20
11k
CJK and Unicode From a PHP Committer
youkidearitai
PRO
0
110
testingを眺める
matumoto
1
140
はじめてのMaterial3 Expressive
ym223
2
290
アセットのコンパイルについて
ojun9
0
120
ProxyによるWindow間RPC機構の構築
syumai
3
1.2k
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
74
5k
Become a Pro
speakerdeck
PRO
29
5.5k
Gamification - CAS2011
davidbonilla
81
5.4k
Mobile First: as difficult as doing things right
swwweet
224
9.9k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
Faster Mobile Websites
deanohume
309
31k
Building an army of robots
kneath
306
46k
Testing 201, or: Great Expectations
jmmastey
45
7.7k
A Tale of Four Properties
chriscoyier
160
23k
Building Applications with DynamoDB
mza
96
6.6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
188
55k
jQuery: Nuts, Bolts and Bling
dougneiner
64
7.9k
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!