Migrating from PHPUnit

Pest is built on top of PHPUnit, so migrating from PHPUnit to Pest is a simple process that can be completed in just a few steps. Once you have Pest installed, you should require the pestphp/pest-plugin-drift package as a "dev" dependency in your project.

1composer require pestphp/pest-plugin-drift --dev

Drift is a simple yet powerful plugin that will automatically convert your PHPUnit tests to Pest, simply by running the --drift option.

1./vendor/bin/pest --drift

So, typically, a PHPUnit test looks like this:

3namespace Tests\Unit;
5use PHPUnit\Framework\TestCase;
7class ExampleTest extends TestCase
9 public function test_that_true_is_true(): void
10 {
11 $this->assertTrue(true);
12 }

Should look like this after running --drift:

1test('true is true', function () {
2 expect(true)->toBeTrue();

The output will contain a summary of the conversion process, as well as a list of the files that were converted.

While most of your tests should be converted automatically, and you should be able to run them without any issues, there are some cases where you may need to manually convert some of your tests.

Of course, this particular chapter is only for those who are migrating from PHPUnit. Next, let's learn how you can contribute to the growth of Pest: Community Guide