From 6094682158125bb8be436693ed3a1232bbbe08c0 Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Sun, 17 Mar 2024 12:04:38 +0000 Subject: [PATCH] Add static closure check --- src/Factories/TestCaseMethodFactory.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Factories/TestCaseMethodFactory.php b/src/Factories/TestCaseMethodFactory.php index 341ec902..4cbc8530 100644 --- a/src/Factories/TestCaseMethodFactory.php +++ b/src/Factories/TestCaseMethodFactory.php @@ -90,6 +90,11 @@ final class TestCaseMethodFactory 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; $testCase = TestSuite::getInstance()->tests->get($this->filename);