Skip to content

Commit 7b7c22d

Browse files
committed
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
2 parents 3d8d7df + f607592 commit 7b7c22d

File tree

10 files changed

+290
-42
lines changed

10 files changed

+290
-42
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ psalm:
3030
.PHONY: test
3131
test:
3232
docker run -it --rm -v${CURDIR}:/github/workspace phpdoc/phpunit-ga
33-
docker run -it --rm -v${CURDIR}:/data -w /data php:7.2 -f ./tests/coverage-checker.php 89
33+
docker run -it --rm -v${CURDIR}:/data -w /data php:7.2 -f ./tests/coverage-checker.php 90
3434

3535
.PHONY: pre-commit-test
3636
pre-commit-test: test phpcs phpstan psalm

composer.lock

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DocBlock/Tags/Covers.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use phpDocumentor\Reflection\Types\Context as TypeContext;
2121
use phpDocumentor\Reflection\Utils;
2222
use Webmozart\Assert\Assert;
23+
use function array_key_exists;
24+
use function explode;
2325

2426
/**
2527
* Reflection class for a @covers tag in a Docblock.
@@ -54,11 +56,24 @@ public static function create(
5456
$parts = Utils::pregSplit('/\s+/Su', $body, 2);
5557

5658
return new static(
57-
$resolver->resolve($parts[0], $context),
59+
self::resolveFqsen($parts[0], $resolver, $context),
5860
$descriptionFactory->create($parts[1] ?? '', $context)
5961
);
6062
}
6163

64+
private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context) : Fqsen
65+
{
66+
Assert::notNull($fqsenResolver);
67+
$fqsenParts = explode('::', $parts);
68+
$resolved = $fqsenResolver->resolve($fqsenParts[0], $context);
69+
70+
if (!array_key_exists(1, $fqsenParts)) {
71+
return $resolved;
72+
}
73+
74+
return new Fqsen($resolved . '::' . $fqsenParts[1]);
75+
}
76+
6277
/**
6378
* Returns the structural element this tag refers to.
6479
*/

src/DocBlock/Tags/Example.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class Example implements Tag, Factory\StaticMethod
4848
public function __construct(string $filePath, bool $isURI, int $startingLine, int $lineCount, ?string $content)
4949
{
5050
Assert::notEmpty($filePath);
51-
Assert::greaterThanEq($startingLine, 0);
51+
Assert::greaterThanEq($startingLine, 1);
5252
Assert::greaterThanEq($lineCount, 0);
5353

5454
$this->filePath = $filePath;
@@ -63,7 +63,7 @@ public function __construct(string $filePath, bool $isURI, int $startingLine, in
6363

6464
public function getContent() : string
6565
{
66-
if ($this->content === null) {
66+
if ($this->content === null || $this->content === '') {
6767
$filePath = '"' . $this->filePath . '"';
6868
if ($this->isURI) {
6969
$filePath = $this->isUriRelative($this->filePath)
@@ -107,7 +107,7 @@ public static function create(string $body) : ?Tag
107107
// Starting line / Number of lines / Description
108108
if (preg_match('/^([1-9]\d*)(?:\s+((?1))\s*)?(.*)$/sux', $matches[3], $contentMatches)) {
109109
$startingLine = (int) $contentMatches[1];
110-
if (isset($contentMatches[2]) && $contentMatches[2] !== '') {
110+
if (isset($contentMatches[2])) {
111111
$lineCount = (int) $contentMatches[2];
112112
}
113113

src/DocBlock/Tags/See.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen as FqsenRef;
1919
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Reference;
2020
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url;
21+
use phpDocumentor\Reflection\Fqsen;
2122
use phpDocumentor\Reflection\FqsenResolver;
2223
use phpDocumentor\Reflection\Types\Context as TypeContext;
2324
use phpDocumentor\Reflection\Utils;
2425
use Webmozart\Assert\Assert;
26+
use function array_key_exists;
27+
use function explode;
2528
use function preg_match;
2629

2730
/**
@@ -50,7 +53,6 @@ public static function create(
5053
?DescriptionFactory $descriptionFactory = null,
5154
?TypeContext $context = null
5255
) : self {
53-
Assert::notNull($typeResolver);
5456
Assert::notNull($descriptionFactory);
5557

5658
$parts = Utils::pregSplit('/\s+/Su', $body, 2);
@@ -61,7 +63,20 @@ public static function create(
6163
return new static(new Url($parts[0]), $description);
6264
}
6365

64-
return new static(new FqsenRef($typeResolver->resolve($parts[0], $context)), $description);
66+
return new static(new FqsenRef(self::resolveFqsen($parts[0], $typeResolver, $context)), $description);
67+
}
68+
69+
private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context) : Fqsen
70+
{
71+
Assert::notNull($fqsenResolver);
72+
$fqsenParts = explode('::', $parts);
73+
$resolved = $fqsenResolver->resolve($fqsenParts[0], $context);
74+
75+
if (!array_key_exists(1, $fqsenParts)) {
76+
return $resolved;
77+
}
78+
79+
return new Fqsen($resolved . '::' . $fqsenParts[1]);
6580
}
6681

6782
/**

src/DocBlock/Tags/Uses.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use phpDocumentor\Reflection\Types\Context as TypeContext;
2121
use phpDocumentor\Reflection\Utils;
2222
use Webmozart\Assert\Assert;
23+
use function array_key_exists;
24+
use function explode;
2325

2426
/**
2527
* Reflection class for a {@}uses tag in a Docblock.
@@ -53,11 +55,24 @@ public static function create(
5355
$parts = Utils::pregSplit('/\s+/Su', $body, 2);
5456

5557
return new static(
56-
$resolver->resolve($parts[0], $context),
58+
self::resolveFqsen($parts[0], $resolver, $context),
5759
$descriptionFactory->create($parts[1] ?? '', $context)
5860
);
5961
}
6062

63+
private static function resolveFqsen(string $parts, ?FqsenResolver $fqsenResolver, ?TypeContext $context) : Fqsen
64+
{
65+
Assert::notNull($fqsenResolver);
66+
$fqsenParts = explode('::', $parts);
67+
$resolved = $fqsenResolver->resolve($fqsenParts[0], $context);
68+
69+
if (!array_key_exists(1, $fqsenParts)) {
70+
return $resolved;
71+
}
72+
73+
return new Fqsen($resolved . '::' . $fqsenParts[1]);
74+
}
75+
6176
/**
6277
* Returns the structural element this tag refers to.
6378
*/
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpDocumentor\Reflection;
6+
7+
use phpDocumentor\Reflection\DocBlock\Tags\See;
8+
use phpDocumentor\Reflection\Types\Context;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class DocblockSeeTagResolvingTest extends TestCase
12+
{
13+
public function testResolvesSeeFQSENOfInlineTags()
14+
{
15+
$context = new Context('\Project\Sub\Level', ['Issue2425B' => '\Project\Other\Level\Issue2425B', 'Aliased' => 'Project\Other\Level\Issue2425C']);
16+
$docblockString = <<<DOCBLOCK
17+
/**
18+
* Class summary.
19+
*
20+
* A description containing an inline {@see Issue2425B::bar()} tag
21+
* to a class inside of the project referenced via a use statement.
22+
*
23+
* And here is another inline {@see Aliased::bar()} tag to a class
24+
* aliased via a use statement.
25+
*/
26+
DOCBLOCK;
27+
28+
29+
30+
$factory = DocBlockFactory::createInstance();
31+
$docblock = $factory->create($docblockString, $context);
32+
33+
/** @var See $see1 */
34+
$see1 = $docblock->getDescription()->getTags()[0];
35+
36+
$this->assertSame('\Project\Other\Level\Issue2425B::bar()', (string)$see1->getReference());
37+
}
38+
}

tests/unit/DocBlock/Tags/AuthorTest.php

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,40 @@ public function testStringRepresentationWithEmtpyEmail() : void
150150
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Author::<public>
151151
*
152152
* @covers ::create
153+
* @dataProvider authorTagProvider
153154
*/
154-
public function testFactoryMethod() : void
155+
public function testFactoryMethod(string $input, string $output, string $name, string $email) : void
155156
{
156-
$fixture = Author::create('Mike van Riel <[email protected]>');
157+
$fixture = Author::create($input);
157158

158-
$this->assertSame('Mike van Riel <[email protected]>', (string) $fixture);
159-
$this->assertSame('Mike van Riel', $fixture->getAuthorName());
160-
$this->assertSame('[email protected]', $fixture->getEmail());
159+
$this->assertSame($output, (string) $fixture);
160+
$this->assertSame($name, $fixture->getAuthorName());
161+
$this->assertSame($email, $fixture->getEmail());
162+
}
163+
164+
/** @return mixed[][] */
165+
public function authorTagProvider() : array
166+
{
167+
return [
168+
[
169+
'Mike van Riel <[email protected]>',
170+
'Mike van Riel <[email protected]>',
171+
'Mike van Riel',
172+
173+
],
174+
[
175+
'Mike van Riel < [email protected] >',
176+
'Mike van Riel <[email protected]>',
177+
'Mike van Riel',
178+
179+
],
180+
[
181+
'Mike van Riel',
182+
'Mike van Riel',
183+
'Mike van Riel',
184+
'',
185+
],
186+
];
161187
}
162188

163189
/**

0 commit comments

Comments
 (0)