mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-05 19:37:17 +00:00
Fixup TesterPlugin to PHPStan standards
This commit is contained in:
parent
09eb904f6b
commit
b7578fef9c
@ -20,6 +20,8 @@ parameters:
|
||||
checkExplicitMixed: true
|
||||
bootstrapFiles:
|
||||
- tests/phpstan/bootstrap.php
|
||||
scanDirectories:
|
||||
- tests/plugins/TesterPlugin
|
||||
scanFiles:
|
||||
- src/pocketmine/PocketMine.php
|
||||
- build/make-release.php
|
||||
@ -29,6 +31,7 @@ parameters:
|
||||
- build/make-release.php
|
||||
- build/server-phar.php
|
||||
- tests/phpunit
|
||||
- tests/plugins/TesterPlugin
|
||||
dynamicConstantNames:
|
||||
- pocketmine\IS_DEVELOPMENT_BUILD
|
||||
- pocketmine\DEBUG
|
||||
|
@ -1715,3 +1715,8 @@ parameters:
|
||||
count: 1
|
||||
path: ../../phpunit/network/mcpe/StupidJsonDecodeTest.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method cancel\\(\\) on pocketmine\\\\scheduler\\\\TaskHandler\\|null\\.$#"
|
||||
count: 1
|
||||
path: ../../plugins/TesterPlugin/src/pmmp/TesterPlugin/CheckTestCompletionTask.php
|
||||
|
||||
|
@ -38,7 +38,7 @@ class Main extends PluginBase implements Listener{
|
||||
/** @var int */
|
||||
protected $currentTestNumber = 0;
|
||||
|
||||
public function onEnable(){
|
||||
public function onEnable() : void{
|
||||
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||
$this->getScheduler()->scheduleRepeatingTask(new CheckTestCompletionTask($this), 10);
|
||||
|
||||
@ -49,7 +49,7 @@ class Main extends PluginBase implements Listener{
|
||||
];
|
||||
}
|
||||
|
||||
public function onServerCommand(CommandEvent $event){
|
||||
public function onServerCommand(CommandEvent $event) : void{
|
||||
//The CI will send this command as a failsafe to prevent the build from hanging if the tester plugin failed to
|
||||
//run. However, if the plugin loaded successfully we don't want to allow this to stop the server as there may
|
||||
//be asynchronous tests running. Instead we cancel this and stop the server of our own accord once all tests
|
||||
@ -59,10 +59,7 @@ class Main extends PluginBase implements Listener{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Test|null
|
||||
*/
|
||||
public function getCurrentTest(){
|
||||
public function getCurrentTest() : ?Test{
|
||||
return $this->currentTest;
|
||||
}
|
||||
|
||||
@ -77,7 +74,7 @@ class Main extends PluginBase implements Listener{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onTestCompleted(Test $test){
|
||||
public function onTestCompleted(Test $test) : void{
|
||||
$message = "Finished test #" . $this->currentTestNumber . " (" . $test->getName() . "): ";
|
||||
switch($test->getResult()){
|
||||
case Test::RESULT_OK:
|
||||
@ -103,7 +100,7 @@ class Main extends PluginBase implements Listener{
|
||||
$this->currentTest = null;
|
||||
}
|
||||
|
||||
public function onAllTestsCompleted(){
|
||||
public function onAllTestsCompleted() : void{
|
||||
$this->getLogger()->notice("All tests finished, stopping the server");
|
||||
$this->getServer()->shutdown();
|
||||
}
|
||||
|
@ -29,9 +29,13 @@ abstract class Test{
|
||||
const RESULT_FAILED = 1;
|
||||
const RESULT_ERROR = 2;
|
||||
|
||||
/** @var Main */
|
||||
private $plugin;
|
||||
/** @var int */
|
||||
private $result = Test::RESULT_WAITING;
|
||||
/** @var int */
|
||||
private $startTime;
|
||||
/** @var int */
|
||||
private $timeout = 60; //seconds
|
||||
|
||||
public function __construct(Main $plugin){
|
||||
@ -42,7 +46,7 @@ abstract class Test{
|
||||
return $this->plugin;
|
||||
}
|
||||
|
||||
final public function start(){
|
||||
final public function start() : void{
|
||||
$this->startTime = time();
|
||||
try{
|
||||
$this->run();
|
||||
@ -55,11 +59,11 @@ abstract class Test{
|
||||
}
|
||||
}
|
||||
|
||||
public function tick(){
|
||||
public function tick() : void{
|
||||
|
||||
}
|
||||
|
||||
abstract public function run();
|
||||
abstract public function run() : void;
|
||||
|
||||
public function isFinished() : bool{
|
||||
return $this->result !== Test::RESULT_WAITING;
|
||||
@ -69,7 +73,7 @@ abstract class Test{
|
||||
return !$this->isFinished() and time() - $this->timeout > $this->startTime;
|
||||
}
|
||||
|
||||
protected function setTimeout(int $timeout){
|
||||
protected function setTimeout(int $timeout) : void{
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
|
||||
@ -77,7 +81,7 @@ abstract class Test{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
public function setResult(int $result){
|
||||
public function setResult(int $result) : void{
|
||||
$this->result = $result;
|
||||
}
|
||||
|
||||
|
@ -26,11 +26,13 @@ namespace pmmp\TesterPlugin\tests;
|
||||
use pmmp\TesterPlugin\Test;
|
||||
use pocketmine\scheduler\AsyncTask;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\AssumptionFailedError;
|
||||
use pocketmine\utils\MainLogger;
|
||||
use function ob_get_contents;
|
||||
|
||||
class AsyncTaskMainLoggerTest extends Test{
|
||||
|
||||
public function run(){
|
||||
public function run() : void{
|
||||
$this->getPlugin()->getServer()->getAsyncPool()->submitTask(new class($this) extends AsyncTask{
|
||||
|
||||
/** @var bool */
|
||||
@ -43,7 +45,9 @@ class AsyncTaskMainLoggerTest extends Test{
|
||||
public function onRun(){
|
||||
ob_start();
|
||||
MainLogger::getLogger()->info("Testing");
|
||||
if(strpos(ob_get_contents(), "Testing") !== false){
|
||||
$contents = ob_get_contents();
|
||||
if($contents === false) throw new AssumptionFailedError("ob_get_contents() should not return false here");
|
||||
if(strpos($contents, "Testing") !== false){
|
||||
$this->success = true;
|
||||
}
|
||||
ob_end_flush();
|
||||
|
@ -28,11 +28,11 @@ use pocketmine\scheduler\AsyncTask;
|
||||
|
||||
class AsyncTaskMemoryLeakTest extends Test{
|
||||
|
||||
public function run(){
|
||||
public function run() : void{
|
||||
$this->getPlugin()->getServer()->getAsyncPool()->submitTask(new TestAsyncTask());
|
||||
}
|
||||
|
||||
public function tick(){
|
||||
public function tick() : void{
|
||||
if(TestAsyncTask::$destroyed === true){
|
||||
$this->setResult(Test::RESULT_OK);
|
||||
}
|
||||
@ -48,6 +48,7 @@ class AsyncTaskMemoryLeakTest extends Test{
|
||||
}
|
||||
|
||||
class TestAsyncTask extends AsyncTask{
|
||||
/** @var bool */
|
||||
public static $destroyed = false;
|
||||
|
||||
public function onRun(){
|
||||
|
@ -41,6 +41,7 @@ class AsyncTaskPublishProgressRaceTest extends Test{
|
||||
//this test is racy, but it should fail often enough to be a pest if something is broken
|
||||
|
||||
$this->getPlugin()->getServer()->getAsyncPool()->submitTask(new class($this) extends AsyncTask{
|
||||
/** @var bool */
|
||||
private static $success = false;
|
||||
|
||||
public function __construct(AsyncTaskPublishProgressRaceTest $t){
|
||||
|
Loading…
x
Reference in New Issue
Block a user