Home > Backend Development > PHP Tutorial > Official open source elegant testing framework PestPHP

Official open source elegant testing framework PestPHP

Guanhui
Release: 2023-04-08 17:16:02
forward
2431 people have browsed it

Official open source elegant testing framework PestPHP

Console legend Nuno Maduro has open sourced Pest, an elegant PHP testing framework that focuses on simplicity.

Here is a simple example, If you have used other testing tools, such as Mocha or Jest, you will feel familiar with it:

test('asserts true is true', function () {
    assertTrue(true);
});
// or
it('asserts true is true', function () {
    assertTrue(true);
});
Copy after login

Under the hood, Pest tests are bound to a test case class (PHPUnit's TestCase by default) , this means that your closure function will run in the environment where the test case is configured:

it('has home', function () {
    $this->assertTrue(true);
    // \PHPUnit\Framework\TestCase
    echo get_class($this); 
});
Copy after login

Be sure to check out the documentation on how to customize the underlying test case through the uses() function provided by Pest.

Before you start, please make sure you have read the Laravel Guide to understand how to use Pest to create tests in Laravel. The following is a test for Laravel:

use Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseMigrations;
uses(TestCase::class, DatabaseMigrations::class);
it('has home page')
    ->get('/')
    ->see('Laravel.io')
    ->see('The Laravel Community Portal');
Copy after login

Recommended tutorial: "PHP Tutorial

The above is the detailed content of Official open source elegant testing framework PestPHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template