DEV Community

AriaieBOY
AriaieBOY

Posted on • Originally published at ariaieboy.ir

1

Enjoyable PHP Testing with PestPHP

Writing tests is time-consuming and tedious. But if you want close your eyes without fear at night, having good tests in your applications is essential.

With Pest, testing is much more enjoyable. It has a simpler syntax compared to PHPUnit. The test reports have more useful information in a beautiful style.

Pest is a progressive testing framework that uses PHPUnit at its core. That means you can both PHPUnit test classes and Pest test files in the same test suite.

You can also convert your PHPUnit test classes to Pest test files using these tools:
Pest Convertor by Laravel-Shift (Each Shift Costs 9$)
Pest Convertor by mandisma (Open-Source and free!)

Laravel Shift is a well-known Service, especially among Laravel Users. It can convert your PHPUnit tests for 9$.

The open-source option is not that popular but I've used it on a medium-sized project with hundreds of tests, and it's worked very well for me but it may need more work in big projects with complicated test suites.

At the end let's compare a test written in both PHPUnit and Pest:

PHPUnit:

<?php

    namespace Tests\Feature;

    use Tests\TestCase;

    class HomepageTest extends TestCase
    {
     /** @test */
     public function it_renders_the_homepage()
     {
     $response = $this->get('/');

     $response->assertStatus(200);
     }

    }
Enter fullscreen mode Exit fullscreen mode

Pest:

<?php

    it('renders the homepage', function () {
     $response = $this->get('/');

     $response->assertStatus(200);
    });
Enter fullscreen mode Exit fullscreen mode

Beautiful version of this test using Pest:

<?php

    it('renders the homepage')->get('/')->assertStatus(200);
Enter fullscreen mode Exit fullscreen mode

Isn't the last example beautiful? We only wrote 1 line of code instead of 18 lines.

And that's why I love Pest that much. it's simple, minimal, and enjoyable to use.

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay