Handles tests where a static closure is provided

This commit is contained in:
Peter Fox
2024-03-17 16:48:43 +00:00
parent 6094682158
commit a4f8ae1a12
6 changed files with 44 additions and 5 deletions

View File

@ -22,6 +22,7 @@ arch('dependencies')
'Whoops',
'Symfony\Component\Console',
'Symfony\Component\Process',
'Laravel\SerializableClosure\Support\ReflectionClosure',
])->ignoring(['Composer', 'PHPUnit', 'SebastianBergmann']);
arch('contracts')

View File

@ -2,6 +2,7 @@
use Pest\Exceptions\DatasetMissing;
use Pest\Exceptions\TestAlreadyExist;
use Pest\Exceptions\TestClosureMustNotBeStatic;
use Pest\Factories\TestCaseMethodFactory;
use Pest\TestSuite;
@ -16,6 +17,22 @@ it('does not allow to add the same test description twice', function () {
sprintf('A test with the description `%s` already exists in the filename `%s`.', 'bar', 'foo'),
);
it('does not allow static closures', function () {
$testSuite = new TestSuite(getcwd(), 'tests');
$method = new TestCaseMethodFactory('foo', 'bar', static function () {
});
$testSuite->tests->set($method);
})->throws(
TestClosureMustNotBeStatic::class,
sprintf(
'The test `%s` closure must not be static in %s.',
'bar',
'foo',
)
);
it('alerts users about tests with arguments but no input', function () {
$testSuite = new TestSuite(getcwd(), 'tests');