mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Improve test coverage
This commit is contained in:
@@ -30,7 +30,7 @@ psalm:
|
|||||||
.PHONY: test
|
.PHONY: test
|
||||||
test:
|
test:
|
||||||
docker run -it --rm -v${CURDIR}:/github/workspace phpdoc/phpunit-ga
|
docker run -it --rm -v${CURDIR}:/github/workspace phpdoc/phpunit-ga
|
||||||
docker run -it --rm -v${CURDIR}:/data -w /data php:7.2 -f ./tests/coverage-checker.php 89
|
docker run -it --rm -v${CURDIR}:/data -w /data php:7.2 -f ./tests/coverage-checker.php 90
|
||||||
|
|
||||||
.PHONY: pre-commit-test
|
.PHONY: pre-commit-test
|
||||||
pre-commit-test: test phpcs phpstan psalm
|
pre-commit-test: test phpcs phpstan psalm
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ final class Example implements Tag, Factory\StaticMethod
|
|||||||
public function __construct(string $filePath, bool $isURI, int $startingLine, int $lineCount, ?string $content)
|
public function __construct(string $filePath, bool $isURI, int $startingLine, int $lineCount, ?string $content)
|
||||||
{
|
{
|
||||||
Assert::notEmpty($filePath);
|
Assert::notEmpty($filePath);
|
||||||
Assert::greaterThanEq($startingLine, 0);
|
Assert::greaterThanEq($startingLine, 1);
|
||||||
Assert::greaterThanEq($lineCount, 0);
|
Assert::greaterThanEq($lineCount, 0);
|
||||||
|
|
||||||
$this->filePath = $filePath;
|
$this->filePath = $filePath;
|
||||||
@@ -63,7 +63,7 @@ final class Example implements Tag, Factory\StaticMethod
|
|||||||
|
|
||||||
public function getContent() : string
|
public function getContent() : string
|
||||||
{
|
{
|
||||||
if ($this->content === null) {
|
if ($this->content === null || $this->content === '') {
|
||||||
$filePath = '"' . $this->filePath . '"';
|
$filePath = '"' . $this->filePath . '"';
|
||||||
if ($this->isURI) {
|
if ($this->isURI) {
|
||||||
$filePath = $this->isUriRelative($this->filePath)
|
$filePath = $this->isUriRelative($this->filePath)
|
||||||
@@ -107,7 +107,7 @@ final class Example implements Tag, Factory\StaticMethod
|
|||||||
// Starting line / Number of lines / Description
|
// Starting line / Number of lines / Description
|
||||||
if (preg_match('/^([1-9]\d*)(?:\s+((?1))\s*)?(.*)$/sux', $matches[3], $contentMatches)) {
|
if (preg_match('/^([1-9]\d*)(?:\s+((?1))\s*)?(.*)$/sux', $matches[3], $contentMatches)) {
|
||||||
$startingLine = (int) $contentMatches[1];
|
$startingLine = (int) $contentMatches[1];
|
||||||
if (isset($contentMatches[2]) && $contentMatches[2] !== '') {
|
if (isset($contentMatches[2])) {
|
||||||
$lineCount = (int) $contentMatches[2];
|
$lineCount = (int) $contentMatches[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,14 +133,40 @@ class AuthorTest extends TestCase
|
|||||||
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Author::<public>
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Author::<public>
|
||||||
*
|
*
|
||||||
* @covers ::create
|
* @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($output, (string) $fixture);
|
||||||
$this->assertSame('Mike van Riel', $fixture->getAuthorName());
|
$this->assertSame($name, $fixture->getAuthorName());
|
||||||
$this->assertSame('[email protected]', $fixture->getEmail());
|
$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,25 +4,18 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace DocBlock\Tags;
|
namespace DocBlock\Tags;
|
||||||
|
|
||||||
use Mockery as m;
|
use InvalidArgumentException;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tags\Example;
|
use phpDocumentor\Reflection\DocBlock\Tags\Example;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\Example
|
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\Example
|
||||||
|
* @covers ::<private>
|
||||||
*/
|
*/
|
||||||
class ExampleTest extends TestCase
|
class ExampleTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Call Mockery::close after each test.
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
||||||
*/
|
|
||||||
public function tearDown() : void
|
|
||||||
{
|
|
||||||
m::close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
|
||||||
*
|
*
|
||||||
* @covers ::create
|
* @covers ::create
|
||||||
* @covers ::__construct
|
* @covers ::__construct
|
||||||
@@ -37,7 +30,7 @@ class ExampleTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
||||||
*
|
*
|
||||||
* @covers ::create
|
* @covers ::create
|
||||||
* @covers ::__construct
|
* @covers ::__construct
|
||||||
@@ -52,7 +45,7 @@ class ExampleTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
||||||
*
|
*
|
||||||
* @covers ::create
|
* @covers ::create
|
||||||
* @covers ::__construct
|
* @covers ::__construct
|
||||||
@@ -67,7 +60,7 @@ class ExampleTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
||||||
*
|
*
|
||||||
* @covers ::create
|
* @covers ::create
|
||||||
* @covers ::__construct
|
* @covers ::__construct
|
||||||
@@ -84,7 +77,7 @@ class ExampleTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
||||||
*
|
*
|
||||||
* @covers ::create
|
* @covers ::create
|
||||||
* @covers ::__construct
|
* @covers ::__construct
|
||||||
@@ -101,21 +94,149 @@ class ExampleTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
|
||||||
*
|
*
|
||||||
|
* @dataProvider tagContentProvider
|
||||||
* @covers ::create
|
* @covers ::create
|
||||||
* @covers ::__construct
|
* @covers ::__construct
|
||||||
* @covers ::getFilePath
|
* @covers ::getFilePath
|
||||||
* @covers ::getStartingLine
|
* @covers ::getStartingLine
|
||||||
* @covers ::getLineCount
|
* @covers ::getLineCount
|
||||||
* @covers ::getDescription
|
* @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');
|
return [
|
||||||
$this->assertEquals('example1.php', $tag->getFilePath());
|
[
|
||||||
$this->assertEquals(10, $tag->getStartingLine());
|
'"example1.php" 10 5 test text ',
|
||||||
$this->assertEquals(5, $tag->getLineCount());
|
'example1.php',
|
||||||
$this->assertEquals('test text', $tag->getDescription());
|
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',
|
||||||
|
],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user