New updates for PEST PHP – higher-order expectations, Ray debugging integration,

Are you a fan of Pest PHP? I am excited to announce the new stunning updates coming to Pest PHP. The Savvy behind this great testing framework bringing simplicity to Unit testing 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

The following contributors Luke Downing and Sam Rowden has brought about higher order expectations API, which allows you to create expectations on methods and properties.

Today, we are proud to introduce “Higher Order Expectations” to @pestphp. 🪄

This feature allows you to create expectations on methods or properties of the original expectation value. 🤯

📚 https://t.co/90q9KZGZVMpic.twitter.com/fzpjr1lxy0— Nuno Maduro (@enunomaduro) June 11, 2021

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

// Before
expect($user->first_name)->toEqual('Nuno');
expect($user->last_name)->toEqual('Maduro');
expect($user->withTitle('Mr'))->toEqual('Mr Nuno Maduro');

// After
expect($user)
    ->first_name->toEqual('Nuno')
    ->last_name->toEqual('Maduro')
    ->withTitle('Mr')->toEqual('Mr Nuno Maduro');

This feature also works with array data as well:

expect(['name' => 'Nuno', 'companies' => ['Pest', 'Laravel']])
    ->name->toEqual('Nuno')
    ->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():

New in @pestphp: You can now call `ray()` on any expectation to debug the current expectation value with https://t.co/VvOabtnkrQ. 💅🏻 pic.twitter.com/9m5YqVFb5m— Nuno Maduro (@enunomaduro) June 10, 2021

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

expect($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:

✨ Pest snippets for VS Code ✨

🔥 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— Dan (@DanSysAnalyst) June 14, 2021

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

Reference:

Laravel News – https://laravel-news.com/

Leave a Comment

%d bloggers like this: