Improve test coverage

This commit is contained in:
Jaapio
2020-09-02 22:46:14 +02:00
parent 13d9a6bb0b
commit 08c0b366d7
4 changed files with 177 additions and 30 deletions
+31 -5
View File
@@ -133,14 +133,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',
'',
],
];
}
/**
+142 -21
View File
@@ -4,25 +4,18 @@ 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
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
*
* @covers ::create
* @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 ::__construct
@@ -52,7 +45,7 @@ class ExampleTest extends TestCase
}
/**
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
*
* @covers ::create
* @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 ::__construct
@@ -84,7 +77,7 @@ class ExampleTest extends TestCase
}
/**
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
*
* @covers ::create
* @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 ::__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',
],
];
}
}