Search by

presentkim / pmmp-test-utils

PresentKim

PHPUnit helpers for axolotl-pm/PocketMine-MP plugins and libraries: native extension polyfills, a fake player, packet and class load test cases

Package info

github.com/presentkim-pm/pmmp-test-utils

pkg:composer/presentkim/pmmp-test-utils

Statistics

Installs: 185

Dependents: 5

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-12-03 02:53 UTC

This package is auto-updated.

Last update: 2026-12-03 09:51:25 UTC


README

Packagist CI Stars License


Logo

pmmp-test-utils

PHPUnit helpers for axolotl-pm/PocketMine-MP plugins and libraries

Packagist ยท Changelog ยท Report a bug ยท Request a feature

final class ClassLoadTest extends ClassLoadTestCase{}

final class GreetTest extends PacketTestCase{
    public function testGreets() : void{
        $player = FakePlayer::create("Steve", session: $this->createSession());
        Greeter::greet($player);
        self::assertSame(["Hello, Steve!"], $player->messages);
        self::assertRoundTrip($this->sentOne(PlaySoundPacket::class));
    }
}

๐ŸŒŸ Why pmmp-test-utils?

PocketMine-MP needs native extensions (ext-encoding, ext-morton, ext-pmmpthread) that a plain PHP on CI does not have, and a Player cannot be built without a server. Every plugin used to carry its own copy of the polyfills and fake objects; this package keeps one copy.

  • Bootstrap : links the server's vendor/, loads the autoloader and the polyfills of the missing extensions
  • Polyfills : test-only stand-ins for ext-encoding (enough to encode and decode packets), ext-morton and the ext-pmmpthread base classes
  • Fake objects : FakePlayer without a server or a world, ServerInstance for code that touches Server::getInstance() in passing
  • Ready-made tests : ClassLoadTestCase (every class links), PluginManifestTestCase (plugin.yml matches the code), PacketTestCase (records sent packets, checks round trips)

The polyfills are only for tests: never load them on a server.

๐Ÿ“ฆ Installation

composer require --dev presentkim/pmmp-test-utils

This also installs axolotl-pm/pocketmine-mp and phpunit/phpunit as dev dependencies.

Requirement Version
Server axolotl-pm/PocketMine-MP (fork of PocketMine-MP 5)
PHP 8.4 or newer
PHPUnit 12

๐Ÿš€ Quick start

  1. Point PHPUnit at the bootstrap in phpunit.xml.dist:
<phpunit bootstrap="vendor/presentkim/pmmp-test-utils/bootstrap.php">

When you need more setup, keep your own tests/bootstrap.php and require the package's bootstrap first:

require dirname(__DIR__) . "/vendor/presentkim/pmmp-test-utils/bootstrap.php";
  1. Delete the copies this replaces: tests/polyfill/encoding.php, morton.php, pmmpthread.php / thread.php, and the server vendor/ link code of tests/bootstrap.php.

  2. Use the test cases and fake objects:

use kim\present\utils\pmmptest\ClassLoadTestCase;
use kim\present\utils\pmmptest\PluginManifestTestCase;

final class ClassLoadTest extends ClassLoadTestCase{}

final class PluginManifestTest extends PluginManifestTestCase{
    public function testNbtPermissionIsDeclared() : void{
        // add plugin specific checks here
    }
}

๐Ÿ“– API reference

All classes are in kim\present\utils\pmmptest.

Member Description
bootstrap.php PHPUnit bootstrap: server vendor/ link, autoloader, polyfills
FakePlayer::create(name = "Steve", ?Location, GameMode, ?array $permissions = null, ?NetworkSession, bool $connected = true, string $locale = "en_US") A player without a server; null permissions grant everything
FakePlayer::$messages Messages sent with sendMessage() (a Translatable as its text key)
ServerInstance::install() : Server Makes Server::getInstance() return an uninitialized server
PacketTestCase::createSession() : NetworkSession A session stub that records sent packets in $this->sent
PacketTestCase::sentOne(string $class) Asserts one packet of the class was sent and returns it
PacketTestCase::assertRoundTrip(DataPacket $packet) Encode, decode, encode again: same bytes, nothing unread
ClassLoadTestCase Loads every class of the project's PSR-4 autoload
PluginManifestTestCase name/main/version/api present, main class is a plugin, src-namespace-prefix matches composer.json, api is EXPECTED_API ([5.51.0])
ProjectRoot::path() / composer() / psr4() / pluginManifest() Paths and settings of the project under test

๐Ÿงช Development

composer install --ignore-platform-req='ext-*'
composer test
composer analyse # PHPStan

๐Ÿ“„ License

Distributed under the MIT License. See LICENSE for more information.