From e31c62da4c904cbab2f885da915f7d65430dbc11 Mon Sep 17 00:00:00 2001 From: Lars Moelleken Date: Sat, 24 Oct 2020 02:34:44 +0200 Subject: [PATCH] "See" -> add more test + simplify the regex --- src/DocBlock/Tags/See.php | 2 +- tests/unit/DocBlock/Tags/SeeTest.php | 32 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/DocBlock/Tags/See.php b/src/DocBlock/Tags/See.php index 73311df..e211647 100644 --- a/src/DocBlock/Tags/See.php +++ b/src/DocBlock/Tags/See.php @@ -59,7 +59,7 @@ final class See extends BaseTag implements Factory\StaticMethod $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; // https://tools.ietf.org/html/rfc2396#section-3 - if (preg_match('/\w:\/\/\w/i', $parts[0])) { + if (preg_match('#\w://\w#', $parts[0])) { return new static(new Url($parts[0]), $description); } diff --git a/tests/unit/DocBlock/Tags/SeeTest.php b/tests/unit/DocBlock/Tags/SeeTest.php index dd7236d..58b7a50 100644 --- a/tests/unit/DocBlock/Tags/SeeTest.php +++ b/tests/unit/DocBlock/Tags/SeeTest.php @@ -16,7 +16,9 @@ namespace phpDocumentor\Reflection\DocBlock\Tags; use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\StandardTagFactory; use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen as FqsenRef; +use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen as TagsFqsen; use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url as UrlRef; use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\FqsenResolver; @@ -251,6 +253,36 @@ class SeeTest extends TestCase $this->assertSame($description, $fixture->getDescription()); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\See:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\FqsenResolver + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Url + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithoutUrl() : void + { + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = See::create( + 'Foo My Description ', + $fqsenResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('\Foo My Description ', (string) $fixture); + $this->assertInstanceOf(TagsFqsen::class, $fixture->getReference()); + $this->assertSame('\Foo', (string) $fixture->getReference()); + $this->assertSame('My Description ', $fixture->getDescription() . ''); + } + /** * @covers ::create */