mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Add test for Author Tag
This commit is contained in:
committed by
Mike van Riel
parent
8798633221
commit
0d29e96332
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||||
|
|
||||||
use phpDocumentor\Reflection\DocBlock\Description;
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reflection class for an {@}author tag in a Docblock.
|
* Reflection class for an {@}author tag in a Docblock.
|
||||||
@@ -36,10 +36,9 @@ final class Author extends BaseTag
|
|||||||
*/
|
*/
|
||||||
public function __construct($authorName, $authorEmail)
|
public function __construct($authorName, $authorEmail)
|
||||||
{
|
{
|
||||||
if (!is_string($authorName)) {
|
Assert::string($authorName);
|
||||||
throw new \InvalidArgumentException('The author tag does not have a valid name');
|
Assert::string($authorEmail);
|
||||||
}
|
if ($authorEmail && !filter_var($authorEmail, FILTER_VALIDATE_EMAIL)) {
|
||||||
if (!is_string($authorEmail) || ($authorEmail && !filter_var($authorEmail, FILTER_VALIDATE_EMAIL))) {
|
|
||||||
throw new \InvalidArgumentException('The author tag does not have a valid e-mail address');
|
throw new \InvalidArgumentException('The author tag does not have a valid e-mail address');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,10 +77,16 @@ final class Author extends BaseTag
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* Attempts to create a new Author object based on †he tag body.
|
||||||
|
*
|
||||||
|
* @param string $body
|
||||||
|
*
|
||||||
|
* @return static
|
||||||
*/
|
*/
|
||||||
public static function create($body)
|
public static function create($body)
|
||||||
{
|
{
|
||||||
|
Assert::string($body);
|
||||||
|
|
||||||
$splitTagContent = preg_match('/^([^\<]*)(?:\<([^\>]*)\>)?$/u', $body, $matches);
|
$splitTagContent = preg_match('/^([^\<]*)(?:\<([^\>]*)\>)?$/u', $body, $matches);
|
||||||
if (!$splitTagContent) {
|
if (!$splitTagContent) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
<?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.
|
||||||
|
*
|
||||||
|
* @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 Mockery as m;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Description;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Tags\Other;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\Author
|
||||||
|
* @covers ::<private>
|
||||||
|
*/
|
||||||
|
class AuthorTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
* @covers ::getAuthorName
|
||||||
|
*/
|
||||||
|
public function testHasTheAuthorName()
|
||||||
|
{
|
||||||
|
$expected = 'Mike van Riel';
|
||||||
|
|
||||||
|
$fixture = new Author($expected, '[email protected]');
|
||||||
|
|
||||||
|
$this->assertSame($expected, $fixture->getAuthorName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
* @covers ::getAuthorName
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testInitializationFailsIfAuthorNameIsNotAString()
|
||||||
|
{
|
||||||
|
new Author([], '[email protected]');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
* @covers ::getEmail
|
||||||
|
*/
|
||||||
|
public function testHasTheAuthorMailAddress()
|
||||||
|
{
|
||||||
|
$expected = '[email protected]';
|
||||||
|
|
||||||
|
$fixture = new Author('Mike van Riel', $expected);
|
||||||
|
|
||||||
|
$this->assertSame($expected, $fixture->getEmail());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testInitializationFailsIfEmailIsNotAString()
|
||||||
|
{
|
||||||
|
new Author('Mike van Riel', []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public function testInitializationFailsIfEmailIsNotValid()
|
||||||
|
{
|
||||||
|
new Author('Mike van Riel', 'mike');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
* @covers ::__toString
|
||||||
|
*/
|
||||||
|
public function testStringRepresentationIsReturned()
|
||||||
|
{
|
||||||
|
$fixture = new Author('Mike van Riel', '[email protected]');
|
||||||
|
|
||||||
|
$this->assertSame('Mike van Riel<[email protected]>', (string)$fixture);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::create
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Author::<public>
|
||||||
|
*/
|
||||||
|
public function testFactoryMethod()
|
||||||
|
{
|
||||||
|
$fixture = Author::create('Mike van Riel <[email protected]>');
|
||||||
|
|
||||||
|
$this->assertSame('Mike van Riel<[email protected]>', (string)$fixture);
|
||||||
|
$this->assertSame('Mike van Riel', $fixture->getAuthorName());
|
||||||
|
$this->assertSame('[email protected]', $fixture->getEmail());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::create
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Author::<public>
|
||||||
|
*/
|
||||||
|
public function testFactoryMethodReturnsNullIfItCouldNotReadBody()
|
||||||
|
{
|
||||||
|
$this->assertNull(Author::create('dfgr<'));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user