diff --git a/tests/muqsit/preprocessor/PreProcessorTest.php b/tests/muqsit/preprocessor/PreProcessorTest.php index 8e981f6..6441b2a 100644 --- a/tests/muqsit/preprocessor/PreProcessorTest.php +++ b/tests/muqsit/preprocessor/PreProcessorTest.php @@ -5,6 +5,7 @@ namespace muqsit\preprocessor; use PHPUnit\Framework\TestCase; +use pocketmine\utils\Utils; use Symfony\Component\Filesystem\Path; use function explode; use function file_get_contents; @@ -36,14 +37,18 @@ private function assertDiff(PreProcessor $processor, array $differences) : void{ } public function testCommentOutMethodCalls() : void{ - $processor = $this->buildPreProcessorForSample("logger-debug-method-call.php"); - $processor->commentOut(\Logger::class, "debug"); + $processor = $this->buildPreProcessorForSample("comment-out-method-call.php"); + $processor->commentOut(\Logger::class, "debug"); // non-static method + $processor->commentOut(Utils::class, "validateCallableSignature"); // static method $this->assertDiff($processor, [ - [15, "\t\t/* \$this->getLogger()->debug(\"Plugin enabled timestamp: \" . \\time()) */;"], - [18, "\t\t/* \$logger->debug(\"Logging from {\$this->getName()}\") */;"], - [23, "\t\t/* \$child->debug(\"Hello world\") */;"], - [25, "\t\t/* \$this->l1->debug(\"test phpdoc typed property\") */;"], - [26, "\t\t/* \$this->l2->debug(\"test native typed property\") */;"] + [24, "\t\t/* \$this->getLogger()->debug(\"Plugin enabled timestamp: \" . time()) */;"], + [27, "\t\t/* \$logger->debug(\"Logging from {\$this->getName()}\") */;"], + [32, "\t\t/* \$child->debug(\"Hello world\") */;"], + [34, "\t\t/* \$this->l1->debug(\"test phpdoc typed property\") */;"], + [35, "\t\t/* \$this->l2->debug(\"test native typed property\") */;"], + [38, "\t\t\$l->info(\"x\"); /* \$l->debug(\"y\") */; \$l->notice(\"z\");"], + [45, "\t\t/* \\pocketmine\\utils\\Utils::validateCallableSignature(static fn(\\pocketmine\\player\\Player \$player): bool => true, \$listener) */;"], + [54, "\t\t/* \$utils::validateCallableSignature(static fn(\\pocketmine\\entity\\Entity \$entity): bool => true, \$listener) */;"] ]); } } \ No newline at end of file diff --git a/tests/muqsit/preprocessor/samples/comment-out-method-call.php b/tests/muqsit/preprocessor/samples/comment-out-method-call.php new file mode 100644 index 0000000..dd43ad9 --- /dev/null +++ b/tests/muqsit/preprocessor/samples/comment-out-method-call.php @@ -0,0 +1,57 @@ +getLogger()->debug("Plugin enabled timestamp: " . time()); + + $logger = $this->getServer()->getLogger(); + $logger->debug("Logging from {$this->getName()}"); + + $logger->notice("This isn't a debug message"); + + $child = new PrefixedLogger($this->getLogger(), "Prefix"); + $child->debug("Hello world"); + + $this->l1->debug("test phpdoc typed property"); + $this->l2->debug("test native typed property"); + + $l = $this->l1; + $l->info("x"); $l->debug("y"); $l->notice("z"); + } + + /** + * @param Closure(Player) : bool $listener + */ + public function registerPlayerListener(Closure $listener) : void{ + Utils::validateCallableSignature(static fn(Player $player) : bool => true, $listener); + $listener($this->getServer()->getPlayerByUUID(Uuid::fromString(Uuid::NIL))); + } + + /** + * @param Closure(Entity) : bool $listener + */ + public function registerEntityListener(Closure $listener) : void{ + $utils = Utils::class; + $utils::validateCallableSignature(static fn(Entity $entity) : bool => true, $listener); + $listener($this->getServer()->getWorldManager()->findEntity(0)); + } +} \ No newline at end of file diff --git a/tests/muqsit/preprocessor/samples/logger-debug-method-call.php b/tests/muqsit/preprocessor/samples/logger-debug-method-call.php deleted file mode 100644 index b43dc88..0000000 --- a/tests/muqsit/preprocessor/samples/logger-debug-method-call.php +++ /dev/null @@ -1,28 +0,0 @@ -getLogger()->debug("Plugin enabled timestamp: " . time()); - - $logger = $this->getServer()->getLogger(); - $logger->debug("Logging from {$this->getName()}"); - - $logger->notice("This isn't a debug message"); - - $child = new PrefixedLogger($this->getLogger(), "Prefix"); - $child->debug("Hello world"); - - $this->l1->debug("test phpdoc typed property"); - $this->l2->debug("test native typed property"); - } -} \ No newline at end of file