mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Cleanup and var implementation
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of phpDocumentor.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Param;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
use phpDocumentor\Reflection\Types\String_;
|
||||
|
||||
final class ParamFactoryTest extends TagFactoryTestCase
|
||||
{
|
||||
/**
|
||||
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::__construct
|
||||
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::create
|
||||
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::supports
|
||||
*/
|
||||
public function testParamIsCreated(): void
|
||||
{
|
||||
$ast = $this->parseTag('@param string $var');
|
||||
$factory = new ParamFactory($this->giveTypeFactory(), $this->givenDescriptionFactory());
|
||||
$context = new Context('global');
|
||||
|
||||
self::assertTrue($factory->supports($ast, $context));
|
||||
self::assertEquals(
|
||||
new Param(
|
||||
'var',
|
||||
new String_(),
|
||||
false,
|
||||
new Description(''),
|
||||
false
|
||||
),
|
||||
$factory->create($ast, $context)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of phpDocumentor.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @link http://phpdoc.org
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||
|
||||
use Mockery as m;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\FqsenResolver;
|
||||
use phpDocumentor\Reflection\TypeResolver;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use PHPStan\PhpDocParser\Lexer\Lexer;
|
||||
use PHPStan\PhpDocParser\Parser\ConstExprParser;
|
||||
use PHPStan\PhpDocParser\Parser\PhpDocParser;
|
||||
use PHPStan\PhpDocParser\Parser\TokenIterator;
|
||||
use PHPStan\PhpDocParser\Parser\TypeParser;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
abstract class TagFactoryTestCase extends TestCase
|
||||
{
|
||||
public function parseTag(string $tag): PhpDocTagNode
|
||||
{
|
||||
$lexer = new Lexer();
|
||||
$tokens = $lexer->tokenize($tag);
|
||||
$constParser = new ConstExprParser();
|
||||
|
||||
return (new PhpDocParser(new TypeParser($constParser), $constParser))->parseTag(new TokenIterator($tokens));
|
||||
}
|
||||
|
||||
public function giveTypeFactory(): TypeFactory
|
||||
{
|
||||
return new TypeFactory(new TypeResolver(new FqsenResolver()));
|
||||
}
|
||||
|
||||
public function givenDescriptionFactory(): DescriptionFactory
|
||||
{
|
||||
$factory = m::mock(DescriptionFactory::class);
|
||||
$factory->shouldReceive('create')->andReturn(new Description(''));
|
||||
|
||||
return $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call Mockery::close after each test.
|
||||
*
|
||||
* @after
|
||||
*/
|
||||
public function closeMockery(): void
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,15 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of phpDocumentor.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||
|
||||
use phpDocumentor\Reflection\Fqsen;
|
||||
@@ -56,6 +65,9 @@ final class TypeFactoryTest extends TestCase
|
||||
self::assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<array{0: string, 1: Type}>
|
||||
*/
|
||||
public function typeProvider(): array
|
||||
{
|
||||
return [
|
||||
@@ -126,6 +138,9 @@ final class TypeFactoryTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<array{0: string, 1: Type}>
|
||||
*/
|
||||
public function genericsProvider(): array
|
||||
{
|
||||
return [
|
||||
@@ -169,6 +184,9 @@ final class TypeFactoryTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<array{0: string, 1: Type}>
|
||||
*/
|
||||
public function callableProvider(): array
|
||||
{
|
||||
return [
|
||||
@@ -195,6 +213,9 @@ final class TypeFactoryTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<array{0: string, 1: Type}>
|
||||
*/
|
||||
public function constExpressions(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of phpDocumentor.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
use phpDocumentor\Reflection\Types\String_;
|
||||
|
||||
final class VarFactoryTest extends TagFactoryTestCase
|
||||
{
|
||||
/**
|
||||
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::__construct
|
||||
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::create
|
||||
* @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::supports
|
||||
*/
|
||||
public function testParamIsCreated(): void
|
||||
{
|
||||
$ast = $this->parseTag('@var string $var');
|
||||
$factory = new VarFactory($this->giveTypeFactory(), $this->givenDescriptionFactory());
|
||||
$context = new Context('global');
|
||||
|
||||
self::assertTrue($factory->supports($ast, $context));
|
||||
self::assertEquals(
|
||||
new Var_(
|
||||
'var',
|
||||
new String_(),
|
||||
new Description('')
|
||||
),
|
||||
$factory->create($ast, $context)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user