refaltor/pest-pmmp-tests

Little library for create unit test in PocketMine with Await Generator.

2.1.0 2025-04-12 12:19 UTC

This package is auto-updated.

Last update: 2025-04-12 12:20:03 UTC


README

Logo

Pest PMMP Tests

License PHP PocketMine-MP Await Generator

Simple & elegant unit testing for PocketMine-MP inspired by Pest and powered Await Generator.

πŸ“¦ Installation

composer require refaltor/pest-pmmp-tests

πŸ“¦ Simple Usage

In your PocketMine plugin, you can easily integrate this unit testing library and run it either through a command or directly in onEnable β€” it’s totally up to you.

 public function onEnable(): void
 {
     # tester load
     PocketMineTester::initPlugin($this);
     PocketMineTester::launchTest(__DIR__ . '/tests', "core\\tests\\");
 }

Project Structure Example :

my-plugin/
β”œβ”€β”€ src/
β”‚   └── core/
β”‚       └── Main.php
β”œβ”€β”€ tests/
β”‚   └── MyFirstTest.php
β”œβ”€β”€ plugin.yml
β”œβ”€β”€ composer.json
└── README.md

πŸ“¦ Test Example

Note: For your tests to run, your .php file must end with ...Test.php, and all the functions within that file must end with ...test().

<?php

namespace core\tests;

use core\Main;
use Generator;
use Refaltor\PestPmmpTests\tests\PmmpTest;
use SOFe\AwaitGenerator\Await;

class TestTest extends PmmpTest
{
    public function player_check_name_test(): Generator
    {
        $player = $this->getFakePlayer();
        
        $this->assertString("FAKEPLAYER", $player->getName());

        return yield Await::ALL;
    }

    public function player_check_name_error_test(): Generator
    {
        $player = $this->getFakePlayer();

        $this->assertString("FAKEPLAYERRRRRR", $player->getName());

        return yield Await::ALL;
    }

    public function onBeforeAllTest(): void
    {
        Main::getInstance()->getLogger()->info("Units test is starting...");
    }

    public function onAfterAllTest(): void
    {
        Main::getInstance()->getLogger()->info("Units test is finish.");
    }
}

Result :

Result