From 500fd2d8424ea1697fd6963975fe04cee0987488 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 26 Oct 2020 15:59:17 +0000 Subject: [PATCH 1/5] tests: strip useless phpdoc --- tests/phpunit/block/BlockTest.php | 2 -- tests/phpunit/item/ItemTest.php | 3 --- tests/phpunit/level/format/io/region/RegionLoaderTest.php | 4 ---- tests/phpunit/network/mcpe/StupidJsonDecodeTest.php | 1 - tests/phpunit/utils/ConfigTest.php | 1 - tests/phpunit/utils/UtilsTest.php | 1 - 6 files changed, 12 deletions(-) diff --git a/tests/phpunit/block/BlockTest.php b/tests/phpunit/block/BlockTest.php index 5dc6f944d..417e46177 100644 --- a/tests/phpunit/block/BlockTest.php +++ b/tests/phpunit/block/BlockTest.php @@ -110,8 +110,6 @@ class BlockTest extends TestCase{ /** * @dataProvider blockGetProvider - * @param int $id - * @param int $meta */ public function testBlockGet(int $id, int $meta) : void{ $block = BlockFactory::get($id, $meta); diff --git a/tests/phpunit/item/ItemTest.php b/tests/phpunit/item/ItemTest.php index 817840f6c..57a94ea6e 100644 --- a/tests/phpunit/item/ItemTest.php +++ b/tests/phpunit/item/ItemTest.php @@ -79,9 +79,6 @@ class ItemTest extends TestCase{ /** * @dataProvider itemFromStringProvider - * @param string $string - * @param int $id - * @param int $meta */ public function testFromStringSingle(string $string, int $id, int $meta) : void{ $item = ItemFactory::fromStringSingle($string); diff --git a/tests/phpunit/level/format/io/region/RegionLoaderTest.php b/tests/phpunit/level/format/io/region/RegionLoaderTest.php index 87145144c..0640f1858 100644 --- a/tests/phpunit/level/format/io/region/RegionLoaderTest.php +++ b/tests/phpunit/level/format/io/region/RegionLoaderTest.php @@ -82,8 +82,6 @@ class RegionLoaderTest extends TestCase{ /** * @dataProvider outOfBoundsCoordsProvider - * @param int $x - * @param int $z * * @throws ChunkException * @throws \InvalidArgumentException @@ -109,8 +107,6 @@ class RegionLoaderTest extends TestCase{ /** * @dataProvider outOfBoundsCoordsProvider - * @param int $x - * @param int $z * * @throws \InvalidArgumentException * @throws \pocketmine\level\format\io\exception\CorruptedChunkException diff --git a/tests/phpunit/network/mcpe/StupidJsonDecodeTest.php b/tests/phpunit/network/mcpe/StupidJsonDecodeTest.php index c290b65eb..b912c47ad 100644 --- a/tests/phpunit/network/mcpe/StupidJsonDecodeTest.php +++ b/tests/phpunit/network/mcpe/StupidJsonDecodeTest.php @@ -57,7 +57,6 @@ class StupidJsonDecodeTest extends TestCase{ /** * @dataProvider stupidJsonDecodeProvider * - * @param string $brokenJson * @param mixed $expect * * @throws \ReflectionException diff --git a/tests/phpunit/utils/ConfigTest.php b/tests/phpunit/utils/ConfigTest.php index 3e1487358..97d88a788 100644 --- a/tests/phpunit/utils/ConfigTest.php +++ b/tests/phpunit/utils/ConfigTest.php @@ -61,7 +61,6 @@ class ConfigTest extends TestCase{ /** * @dataProvider fixYamlIndexesProvider * - * @param string $test * @param mixed[] $expected */ public function testFixYamlIndexes(string $test, array $expected) : void{ diff --git a/tests/phpunit/utils/UtilsTest.php b/tests/phpunit/utils/UtilsTest.php index 8c49e567a..38357a96c 100644 --- a/tests/phpunit/utils/UtilsTest.php +++ b/tests/phpunit/utils/UtilsTest.php @@ -51,7 +51,6 @@ class UtilsTest extends TestCase{ } /** - * @param string $docComment * @dataProvider parseDocCommentNewlineProvider */ public function testParseDocCommentNewlines(string $docComment) : void{ From e2e960e43de6ccffc609c18a663a95784ae8f7e4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 26 Oct 2020 15:59:42 +0000 Subject: [PATCH 2/5] tests: add missing function imports --- .../level/format/io/region/RegionLocationTableEntryTest.php | 1 + tests/phpunit/utils/ConfigTest.php | 1 + tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/Main.php | 1 + tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/Test.php | 2 ++ .../src/pmmp/TesterPlugin/tests/AsyncTaskMainLoggerTest.php | 3 +++ .../src/pmmp/TesterPlugin/tests/AsyncTaskMemoryLeakTest.php | 1 + 6 files changed, 9 insertions(+) diff --git a/tests/phpunit/level/format/io/region/RegionLocationTableEntryTest.php b/tests/phpunit/level/format/io/region/RegionLocationTableEntryTest.php index bf8550df4..c87a537a1 100644 --- a/tests/phpunit/level/format/io/region/RegionLocationTableEntryTest.php +++ b/tests/phpunit/level/format/io/region/RegionLocationTableEntryTest.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\level\format\io\region; use PHPUnit\Framework\TestCase; +use function sprintf; class RegionLocationTableEntryTest extends TestCase{ diff --git a/tests/phpunit/utils/ConfigTest.php b/tests/phpunit/utils/ConfigTest.php index 97d88a788..22f9f3ea8 100644 --- a/tests/phpunit/utils/ConfigTest.php +++ b/tests/phpunit/utils/ConfigTest.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\utils; use PHPUnit\Framework\TestCase; +use function yaml_parse; class ConfigTest extends TestCase{ diff --git a/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/Main.php b/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/Main.php index 41ca5512e..cbe1408e3 100644 --- a/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/Main.php +++ b/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/Main.php @@ -26,6 +26,7 @@ namespace pmmp\TesterPlugin; use pocketmine\event\Listener; use pocketmine\event\server\CommandEvent; use pocketmine\plugin\PluginBase; +use function array_shift; class Main extends PluginBase implements Listener{ diff --git a/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/Test.php b/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/Test.php index f20402336..7af551840 100644 --- a/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/Test.php +++ b/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/Test.php @@ -23,6 +23,8 @@ declare(strict_types=1); namespace pmmp\TesterPlugin; +use function time; + abstract class Test{ const RESULT_WAITING = -1; const RESULT_OK = 0; diff --git a/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMainLoggerTest.php b/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMainLoggerTest.php index 3f52c6fd5..fd10642ff 100644 --- a/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMainLoggerTest.php +++ b/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMainLoggerTest.php @@ -28,7 +28,10 @@ use pocketmine\scheduler\AsyncTask; use pocketmine\Server; use pocketmine\utils\AssumptionFailedError; use pocketmine\utils\MainLogger; +use function ob_end_flush; use function ob_get_contents; +use function ob_start; +use function strpos; class AsyncTaskMainLoggerTest extends Test{ diff --git a/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMemoryLeakTest.php b/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMemoryLeakTest.php index 7970fc026..b59c08c0f 100644 --- a/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMemoryLeakTest.php +++ b/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMemoryLeakTest.php @@ -25,6 +25,7 @@ namespace pmmp\TesterPlugin\tests; use pmmp\TesterPlugin\Test; use pocketmine\scheduler\AsyncTask; +use function usleep; class AsyncTaskMemoryLeakTest extends Test{ From 340881d590b124969f80aec057d3e26fb123ed53 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 26 Oct 2020 15:59:57 +0000 Subject: [PATCH 3/5] remove superfluous newline --- .../src/pmmp/TesterPlugin/tests/AsyncTaskMainLoggerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMainLoggerTest.php b/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMainLoggerTest.php index fd10642ff..dc4b1b122 100644 --- a/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMainLoggerTest.php +++ b/tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMainLoggerTest.php @@ -72,5 +72,4 @@ class AsyncTaskMainLoggerTest extends Test{ return "Verifies that the MainLogger is accessible by MainLogger::getLogger() in an AsyncTask"; } - } From c0dafe787277faad36b058461186d3666027d0c4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 29 Oct 2020 13:32:56 +0000 Subject: [PATCH 4/5] Explosion: remove dead code this was needed for the old ExplodePacket, which was removed a few versions back. --- src/pocketmine/level/Explosion.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index 07c82399e..066f5cdea 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -154,7 +154,6 @@ class Explosion{ * and creating sounds and particles. */ public function explodeB() : bool{ - $send = []; $updateBlocks = []; $source = (new Vector3($this->source->x, $this->source->y, $this->source->z))->floor(); @@ -254,7 +253,6 @@ class Explosion{ $updateBlocks[$index] = true; } } - $send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z); } $this->level->addParticle(new HugeExplodeSeedParticle($source)); From deb0cee8a0467434e21afea87a776b0d9caf38d5 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 1 Nov 2020 16:49:13 +0300 Subject: [PATCH 5/5] BaseInventory::canAddItem(): consider item max stack size (#3881) this fixes addItem() failing when canAddItem() reported that an item can be added. --- src/pocketmine/inventory/BaseInventory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index f1d8bb987..cde92cc4a 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -252,11 +252,11 @@ abstract class BaseInventory implements Inventory{ for($i = 0, $size = $this->getSize(); $i < $size; ++$i){ $slot = $this->getItem($i); if($item->equals($slot)){ - if(($diff = $slot->getMaxStackSize() - $slot->getCount()) > 0){ + if(($diff = min($slot->getMaxStackSize(), $item->getMaxStackSize()) - $slot->getCount()) > 0){ $count -= $diff; } }elseif($slot->isNull()){ - $count -= $this->getMaxStackSize(); + $count -= min($this->getMaxStackSize(), $item->getMaxStackSize()); } if($count <= 0){