#1901·pest

[Bug]: bin/pest --drift does not take into account strict_types=1 during migration

Author: NiklasBrCreated Sep 9, 2026Updated Sep 9, 2026
Labelsbug

What Happened

After installing Pest and Drift I ran the command ./vendor/bin/pest --drift and it migrated a lot of our PhpUnit files. However, two things were incomplete and caused tests to not run after the migration:

  • Error 'strict_types' declaration must be the very first statement in the script
  • Error Cannot use "self" when no class scope is active

How to Reproduce

This shortened sample code from one of our PhpUnit tests will trigger both above issues:

php
<?php

declare(strict_types=1);

namespace App\Tests\Functional\Command;

use Pimcore\Test\KernelTestCase;

class DocumentCronCommandTest extends KernelTestCase
{
    public function testExecute(): void
    {
        $kernel = self::bootKernel();
        // Rest of test removed for brevity
    }
}

Sample Repository

No response

Pest Version

4.7.8

PHP Version

8.4.20

Operation System

Linux, macOS

Notes

No response