fix: don't allow invalid class names

This commit is contained in:
nuno maduro
2026-08-04 20:46:21 +01:00
parent 872f0a50c2
commit 92c7677c6e
23 changed files with 147 additions and 19 deletions
+2 -2
View File
@@ -21,7 +21,7 @@ test('reports missing datasets as errors for a single file run', function () use
$result = $run('tests/Fixtures/Suites/IssueOnly.php');
expect($result['output'])
->toContain("A dataset with the name `missing` does not exist. You can create it using `dataset('missing', ['a', 'b']);`.")
->toContain("A dataset with the name [missing] does not exist. You can create it using `dataset('missing', ['a', 'b']);`.")
->toContain('FAILED')
->toContain('Tests: 1 failed')
->and($result['code'])->not->toBe(0);
@@ -31,7 +31,7 @@ test('reports missing datasets as errors alongside passing tests', function () u
$result = $run('tests/Fixtures/Suites/IssueWithPassing.php');
expect($result['output'])
->toContain("A dataset with the name `missing` does not exist. You can create it using `dataset('missing', ['a', 'b']);`.")
->toContain("A dataset with the name [missing] does not exist. You can create it using `dataset('missing', ['a', 'b']);`.")
->toContain('1 passed')
->toContain('1 failed')
->and($result['code'])->not->toBe(0);
+2 -2
View File
@@ -10,12 +10,12 @@ beforeEach(function (): void {
});
it('throws exception if dataset does not exist', function (): void {
expect(fn () => DatasetsRepository::resolve(['first'], __FILE__))->toThrow(DatasetDoesNotExist::class, "A dataset with the name `first` does not exist. You can create it using `dataset('first', ['a', 'b']);`.");
expect(fn () => DatasetsRepository::resolve(['first'], __FILE__))->toThrow(DatasetDoesNotExist::class, "A dataset with the name [first] does not exist. You can create it using `dataset('first', ['a', 'b']);`.");
});
it('throws exception if dataset already exist', function (): void {
DatasetsRepository::set('second', [[]], __DIR__);
expect(fn () => DatasetsRepository::set('second', [[]], __DIR__))->toThrow(DatasetAlreadyExists::class, 'A dataset with the name `second` already exists in scope ['.__DIR__.'].');
expect(fn () => DatasetsRepository::set('second', [[]], __DIR__))->toThrow(DatasetAlreadyExists::class, 'A dataset with the name [second] already exists in scope ['.__DIR__.'].');
});
it('sets closures', function (): void {
@@ -0,0 +1,5 @@
<?php
// The folder name creates the namespace segment `2fa`, which starts with a number.
it('never runs')->assertTrue(true);
@@ -0,0 +1,5 @@
<?php
// The file name creates the class `list`, which is a PHP keyword.
it('never runs')->assertTrue(true);
@@ -0,0 +1,5 @@
<?php
// The file name creates the class `int`, which is a name PHP reserves.
it('never runs')->assertTrue(true);
@@ -0,0 +1,5 @@
<?php
// The file name creates the class `2fa`, which starts with a number.
it('never runs')->assertTrue(true);
+1 -1
View File
@@ -15,7 +15,7 @@ it('does not allow to add the same test description twice', function (): void {
$testSuite->tests->set($method);
})->throws(
TestAlreadyExist::class,
sprintf('A test with the description `%s` already exists in the filename `%s`.', 'bar', 'foo'),
sprintf('A test with the description [%s] already exists in the filename [%s].', 'bar', 'foo'),
);
it('does not allow static closures', function (): void {
+1 -1
View File
@@ -43,7 +43,7 @@ test('a parallel test can extend another test with same name', function () use (
test('parallel reports invalid datasets as failures', function () use ($run): void {
expect($run('tests/Fixtures/Suites/ParallelInvalidDataset'))
->toContain("A dataset with the name `missing.dataset` does not exist. You can create it using `dataset('missing.dataset', ['a', 'b']);`.")
->toContain("A dataset with the name [missing.dataset] does not exist. You can create it using `dataset('missing.dataset', ['a', 'b']);`.")
->toContain('Tests: 1 failed, 1 passed (1 assertions)')
->toContain('Parallel: 3 processes');
})->skipOnWindows();