mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Merge remote-tracking branch 'upstream/master' into fix_for_phpstorm_stubs
* upstream/master: Bump mockery Fix FQSEN resolving on see,covers,uses Improve test coverage
This commit is contained in:
@@ -150,14 +150,40 @@ class AuthorTest extends TestCase
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Author::<public>
|
||||
*
|
||||
* @covers ::create
|
||||
* @dataProvider authorTagProvider
|
||||
*/
|
||||
public function testFactoryMethod() : void
|
||||
public function testFactoryMethod(string $input, string $output, string $name, string $email) : void
|
||||
{
|
||||
$fixture = Author::create('Mike van Riel <[email protected]>');
|
||||
$fixture = Author::create($input);
|
||||
|
||||
$this->assertSame('Mike van Riel <[email protected]>', (string) $fixture);
|
||||
$this->assertSame('Mike van Riel', $fixture->getAuthorName());
|
||||
$this->assertSame('[email protected]', $fixture->getEmail());
|
||||
$this->assertSame($output, (string) $fixture);
|
||||
$this->assertSame($name, $fixture->getAuthorName());
|
||||
$this->assertSame($email, $fixture->getEmail());
|
||||
}
|
||||
|
||||
/** @return mixed[][] */
|
||||
public function authorTagProvider() : array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'Mike van Riel <[email protected]>',
|
||||
'Mike van Riel <[email protected]>',
|
||||
'Mike van Riel',
|
||||
'[email protected]',
|
||||
],
|
||||
[
|
||||
'Mike van Riel < [email protected] >',
|
||||
'Mike van Riel <[email protected]>',
|
||||
'Mike van Riel',
|
||||
'[email protected]',
|
||||
],
|
||||
[
|
||||
'Mike van Riel',
|
||||
'Mike van Riel',
|
||||
'Mike van Riel',
|
||||
'',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,23 +4,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace DocBlock\Tags;
|
||||
|
||||
use Mockery as m;
|
||||
use InvalidArgumentException;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Example;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\Example
|
||||
* @covers ::<private>
|
||||
*/
|
||||
class ExampleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Call Mockery::close after each test.
|
||||
*/
|
||||
public function tearDown() : void
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
||||
*
|
||||
@@ -103,19 +96,147 @@ class ExampleTest extends TestCase
|
||||
/**
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
||||
*
|
||||
* @dataProvider tagContentProvider
|
||||
* @covers ::create
|
||||
* @covers ::__construct
|
||||
* @covers ::getFilePath
|
||||
* @covers ::getStartingLine
|
||||
* @covers ::getLineCount
|
||||
* @covers ::getDescription
|
||||
* @covers ::getContent
|
||||
*/
|
||||
public function testFullExample() : void
|
||||
public function testFactoryMethod(
|
||||
string $input,
|
||||
string $filePath,
|
||||
int $startLine,
|
||||
int $lineCount,
|
||||
?string $description,
|
||||
string $content
|
||||
) : void {
|
||||
$tag = Example::create($input);
|
||||
$this->assertSame($filePath, $tag->getFilePath());
|
||||
$this->assertSame($startLine, $tag->getStartingLine());
|
||||
$this->assertSame($lineCount, $tag->getLineCount());
|
||||
$this->assertSame($description, $tag->getDescription());
|
||||
$this->assertSame($content, $tag->getContent());
|
||||
}
|
||||
|
||||
/** @return mixed[][] */
|
||||
public function tagContentProvider() : array
|
||||
{
|
||||
$tag = Example::create('"example1.php" 10 5 test text');
|
||||
$this->assertEquals('example1.php', $tag->getFilePath());
|
||||
$this->assertEquals(10, $tag->getStartingLine());
|
||||
$this->assertEquals(5, $tag->getLineCount());
|
||||
$this->assertEquals('test text', $tag->getDescription());
|
||||
return [
|
||||
[
|
||||
'"example1.php" 10 5 test text ',
|
||||
'example1.php',
|
||||
10,
|
||||
5,
|
||||
'test text',
|
||||
'test text',
|
||||
],
|
||||
[
|
||||
'example1.php 10 5 test text',
|
||||
'example1.php',
|
||||
10,
|
||||
5,
|
||||
'test text',
|
||||
'test text',
|
||||
],
|
||||
[
|
||||
'example1.php 1 10 test text',
|
||||
'example1.php',
|
||||
1,
|
||||
10,
|
||||
'test text',
|
||||
'test text',
|
||||
],
|
||||
[
|
||||
'example1.php',
|
||||
'example1.php',
|
||||
1,
|
||||
0,
|
||||
null,
|
||||
'example1.php',
|
||||
],
|
||||
[
|
||||
'file://example1.php ',
|
||||
'file://example1.php',
|
||||
1,
|
||||
0,
|
||||
'',
|
||||
'file://example1.php',
|
||||
],
|
||||
[
|
||||
'/example1.php',
|
||||
'/example1.php',
|
||||
1,
|
||||
0,
|
||||
null,
|
||||
'/example1.php',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidExampleProvider
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testValidatesArguments(
|
||||
string $filePath,
|
||||
bool $isUrl,
|
||||
int $startLine,
|
||||
int $lineCount,
|
||||
string $description
|
||||
) : void {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
new Example(
|
||||
$filePath,
|
||||
$isUrl,
|
||||
$startLine,
|
||||
$lineCount,
|
||||
$description
|
||||
);
|
||||
}
|
||||
|
||||
/** @return mixed[][] */
|
||||
public function invalidExampleProvider() : array
|
||||
{
|
||||
return [
|
||||
'invalid start' => [
|
||||
'/some/path',
|
||||
false,
|
||||
-1,
|
||||
0,
|
||||
'text',
|
||||
],
|
||||
'invalid start 2' => [
|
||||
'/some/path',
|
||||
false,
|
||||
-10,
|
||||
0,
|
||||
'text',
|
||||
],
|
||||
'invalid length' => [
|
||||
'/some/path',
|
||||
false,
|
||||
1,
|
||||
-1,
|
||||
'text',
|
||||
],
|
||||
'invalid length 2' => [
|
||||
'/some/path',
|
||||
false,
|
||||
1,
|
||||
-10,
|
||||
'text',
|
||||
],
|
||||
'empty filepath' => [
|
||||
'',
|
||||
false,
|
||||
1,
|
||||
0,
|
||||
'text',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,6 +188,38 @@ class SeeTest extends TestCase
|
||||
$this->assertSame($description, $fixture->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::<public>
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
|
||||
* @uses \phpDocumentor\Reflection\FqsenResolver
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen
|
||||
* @uses \phpDocumentor\Reflection\Fqsen
|
||||
* @uses \phpDocumentor\Reflection\Types\Context
|
||||
*
|
||||
* @covers ::create
|
||||
*/
|
||||
public function testFactoryMethodWithNonClassFQSEN() : void
|
||||
{
|
||||
$descriptionFactory = m::mock(DescriptionFactory::class);
|
||||
$resolver = m::mock(FqsenResolver::class);
|
||||
$context = new Context('');
|
||||
|
||||
$fqsen = new Fqsen('\DateTime');
|
||||
$description = new Description('My Description');
|
||||
|
||||
$descriptionFactory
|
||||
->shouldReceive('create')->with('My Description', $context)->andReturn($description);
|
||||
$resolver->shouldReceive('resolve')->with('DateTime', $context)->andReturn($fqsen);
|
||||
|
||||
$fixture = See::create('DateTime::createFromFormat() My Description', $resolver, $descriptionFactory, $context);
|
||||
|
||||
$this->assertSame('\DateTime::createFromFormat() My Description', (string) $fixture);
|
||||
$this->assertInstanceOf(FqsenRef::class, $fixture->getReference());
|
||||
$this->assertSame('\DateTime::createFromFormat()', (string) $fixture->getReference());
|
||||
$this->assertSame($description, $fixture->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::<public>
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
|
||||
|
||||
Reference in New Issue
Block a user