pestphp / pestphp/pest

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

Open
#1,901 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
11.7k
Forks
538
Avg merge
4d 11h
Merged PRs (30d)
8

Description

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

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the bin/pest --drift migration entry point and reproduce the issue using the shortened PHPUnit sample from the report. Trace the generated migrated file and add or update coverage so declare(strict_types=1) remains first and self::bootKernel() remains inside its class scope without either reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.