The community around the Pest PHP testing framework has added some new excellent features, including higher-order expectations, ray() debugging integration, and a VS Code snippets extension for Pest PHP.
Higher Order Expectations
Today, we are proud to introduce "Higher Order Expectations" to @pestphp. 🪄— Nuno Maduro (@enunomaduro) June 11, 2021
This feature allows you to create expectations on methods or properties of the original expectation value. 🤯
📚 https://t.co/90q9KZGZVM. pic.twitter.com/fzpjr1lxy0
Here’s that before and after code based on the screenshot above:
1// Before2expect($user->first_name)->toEqual('Nuno');3expect($user->last_name)->toEqual('Maduro');4expect($user->withTitle('Mr'))->toEqual('Mr Nuno Maduro');56// After7expect($user)8 ->first_name->toEqual('Nuno')9 ->last_name->toEqual('Maduro')10 ->withTitle('Mr')->toEqual('Mr Nuno Maduro');
This feature also works with array data as well:
1expect(['name' => 'Nuno', 'companies' => ['Pest', 'Laravel']])2 ->name->toEqual('Nuno')3 ->companies->toHaveCount(2)->each->toBeString
Check out the Expectations documentation for complete examples and information around expectations in PEST.
Use Ray App On Any Expectation
Here’s a snippet of what using the
ray() function looks like:
Check out the ray() expectations documentation to learn more.
Pest Snippets for VS Code
✨ Pest snippets for VS Code ✨— Dan (@DanSysAnalyst) June 14, 2021
🔥 Check out my new extension with code snippets for writing tests even faster and with the joy and simplicity, we all know and love in #Pest.@pestphp #vscode #laravel #php
👉 https://t.co/l6M6l5h462 pic.twitter.com/A2lIFZ5a80
For a complete list of snippets, check out the Pest Snippets - Visual Studio Marketplace page.
If you’d like to get started with Pest PHP, be sure to check out the following resources: