PEST PHP now includes higher-order expectations, Ray debugging integration, and more!

News

June 15th, 2021

pest-php-dark.png

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

Luke Downing and Sam Rowden contributed higher order expectations API, which allows you to create expectations on methods and properties.

Here’s that before and after code based on the screenshot above:

1// Before
2expect($user->first_name)->toEqual('Nuno');
3expect($user->last_name)->toEqual('Maduro');
4expect($user->withTitle('Mr'))->toEqual('Mr Nuno Maduro');
5
6// After
7expect($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

Freek Van der Herten contributed a ray() function to PEST PHP expectations, which can help you easily debug expectations via the Ray app (paid) by changing calls to ray():

Here’s a snippet of what using the ray() function looks like:

1expect($users)->toHaveCount(2)->each->ray();

Check out the ray() expectations documentation to learn more.

Pest Snippets for VS Code

dansysanalyst (Dan Ang.) released a Pest snippets extension extension for writing Pest PHP tests in Visual Studio Code:

For a complete list of snippets, check out the Pest Snippets - Visual Studio Marketplace page.

More Resources

If you’d like to get started with Pest PHP, be sure to check out the following resources:

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.