mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Fixup TesterPlugin to PHPStan standards
This commit is contained in:
parent
09eb904f6b
commit
b7578fef9c
@ -20,6 +20,8 @@ parameters:
|
|||||||
checkExplicitMixed: true
|
checkExplicitMixed: true
|
||||||
bootstrapFiles:
|
bootstrapFiles:
|
||||||
- tests/phpstan/bootstrap.php
|
- tests/phpstan/bootstrap.php
|
||||||
|
scanDirectories:
|
||||||
|
- tests/plugins/TesterPlugin
|
||||||
scanFiles:
|
scanFiles:
|
||||||
- src/pocketmine/PocketMine.php
|
- src/pocketmine/PocketMine.php
|
||||||
- build/make-release.php
|
- build/make-release.php
|
||||||
@ -29,6 +31,7 @@ parameters:
|
|||||||
- build/make-release.php
|
- build/make-release.php
|
||||||
- build/server-phar.php
|
- build/server-phar.php
|
||||||
- tests/phpunit
|
- tests/phpunit
|
||||||
|
- tests/plugins/TesterPlugin
|
||||||
dynamicConstantNames:
|
dynamicConstantNames:
|
||||||
- pocketmine\IS_DEVELOPMENT_BUILD
|
- pocketmine\IS_DEVELOPMENT_BUILD
|
||||||
- pocketmine\DEBUG
|
- pocketmine\DEBUG
|
||||||
|
@ -1715,3 +1715,8 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: ../../phpunit/network/mcpe/StupidJsonDecodeTest.php
|
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 */
|
/** @var int */
|
||||||
protected $currentTestNumber = 0;
|
protected $currentTestNumber = 0;
|
||||||
|
|
||||||
public function onEnable(){
|
public function onEnable() : void{
|
||||||
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||||
$this->getScheduler()->scheduleRepeatingTask(new CheckTestCompletionTask($this), 10);
|
$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
|
//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
|
//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
|
//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{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getCurrentTest() : ?Test{
|
||||||
* @return Test|null
|
|
||||||
*/
|
|
||||||
public function getCurrentTest(){
|
|
||||||
return $this->currentTest;
|
return $this->currentTest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +74,7 @@ class Main extends PluginBase implements Listener{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onTestCompleted(Test $test){
|
public function onTestCompleted(Test $test) : void{
|
||||||
$message = "Finished test #" . $this->currentTestNumber . " (" . $test->getName() . "): ";
|
$message = "Finished test #" . $this->currentTestNumber . " (" . $test->getName() . "): ";
|
||||||
switch($test->getResult()){
|
switch($test->getResult()){
|
||||||
case Test::RESULT_OK:
|
case Test::RESULT_OK:
|
||||||
@ -103,7 +100,7 @@ class Main extends PluginBase implements Listener{
|
|||||||
$this->currentTest = null;
|
$this->currentTest = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onAllTestsCompleted(){
|
public function onAllTestsCompleted() : void{
|
||||||
$this->getLogger()->notice("All tests finished, stopping the server");
|
$this->getLogger()->notice("All tests finished, stopping the server");
|
||||||
$this->getServer()->shutdown();
|
$this->getServer()->shutdown();
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,13 @@ abstract class Test{
|
|||||||
const RESULT_FAILED = 1;
|
const RESULT_FAILED = 1;
|
||||||
const RESULT_ERROR = 2;
|
const RESULT_ERROR = 2;
|
||||||
|
|
||||||
|
/** @var Main */
|
||||||
private $plugin;
|
private $plugin;
|
||||||
|
/** @var int */
|
||||||
private $result = Test::RESULT_WAITING;
|
private $result = Test::RESULT_WAITING;
|
||||||
|
/** @var int */
|
||||||
private $startTime;
|
private $startTime;
|
||||||
|
/** @var int */
|
||||||
private $timeout = 60; //seconds
|
private $timeout = 60; //seconds
|
||||||
|
|
||||||
public function __construct(Main $plugin){
|
public function __construct(Main $plugin){
|
||||||
@ -42,7 +46,7 @@ abstract class Test{
|
|||||||
return $this->plugin;
|
return $this->plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function start(){
|
final public function start() : void{
|
||||||
$this->startTime = time();
|
$this->startTime = time();
|
||||||
try{
|
try{
|
||||||
$this->run();
|
$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{
|
public function isFinished() : bool{
|
||||||
return $this->result !== Test::RESULT_WAITING;
|
return $this->result !== Test::RESULT_WAITING;
|
||||||
@ -69,7 +73,7 @@ abstract class Test{
|
|||||||
return !$this->isFinished() and time() - $this->timeout > $this->startTime;
|
return !$this->isFinished() and time() - $this->timeout > $this->startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setTimeout(int $timeout){
|
protected function setTimeout(int $timeout) : void{
|
||||||
$this->timeout = $timeout;
|
$this->timeout = $timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +81,7 @@ abstract class Test{
|
|||||||
return $this->result;
|
return $this->result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setResult(int $result){
|
public function setResult(int $result) : void{
|
||||||
$this->result = $result;
|
$this->result = $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,11 +26,13 @@ namespace pmmp\TesterPlugin\tests;
|
|||||||
use pmmp\TesterPlugin\Test;
|
use pmmp\TesterPlugin\Test;
|
||||||
use pocketmine\scheduler\AsyncTask;
|
use pocketmine\scheduler\AsyncTask;
|
||||||
use pocketmine\Server;
|
use pocketmine\Server;
|
||||||
|
use pocketmine\utils\AssumptionFailedError;
|
||||||
use pocketmine\utils\MainLogger;
|
use pocketmine\utils\MainLogger;
|
||||||
|
use function ob_get_contents;
|
||||||
|
|
||||||
class AsyncTaskMainLoggerTest extends Test{
|
class AsyncTaskMainLoggerTest extends Test{
|
||||||
|
|
||||||
public function run(){
|
public function run() : void{
|
||||||
$this->getPlugin()->getServer()->getAsyncPool()->submitTask(new class($this) extends AsyncTask{
|
$this->getPlugin()->getServer()->getAsyncPool()->submitTask(new class($this) extends AsyncTask{
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
@ -43,7 +45,9 @@ class AsyncTaskMainLoggerTest extends Test{
|
|||||||
public function onRun(){
|
public function onRun(){
|
||||||
ob_start();
|
ob_start();
|
||||||
MainLogger::getLogger()->info("Testing");
|
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;
|
$this->success = true;
|
||||||
}
|
}
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
|
@ -28,11 +28,11 @@ use pocketmine\scheduler\AsyncTask;
|
|||||||
|
|
||||||
class AsyncTaskMemoryLeakTest extends Test{
|
class AsyncTaskMemoryLeakTest extends Test{
|
||||||
|
|
||||||
public function run(){
|
public function run() : void{
|
||||||
$this->getPlugin()->getServer()->getAsyncPool()->submitTask(new TestAsyncTask());
|
$this->getPlugin()->getServer()->getAsyncPool()->submitTask(new TestAsyncTask());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tick(){
|
public function tick() : void{
|
||||||
if(TestAsyncTask::$destroyed === true){
|
if(TestAsyncTask::$destroyed === true){
|
||||||
$this->setResult(Test::RESULT_OK);
|
$this->setResult(Test::RESULT_OK);
|
||||||
}
|
}
|
||||||
@ -48,6 +48,7 @@ class AsyncTaskMemoryLeakTest extends Test{
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TestAsyncTask extends AsyncTask{
|
class TestAsyncTask extends AsyncTask{
|
||||||
|
/** @var bool */
|
||||||
public static $destroyed = false;
|
public static $destroyed = false;
|
||||||
|
|
||||||
public function onRun(){
|
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 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{
|
$this->getPlugin()->getServer()->getAsyncPool()->submitTask(new class($this) extends AsyncTask{
|
||||||
|
/** @var bool */
|
||||||
private static $success = false;
|
private static $success = false;
|
||||||
|
|
||||||
public function __construct(AsyncTaskPublishProgressRaceTest $t){
|
public function __construct(AsyncTaskPublishProgressRaceTest $t){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user