-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestCase.php
More file actions
72 lines (59 loc) · 2.46 KB
/
Copy pathTestCase.php
File metadata and controls
72 lines (59 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
declare(strict_types=1);
namespace TypeLang\PhpDoc\Tests;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase as BaseTestCase;
use TypeLang\Parser\TypeParser;
use TypeLang\PhpDoc\DocBlock\Combinator\DescriptionCombinator;
use TypeLang\PhpDoc\DocBlock\Combinator\ReferenceCombinator;
use TypeLang\PhpDoc\DocBlock\Combinator\TypeCombinator;
use TypeLang\PhpDoc\DocBlock\Combinator\UriCombinator;
use TypeLang\PhpDoc\DocBlock\Combinator\VariableCombinator;
use TypeLang\PhpDoc\Parser\Description\BalancedBraceAwareParser;
use TypeLang\PhpDoc\Parser\Description\DescriptionParserInterface;
use TypeLang\PhpDoc\Parser\Grammar\Cursor;
use TypeLang\PhpDoc\Parser\Tag\StringTagParser;
use TypeLang\PhpDoc\Parser\TagFactory;
use TypeLang\PhpDoc\Parser\TagRegistryBuilder;
use TypeLang\PhpDoc\TagFactoryInterface;
#[Group('type-lang/phpdoc')]
abstract class TestCase extends BaseTestCase
{
private static ?TagFactoryInterface $cachedTagFactory = null;
private static ?DescriptionParserInterface $cachedDescriptionParser = null;
protected static function createTagFactory(): TagFactoryInterface
{
return self::$cachedTagFactory ??= self::buildTagFactory();
}
private static function buildTagFactory(): TagFactoryInterface
{
$typeParser = new TypeParser();
$baseRules = [
UriCombinator::NAME => new UriCombinator(),
ReferenceCombinator::NAME => new ReferenceCombinator(),
TypeCombinator::NAME => new TypeCombinator(typeParser: $typeParser),
VariableCombinator::NAME => new VariableCombinator(),
];
$tagFactory = null;
$description = null;
$baseRules[DescriptionCombinator::NAME] = static function (Cursor $cursor) use (
&$tagFactory,
&$description,
): mixed {
$description ??= new DescriptionCombinator(
new BalancedBraceAwareParser(new StringTagParser($tagFactory)),
);
return $description($cursor);
};
return $tagFactory = new TagFactory((new TagRegistryBuilder())->build(), $baseRules);
}
protected static function createDescriptionParser(): DescriptionParserInterface
{
if (self::$cachedDescriptionParser === null) {
self::$cachedDescriptionParser = new BalancedBraceAwareParser(
new StringTagParser(self::createTagFactory()),
);
}
return self::$cachedDescriptionParser;
}
}