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-2017 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\Gherkin\Node\PyStringNode; |
17
|
|
|
use phpDocumentor\Reflection\DocBlock\Type\Collection; |
18
|
|
|
use PHPUnit\Framework\Assert; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* This class contains the context methods for tests of the uses tag. |
22
|
|
|
*/ |
23
|
|
|
final class UsesTagContext extends BaseContext implements Context |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @param string $classFqsen |
27
|
|
|
* @param $reference |
28
|
|
|
* @throws \Exception |
29
|
|
|
* @Then class ":classFqsen" has a tag uses referencing url ":reference" |
30
|
|
|
*/ |
31
|
|
|
public function classHasTagUsesReferencingUrl($classFqsen, $reference) |
32
|
|
|
{ |
33
|
|
|
$class = $this->findClassByFqsen($classFqsen); |
34
|
|
|
$usesTags = $class->getTags()->get('uses', new Collection()); |
35
|
|
|
/** @var UsesTag $tag */ |
36
|
|
|
foreach ($usesTags as $tag) { |
37
|
|
|
if ($tag->getReference() === $reference) { |
38
|
|
|
return; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
throw new \Exception(sprintf('Missing uses tag with reference "%s"', $reference)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $classFqsen |
47
|
|
|
* @param $element |
48
|
|
|
* @param $reference |
49
|
|
|
* @Then class ":classFqsen" has :number tag/tags uses referencing :element descriptor ":reference" |
50
|
|
|
*/ |
51
|
|
|
public function classHasTagUsesReferencing($classFqsen, $number, $element, $reference) |
52
|
|
|
{ |
53
|
|
|
$this->classHasTagUsesReferencingWithDescription($classFqsen, $number, $element, $reference, new PyStringNode([],0)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $classFqsen |
58
|
|
|
* @param $element |
59
|
|
|
* @param $reference |
60
|
|
|
* @param $description |
61
|
|
|
* @throws \Exception |
62
|
|
|
* @Then class ":classFqsen" has :number tag/tags uses referencing :element descriptor ":reference" with description: |
63
|
|
|
*/ |
64
|
|
|
public function classHasTagUsesReferencingWithDescription($classFqsen, $number, $element, $reference, PyStringNode $description) |
65
|
|
|
{ |
66
|
|
|
$count = 0; |
67
|
|
|
$class = $this->findClassByFqsen($classFqsen); |
68
|
|
|
$usesTags = $class->getTags()->get('uses', new Collection()); |
69
|
|
|
$element = '\\phpDocumentor\\Descriptor\\' .ucfirst($element) . 'Descriptor'; |
70
|
|
|
/** @var UsesTag $tag */ |
71
|
|
|
foreach ($usesTags as $tag) { |
72
|
|
|
$r = $tag->getReference(); |
73
|
|
|
if ($r instanceof $element |
74
|
|
|
&& $r->getFullyQualifiedStructuralElementName() === $reference |
75
|
|
|
&& $tag->getDescription() === $description->getRaw() |
76
|
|
|
) { |
77
|
|
|
$count++; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
Assert::assertEquals($number, $count, sprintf('Missing uses tag with reference "%s"', $reference)); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|