Fix tests and linting errors after merging in release 4.x

This commit is contained in:
Mike van Riel
2019-12-27 21:38:28 +01:00
parent 1a5d9a2dbc
commit b668892da4
10 changed files with 112 additions and 87 deletions
+7 -4
View File
@@ -21,8 +21,10 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use const PREG_SPLIT_DELIM_CAPTURE;
use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
use function strlen;
use function strpos;
use function substr;
@@ -43,7 +45,7 @@ final class Param extends TagWithType implements Factory\StaticMethod
bool $isVariadic = false,
?Description $description = null
) {
$this->name = 'param';
$this->name = 'param';
$this->variableName = $variableName;
$this->type = $type;
$this->isVariadic = $isVariadic;
@@ -63,9 +65,10 @@ final class Param extends TagWithType implements Factory\StaticMethod
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
list($firstPart, $body) = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
[$firstPart, $body] = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = '';
$isVariadic = false;
+7 -5
View File
@@ -21,8 +21,10 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use const PREG_SPLIT_DELIM_CAPTURE;
use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
use function strlen;
use function strpos;
use function substr;
@@ -38,7 +40,7 @@ final class Property extends TagWithType implements Factory\StaticMethod
{
Assert::string($variableName);
$this->name = 'property';
$this->name = 'property';
$this->variableName = $variableName;
$this->type = $type;
$this->description = $description;
@@ -57,10 +59,10 @@ final class Property extends TagWithType implements Factory\StaticMethod
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
list($firstPart, $body) = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = '';
[$firstPart, $body] = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = '';
// if the first item that is encountered is not a variable; it is a type
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
+7 -5
View File
@@ -21,8 +21,10 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use const PREG_SPLIT_DELIM_CAPTURE;
use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
use function strlen;
use function strpos;
use function substr;
@@ -38,7 +40,7 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
{
Assert::string($variableName);
$this->name = 'property-read';
$this->name = 'property-read';
$this->variableName = $variableName;
$this->type = $type;
$this->description = $description;
@@ -57,10 +59,10 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
list($firstPart, $body) = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = '';
[$firstPart, $body] = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = '';
// if the first item that is encountered is not a variable; it is a type
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
+6 -5
View File
@@ -21,6 +21,7 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use const PREG_SPLIT_DELIM_CAPTURE;
use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
use function strlen;
@@ -39,7 +40,7 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
{
Assert::string($variableName);
$this->name = 'property-write';
$this->name = 'property-write';
$this->variableName = $variableName;
$this->type = $type;
$this->description = $description;
@@ -58,10 +59,10 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
list($firstPart, $body) = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = '';
[$firstPart, $body] = self::extractTypeFromBody($body);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$variableName = '';
// if the first item that is encountered is not a variable; it is a type
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
+7 -8
View File
@@ -19,17 +19,16 @@ use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use function preg_split;
/**
* Reflection class for a {@}return tag in a Docblock.
*/
final class Return_ extends TagWithType implements Factory\StaticMethod
{
public function __construct(Type $type, Description $description = null)
public function __construct(Type $type, ?Description $description = null)
{
$this->name = 'return';
$this->type = $type;
$this->name = 'return';
$this->type = $type;
$this->description = $description;
}
@@ -45,16 +44,16 @@ final class Return_ extends TagWithType implements Factory\StaticMethod
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
list($type, $description) = self::extractTypeFromBody($body);
[$type, $description] = self::extractTypeFromBody($body);
$type = $typeResolver->resolve($type, $context);
$type = $typeResolver->resolve($type, $context);
$description = $descriptionFactory->create($description, $context);
return new static($type, $description);
}
public function __toString() :string
public function __toString() : string
{
return $this->type . ' ' . (string) $this->description;
return ($this->type ?: 'mixed') . ' ' . (string) $this->description;
}
}
+13 -7
View File
@@ -8,33 +8,36 @@ declare(strict_types=1);
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2015 Mike van Riel<[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tags;
use phpDocumentor\Reflection\Type;
use function in_array;
use function strlen;
use function substr;
use function trim;
abstract class TagWithType extends BaseTag
{
/** @var Type */
/** @var ?Type */
protected $type;
/**
* Returns the type section of the variable.
*
* @return Type
*/
public function getType()
public function getType() : ?Type
{
return $this->type;
}
/**
* @return string[]
*/
protected static function extractTypeFromBody(string $body) : array
{
$type = '';
$type = '';
$nestingLevel = 0;
for ($i = 0; $i < strlen($body); $i++) {
$character = $body[$i];
@@ -46,9 +49,12 @@ abstract class TagWithType extends BaseTag
$type .= $character;
if (in_array($character, ['<', '(', '[', '{'])) {
$nestingLevel++;
continue;
}
if (in_array($character, ['>', ')', ']', '}'])) {
$nestingLevel--;
continue;
}
}
+5 -6
View File
@@ -19,17 +19,16 @@ use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use function preg_split;
/**
* Reflection class for a {@}throws tag in a Docblock.
*/
final class Throws extends TagWithType implements Factory\StaticMethod
{
public function __construct(Type $type, Description $description = null)
public function __construct(Type $type, ?Description $description = null)
{
$this->name = 'throws';
$this->type = $type;
$this->name = 'throws';
$this->type = $type;
$this->description = $description;
}
@@ -45,9 +44,9 @@ final class Throws extends TagWithType implements Factory\StaticMethod
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
list($type, $description) = self::extractTypeFromBody($body);
[$type, $description] = self::extractTypeFromBody($body);
$type = $typeResolver->resolve($type, $context);
$type = $typeResolver->resolve($type, $context);
$description = $descriptionFactory->create($description, $context);
return new static($type, $description);
+9 -6
View File
@@ -21,8 +21,10 @@ use phpDocumentor\Reflection\Types\Context as TypeContext;
use Webmozart\Assert\Assert;
use const PREG_SPLIT_DELIM_CAPTURE;
use function array_shift;
use function array_unshift;
use function implode;
use function preg_split;
use function strlen;
use function strpos;
use function substr;
@@ -38,10 +40,10 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
{
Assert::string($variableName);
$this->name = 'var';
$this->name = 'var';
$this->variableName = $variableName;
$this->type = $type;
$this->description = $description;
$this->type = $type;
$this->description = $description;
}
/**
@@ -57,9 +59,10 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
list($firstPart, $body) = self::extractTypeFromBody($body);
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$type = null;
[$firstPart, $body] = self::extractTypeFromBody($body);
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
$type = null;
$variableName = '';
// if the first item that is encountered is not a variable; it is a type
+24 -19
View File
@@ -13,6 +13,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags;
use InvalidArgumentException;
use Mockery as m;
use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
@@ -158,50 +159,53 @@ class ReturnTest extends TestCase
* This test tests whether an error occurs demonstrating that the braces were taken into account; this test is still
* expected to produce an exception because the TypeResolver does not support generics.
*
* @covers ::create
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_::<public>
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
* @uses \phpDocumentor\Reflection\TypeResolver
* @uses \phpDocumentor\Reflection\DocBlock\Description
* @uses \phpDocumentor\Reflection\Types\String_
* @uses \phpDocumentor\Reflection\Types\Context
*
* @covers ::create
*/
public function testFactoryMethodWithGenericWithSpace()
public function testFactoryMethodWithGenericWithSpace() : void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('"\array<string, string>" is not a valid Fqsen.');
$descriptionFactory = m::mock(DescriptionFactory::class);
$resolver = new TypeResolver();
$context = new Context('');
$resolver = new TypeResolver();
$context = new Context('');
$description = new Description('My Description');
$descriptionFactory->shouldReceive('create')
->with('My Description', $context)
->andReturn($description);
Return_::create('array<string, string> My Description', $resolver, $descriptionFactory, $context);
$fixture = Return_::create('array<string, string> My Description', $resolver, $descriptionFactory, $context);
$this->assertSame('array<string,string> My Description', (string) $fixture);
$this->assertEquals('array<string,string>', $fixture->getType());
$this->assertSame($description, $fixture->getDescription());
}
/**
* @see self::testFactoryMethodWithGenericWithSpace()
*
* @covers ::create
* @see self::testFactoryMethodWithGenericWithSpace()
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_::<public>
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
* @uses \phpDocumentor\Reflection\TypeResolver
* @uses \phpDocumentor\Reflection\DocBlock\Description
* @uses \phpDocumentor\Reflection\Types\String_
* @uses \phpDocumentor\Reflection\Types\Context
*
* @covers ::create
*/
public function testFactoryMethodWithGenericWithSpaceAndAddedEmojisToVerifyMultiByteBehaviour()
public function testFactoryMethodWithGenericWithSpaceAndAddedEmojisToVerifyMultiByteBehaviour() : void
{
$this->expectException(\InvalidArgumentException::class);
$this->markTestSkipped('A bug in the TypeResolver breaks this test');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('"\array😁<string,😁 😁string>" is not a valid Fqsen.');
$descriptionFactory = m::mock(DescriptionFactory::class);
$resolver = new TypeResolver();
$context = new Context('');
$resolver = new TypeResolver();
$context = new Context('');
$description = new Description('My Description');
$descriptionFactory->shouldReceive('create')
@@ -212,19 +216,20 @@ class ReturnTest extends TestCase
}
/**
* @covers ::create
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_::<public>
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
* @uses \phpDocumentor\Reflection\TypeResolver
* @uses \phpDocumentor\Reflection\DocBlock\Description
* @uses \phpDocumentor\Reflection\Types\String_
* @uses \phpDocumentor\Reflection\Types\Context
*
* @covers ::create
*/
public function testFactoryMethodWithEmojisToVerifyMultiByteBehaviour()
public function testFactoryMethodWithEmojisToVerifyMultiByteBehaviour() : void
{
$descriptionFactory = m::mock(DescriptionFactory::class);
$resolver = new TypeResolver();
$context = new Context('');
$resolver = new TypeResolver();
$context = new Context('');
$description = new Description('My Description');
$descriptionFactory->shouldReceive('create')
+27 -22
View File
@@ -13,6 +13,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags;
use InvalidArgumentException;
use Mockery as m;
use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
@@ -134,10 +135,10 @@ class ThrowsTest extends TestCase
public function testFactoryMethod() : void
{
$descriptionFactory = m::mock(DescriptionFactory::class);
$resolver = new TypeResolver();
$context = new Context('');
$resolver = new TypeResolver();
$context = new Context('');
$type = new String_();
$type = new String_();
$description = new Description('My Description');
$descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description);
@@ -158,50 +159,53 @@ class ThrowsTest extends TestCase
* This test tests whether an error occurs demonstrating that the braces were taken into account; this test is still
* expected to produce an exception because the TypeResolver does not support generics.
*
* @covers ::create
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Throws::<public>
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
* @uses \phpDocumentor\Reflection\TypeResolver
* @uses \phpDocumentor\Reflection\DocBlock\Description
* @uses \phpDocumentor\Reflection\Types\String_
* @uses \phpDocumentor\Reflection\Types\Context
*
* @covers ::create
*/
public function testFactoryMethodWithGenericWithSpace()
public function testFactoryMethodWithGenericWithSpace() : void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('"\array<string, string>" is not a valid Fqsen.');
$descriptionFactory = m::mock(DescriptionFactory::class);
$resolver = new TypeResolver();
$context = new Context('');
$resolver = new TypeResolver();
$context = new Context('');
$description = new Description('My Description');
$descriptionFactory->shouldReceive('create')
->with('My Description', $context)
->andReturn($description);
Throws::create('array<string, string> My Description', $resolver, $descriptionFactory, $context);
$fixture = Throws::create('array<string, string> My Description', $resolver, $descriptionFactory, $context);
$this->assertSame('array<string,string> My Description', (string) $fixture);
$this->assertEquals('array<string,string>', $fixture->getType());
$this->assertSame($description, $fixture->getDescription());
}
/**
* @see self::testFactoryMethodWithGenericWithSpace()
*
* @covers ::create
* @see self::testFactoryMethodWithGenericWithSpace()
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Throws::<public>
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
* @uses \phpDocumentor\Reflection\TypeResolver
* @uses \phpDocumentor\Reflection\DocBlock\Description
* @uses \phpDocumentor\Reflection\Types\String_
* @uses \phpDocumentor\Reflection\Types\Context
*
* @covers ::create
*/
public function testFactoryMethodWithGenericWithSpaceAndAddedEmojisToVerifyMultiByteBehaviour()
public function testFactoryMethodWithGenericWithSpaceAndAddedEmojisToVerifyMultiByteBehaviour() : void
{
$this->expectException(\InvalidArgumentException::class);
$this->markTestSkipped('A bug in the TypeResolver breaks this test');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('"\array😁<string,😁 😁string>" is not a valid Fqsen.');
$descriptionFactory = m::mock(DescriptionFactory::class);
$resolver = new TypeResolver();
$context = new Context('');
$resolver = new TypeResolver();
$context = new Context('');
$description = new Description('My Description');
$descriptionFactory->shouldReceive('create')
@@ -212,19 +216,20 @@ class ThrowsTest extends TestCase
}
/**
* @covers ::create
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Throws::<public>
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
* @uses \phpDocumentor\Reflection\TypeResolver
* @uses \phpDocumentor\Reflection\DocBlock\Description
* @uses \phpDocumentor\Reflection\Types\String_
* @uses \phpDocumentor\Reflection\Types\Context
*
* @covers ::create
*/
public function testFactoryMethodWithEmojisToVerifyMultiByteBehaviour()
public function testFactoryMethodWithEmojisToVerifyMultiByteBehaviour() : void
{
$descriptionFactory = m::mock(DescriptionFactory::class);
$resolver = new TypeResolver();
$context = new Context('');
$resolver = new TypeResolver();
$context = new Context('');
$description = new Description('My Description');
$descriptionFactory->shouldReceive('create')