[Bug]: Test file names with php reserved keywords crash the test
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 11.7k
- Forks
- 538
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 8
Description
What Happened
I created a list.test.php file (in a Livewire MFC component) and ran Pest, which crashes with syntax error, unexpected token "list", expecting id entifier.
Full output
In TestCaseFactory.php line 180:Unable to create test case for test file at /var/ww
w/html/app/ModuleName/Pages/list/list_.test.p
hp.
namespace P\App\ModuleName\Pages\list;use Pest\Repositories\DatasetsRepository as __PestD
atasets;
use Pest\TestSuite as __PestTestSuite;#[\PHPUnit\Framework\Attributes\TestDox('/var/www/html/app/ModuleName/Pages/list/list_.test.
php')]
#[\AllowDynamicProperties]
final class list extends \Tests\TestCase implements
\Pest\Contracts\HasPrintableTestCaseName {
use \Pest\Concerns\Testable, \Pest\Concerns\Exp
ectable, \Pest\Arch\Concerns\Architectable, \Illumi
nate\Foundation\Testing\RefreshDatabase;public static $__filename = '/var/www/html/app/ModuleName/Pages/list/list_.test.php';
#[\PHPUnit\Framework\Attributes\Test] #[\PHPUnit\Framework\Attributes\TestDox('draftsare visible in the list by default')]
#[\PHPUnit\Framework\Attributes\Group('__pest_o
nly')]
#[\PHPUnit\Framework\Attributes\Group('supplier
-invoice')]
public function __pest_evaluable_drafts_are_vis
ible_in_the_list_by_default(...$arguments)
{
return $this->__runTest(
$this->__test,
...$arguments,
);
}
#[\PHPUnit\Framework\Attributes\Test]
#[\PHPUnit\Framework\Attributes\TestDox('state
filter narrows results to draft only')]
#[\PHPUnit\Framework\Attributes\Group('__pest_o
nly')]
#[\PHPUnit\Framework\Attributes\Group('supplier
-invoice')]
public function __pest_evaluable_state_filter_n
arrows_results_to_draft_only(...$arguments)
{
return $this->__runTest(
$this->__test,
...$arguments,
);
}
#[\PHPUnit\Framework\Attributes\Test]
#[\PHPUnit\Framework\Attributes\TestDox('state
filter narrows results to done only')]
#[\PHPUnit\Framework\Attributes\Group('__pest_o
nly')]
#[\PHPUnit\Framework\Attributes\Group('supplier
-invoice')]
public function __pest_evaluable_state_filter_n
arrows_results_to_done_only(...$arguments)
{
return $this->__runTest(
$this->__test,
...$arguments,
);
}}
In TestCaseFactory.php(178) : eval()'d code line 8:
syntax error, unexpected token "list", expecting id
entifier
It seems to be because list is a php reserved keyword. If I rename the test file to something else (list-dummy-postfix.test.php) it all runs fine.
Since I don't write anything that is misusing reserved keywords (I don't create the class list) I don't expect such error. It would be nice if Pest can avoid creating such. Also extra annoying for even when you understand the error, a common rename to _list.test.php / list_.test.php / list-.test.php doesn't work.
How to Reproduce
- Create a
list.test.phpwith a test that succeeds - Run the tests
Sample Repository
No response
Pest Version
4.7.5
PHP Version
8.5.7
Operation System
Linux
Notes
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in TestCaseFactory.php around line 180 and reproduce the failure with a test file named list.test.php. Compare the generated test case shown in the error with the successful list-dummy-postfix.test.php case, then add coverage for PHP reserved-keyword filenames and verify the test suite no longer crashes.
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
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 73/100