Repository navigation
v0.6.0 Getting Started
⚠️ Documentation of Golem v0.6.0. The latest release is v0.7.0: this page in v0.7.0 · what changed · other versions
This guide takes a plugin with no tests to a green test run in about five minutes.
- Linux or macOS (on Windows, run Golem from WSL)
- PHP 8.1 or newer, to run the
golemcommand - A plugin laid out the usual way:
plugin.ymlandsrc/in the same folder
You do not need to install PocketMine-MP or its PHP build: Golem downloads both from the official
pmmp releases the first time it runs and caches them in ~/.cache/golem (~/Library/Caches/golem
on macOS). Set GOLEM_CACHE_DIR to put them somewhere else.
From your plugin folder:
composer require --dev achedon12/golemNo composer.json yet? composer init creates one in a few questions. Composer is only used to
give your IDE autocompletion for Golem's classes: the CLI itself has no dependencies.
vendor/bin/golem initThis creates two files:
-
tests/ExampleTest.php, a test that checks your plugin enables and that a player can join -
.github/workflows/golem.yml, which runs your tests on every push (skip it with--no-workflow)
vendor/bin/golemThe first run downloads PocketMine and its PHP build (a few dozen MB, once). After that, a run takes a couple of seconds to boot the server plus well under a second per test.
Prefer clicking? vendor/bin/golem ui opens a dashboard in your browser to run the
tests, follow them live, and build new ones without writing PHP.
Say your plugin gives new players a compass when they join. Replace the example with:
<?php
declare(strict_types=1);
namespace MyName\MyPlugin\Tests;
use Generator;
use Golem\TestCase;
use pocketmine\item\VanillaItems;
final class JoinTest extends TestCase
{
public function testNewPlayersGetACompass(): Generator
{
$steve = yield $this->golem('Steve');
$this->assertHasItem($steve, VanillaItems::COMPASS());
}
}yield $this->golem('Steve') spawns a simulated player and waits until it is fully in the world,
after every join event has fired. From there, read Writing tests and
Golems.
- Keep
vendor/bin/golem --watchopen in a terminal while you code: the tests re-run on every save, each time on a fresh server. Ctrl+C stops it. - Run a single test with
vendor/bin/golem --filter=JoinTest(or any part ofClass::method). - Add
--verboseto see the server console while the tests run. - Add
"scripts": { "test": "golem" }to yourcomposer.jsonand runcomposer test.