Add static closure check

This commit is contained in:
Peter Fox
2024-03-17 12:04:38 +00:00
committed by GitHub
parent d519e40b95
commit 6094682158

View File

@ -90,6 +90,11 @@ final class TestCaseMethodFactory
throw ShouldNotHappen::fromMessage('Description can not be empty.'); throw ShouldNotHappen::fromMessage('Description can not be empty.');
} }
if (($reflection = new ReflectionClosure($this->closure))->isStatic()) {
$fileAndLine = $reflection->getFileName() . ':' . $reflection->getStartLine();
throw ShouldNotHappen::fromMessage("The test `$this->description` closure must not be static in $fileAndLine.");
}
$closure = $this->closure; $closure = $this->closure;
$testCase = TestSuite::getInstance()->tests->get($this->filename); $testCase = TestSuite::getInstance()->tests->get($this->filename);