Merge branch 'stable'

This commit is contained in:
Dylan K. Taylor
2020-02-07 18:13:55 +00:00
88 changed files with 543 additions and 283 deletions

View File

@ -0,0 +1,3 @@
parameters:
ignoreErrors:
- "#^Method ReflectionMethod\\:\\:getClosure\\(\\) invoked with 0 parameters, 1 required\\.$#"

View File

@ -1,17 +1,10 @@
parameters:
ignoreErrors:
- "#^Call to function is_resource\\(\\) with resource will always evaluate to true\\.$#"
-
message: "#^Default value of the parameter \\#\\d+ \\$[A-Za-z\\d_]+ \\(\\-?\\d+\\) of method .+\\(\\) is incompatible with type float\\.$#"
path: ../../../src
-
message: "#^Cannot access an offset on Threaded\\.$#"
path: ../../../src
-
message: "#^Cannot assign new offset to Threaded\\.$#"
path: ../../../src
-
message: "#^Offset string does not exist on array\\(\\)\\.$#"
count: 3
@ -39,6 +32,12 @@ parameters:
count: 1
path: ../../../src/block/Liquid.php
-
#readline() may return false
message: "#^Strict comparison using \\!\\=\\= between string and false will always evaluate to true\\.$#"
count: 1
path: ../../../src/command/CommandReader.php
-
message: "#^Call to function assert\\(\\) with false and 'unknown hit type' will always evaluate to false\\.$#"
count: 1
@ -65,3 +64,9 @@ parameters:
message: "#^If condition is always false\\.$#"
count: 1
path: ../../../src/network/mcpe/protocol/types/entity/EntityMetadataCollection.php
-
#phpstan doesn't understand that SplFixedArray may contain null
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with int and string will always evaluate to true\\.$#"
count: 1
path: ../../../tests/phpunit/block/BlockTest.php

View File

@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$class of static method pocketmine\\\\world\\\\format\\\\io\\\\WorldProviderManager\\:\\:addProvider\\(\\) expects class\\-string\\<pocketmine\\\\world\\\\format\\\\io\\\\WorldProvider\\>, string given\\.$#"
count: 2
path: ../../phpunit/world/format/io/LevelProviderManagerTest.php

View File

@ -1,13 +1,50 @@
parameters:
ignoreErrors:
-
message: "#^Instanceof between pocketmine\\\\event\\\\RegisteredListener and pocketmine\\\\event\\\\RegisteredListener will always evaluate to true\\.$#"
count: 1
path: ../../../src/event/HandlerList.php
-
#jsonDeserialize(), not currently validated
message: "#^Casting to int something that's already int\\.$#"
count: 3
path: ../../../src/item/Item.php
-
#commands plugin.yml not currently validated, can't be sure
message: "#^Call to function is_array\\(\\) with array\\<string, mixed\\> will always evaluate to true\\.$#"
count: 1
path: ../../../src/plugin/PluginBase.php
-
#::add() / ::remove() thread parameter
message: "#^If condition is always true\\.$#"
count: 2
path: ../../../src/thread/ThreadManager.php
-
message: "#^Instanceof between pocketmine\\\\thread\\\\Worker and pocketmine\\\\thread\\\\Worker will always evaluate to true\\.$#"
count: 2
path: ../../../src/thread/ThreadManager.php
-
#->sendBlocks() blocks parameter
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 1
path: ../../../src/world/World.php
-
message: "#^Instanceof between pocketmine\\\\math\\\\Vector3 and pocketmine\\\\math\\\\Vector3 will always evaluate to true\\.$#"
count: 1
path: ../../../src/world/World.php
-
message: "#^Call to function is_object\\(\\) with \\*NEVER\\* will always evaluate to true\\.$#"
count: 1
path: ../../../src/world/World.php
-
message: "#^Call to function assert\\(\\) with bool will always evaluate to true\\.$#"
count: 1
path: ../../../src/world/World.php

View File

@ -64,7 +64,7 @@ class BlockTest extends TestCase{
}
}
self::assertTrue(false, "Can't test registering new blocks because no unused spaces left");
throw new \RuntimeException("Can't test registering new blocks because no unused spaces left");
}
/**
@ -97,7 +97,8 @@ class BlockTest extends TestCase{
}
/**
* @return array
* @return int[][]
* @phpstan-return list<array{int,int}>
*/
public function blockGetProvider() : array{
return [

View File

@ -29,7 +29,7 @@ use pocketmine\item\ItemIds;
class BaseInventoryTest extends TestCase{
public static function setUpBeforeClass(){
public static function setUpBeforeClass() : void{
ItemFactory::init();
}

View File

@ -42,6 +42,10 @@ class ItemFactoryTest extends TestCase{
}
}
/**
* @return mixed[][]
* @phpstan-return list<array{string,int,int}>
*/
public function itemFromStringProvider() : array{
return [
["dye:4", ItemIds::DYE, 4],

View File

@ -33,6 +33,10 @@ class StupidJsonDecodeTest extends TestCase{
$this->stupidJsonDecodeFunc = (new \ReflectionMethod(InGamePacketHandler::class, 'stupid_json_decode'))->getClosure();
}
/**
* @return mixed[][]
* @phpstan-return list<array{string,mixed}>
*/
public function stupidJsonDecodeProvider() : array{
return [
["[\n \"a\",\"b,c,d,e\\\" \",,0,1,2, false, 0.001]", ['a', 'b,c,d,e" ', '', 0, 1, 2, false, 0.001]],
@ -55,7 +59,7 @@ class StupidJsonDecodeTest extends TestCase{
*
* @throws \ReflectionException
*/
public function testStupidJsonDecode(string $brokenJson, $expect){
public function testStupidJsonDecode(string $brokenJson, $expect) : void{
$decoded = ($this->stupidJsonDecodeFunc)($brokenJson, true);
self::assertEquals($expect, $decoded);
}

View File

@ -28,7 +28,8 @@ use PHPUnit\Framework\TestCase;
class ConfigTest extends TestCase{
/**
* @return \Generator
* @return \Generator|mixed[][]
* @phpstan-return \Generator<int, array{string, mixed[]}, void, void>
*/
public function fixYamlIndexesProvider() : \Generator{
yield ["x: 1\ny: 2\nz: 3\n", [
@ -60,8 +61,8 @@ class ConfigTest extends TestCase{
/**
* @dataProvider fixYamlIndexesProvider
*
* @param string $test
* @param array $expected
* @param string $test
* @param mixed[] $expected
*/
public function testFixYamlIndexes(string $test, array $expected) : void{
$fixed = Config::fixYAMLIndexes($test);

View File

@ -29,7 +29,7 @@ use function defined;
class UtilsTest extends TestCase{
public function setUp(){
public function setUp() : void{
if(!defined('pocketmine\PATH')){
define('pocketmine\PATH', 'dummy');
}
@ -38,6 +38,10 @@ class UtilsTest extends TestCase{
}
}
/**
* @return string[][]
* @phpstan-return list<array{string}>
*/
public function parseDocCommentNewlineProvider() : array{
return [
["\t/**\r\n\t * @param PlayerJoinEvent \$event\r\n\t * @priority HIGHEST\r\n\t * @notHandler\r\n\t */"],
@ -61,6 +65,6 @@ class UtilsTest extends TestCase{
public function testNamespacedNiceClosureName() : void{
//be careful with this test. The closure has to be declared on the same line as the assertion.
self::assertSame('closure@' . Filesystem::cleanPath(__FILE__) . '#L' . __LINE__, Utils::getNiceClosureName(function(){}));
self::assertSame('closure@' . Filesystem::cleanPath(__FILE__) . '#L' . __LINE__, Utils::getNiceClosureName(function() : void{}));
}
}

View File

@ -38,7 +38,7 @@ class RegionLoaderTest extends TestCase{
/** @var RegionLoader */
private $region;
public function setUp(){
public function setUp() : void{
$this->regionPath = sys_get_temp_dir() . '/test.testregion';
if(file_exists($this->regionPath)){
unlink($this->regionPath);
@ -47,7 +47,7 @@ class RegionLoaderTest extends TestCase{
$this->region->open();
}
public function tearDown(){
public function tearDown() : void{
$this->region->close();
if(file_exists($this->regionPath)){
unlink($this->regionPath);
@ -69,6 +69,10 @@ class RegionLoaderTest extends TestCase{
self::assertSame($data, $r->readChunk(0, 0));
}
/**
* @return \Generator|int[][]
* @phpstan-return \Generator<int, array{int,int}, void, void>
*/
public function outOfBoundsCoordsProvider() : \Generator{
yield [-1, -1];
yield [32, 32];