1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2018 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Behat\Contexts\Ast; |
14
|
|
|
|
15
|
|
|
use Behat\Behat\Context\Context; |
16
|
|
|
use Behat\Behat\Tester\Exception\PendingException; |
17
|
|
|
use Behat\Gherkin\Node\PyStringNode; |
18
|
|
|
use Exception; |
19
|
|
|
use phpDocumentor\Descriptor\Tag\SeeDescriptor; |
20
|
|
|
use Webmozart\Assert\Assert; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* This class contains the context methods for tests of the see tag. |
24
|
|
|
*/ |
25
|
|
|
final class SeeTagContext extends BaseContext implements Context |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @param string $classFqsen |
29
|
|
|
* @throws Exception |
30
|
|
|
* @Then class ":classFqsen" has a tag see referencing url ":reference" |
31
|
|
|
*/ |
32
|
|
|
public function classHasTagSeeReferencingUrl($classFqsen, $reference) |
33
|
|
|
{ |
34
|
|
|
$class = $this->findClassByFqsen($classFqsen); |
35
|
|
|
$seeTags = $class->getTags()->get('see', []); |
36
|
|
|
$this->hasSeeTagReference($seeTags, $reference); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $classFqsen |
41
|
|
|
* @Then class ":classFqsen" has :number tag/tags see referencing :element descriptor ":reference" |
42
|
|
|
* @throws Exception |
43
|
|
|
*/ |
44
|
|
|
public function classHasTagSeeReferencing($classFqsen, $number, $element, $reference) |
45
|
|
|
{ |
46
|
|
|
$this->classHasTagSeeReferencingWithDescription($classFqsen, $number, $element, $reference, new PyStringNode([], 0)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $classFqsen |
51
|
|
|
* @throws Exception |
52
|
|
|
* @Then class ":classFqsen" has :number tag/tags see referencing :element descriptor ":reference" with description: |
53
|
|
|
*/ |
54
|
|
|
public function classHasTagSeeReferencingWithDescription($classFqsen, $number, $element, $reference, PyStringNode $description) |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$count = 0; |
57
|
|
|
$class = $this->findClassByFqsen($classFqsen); |
58
|
|
|
$seeTags = $class->getTags()->get('see', []); |
59
|
|
|
/** @var SeeDescriptor $tag */ |
60
|
|
|
foreach ($seeTags as $tag) { |
61
|
|
|
$r = (string) $tag->getReference(); |
62
|
|
|
if ($r === $reference |
63
|
|
|
&& ((string) $tag->getDescription()) === $description->getRaw() |
64
|
|
|
) { |
65
|
|
|
++$count; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
Assert::eq($number, $count, sprintf('Missing see tag with reference "%s"', $reference)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @then function ":function" has tag see referencing ":reference" |
74
|
|
|
* @throws Exception |
75
|
|
|
*/ |
76
|
|
|
public function functionHasSeeTagReferencing(string $function, string $reference) |
77
|
|
|
{ |
78
|
|
|
$functionDescriptor = $this->findFunctionByFqsen($function); |
79
|
|
|
$this->hasSeeTagReference($functionDescriptor->getTags()->get('see', []), $reference); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param $reference |
84
|
|
|
* @param SeeDescriptor[] $seeTags |
85
|
|
|
* @throws Exception |
86
|
|
|
*/ |
87
|
|
|
private function hasSeeTagReference($seeTags, $reference) : void |
88
|
|
|
{ |
89
|
|
|
/** @var SeeDescriptor $tag */ |
90
|
|
|
foreach ($seeTags as $tag) { |
91
|
|
|
if (((string) $tag->getReference()) === $reference) { |
92
|
|
|
return; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
throw new Exception(sprintf('Missing see tag with reference "%s"', $reference)); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.