-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTypeGeneratorTest.php
More file actions
92 lines (76 loc) · 2.31 KB
/
Copy pathTypeGeneratorTest.php
File metadata and controls
92 lines (76 loc) · 2.31 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* @see https://github.com/open-code-modeling/php-code-ast for the canonical source repository
* @copyright https://github.com/open-code-modeling/php-code-ast/blob/master/COPYRIGHT.md
* @license https://github.com/open-code-modeling/php-code-ast/blob/master/LICENSE.md MIT License
*/
declare(strict_types=1);
namespace OpenCodeModelingTest\CodeAst\Code;
use Generator;
use OpenCodeModeling\CodeAst\Code\TypeGenerator;
use PhpParser\Parser;
use PhpParser\ParserFactory;
use PhpParser\PrettyPrinter\Standard;
use PHPUnit\Framework\TestCase;
final class TypeGeneratorTest extends TestCase
{
/**
* @var Parser
*/
private $parser;
/**
* @var Standard
*/
private $printer;
public function setUp(): void
{
$this->parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
$this->printer = new Standard(['shortArraySyntax' => true]);
}
/**
* Values are: type, expected output
*
* @return Generator
*/
public function provideTypes(): Generator
{
yield 'string' => ['string', 'string'];
yield 'bool' => ['bool', 'bool'];
yield 'boolean' => ['bool', 'bool'];
yield 'int' => ['int', 'int'];
yield 'integer' => ['int', 'int'];
yield 'float' => ['float', 'float'];
yield '\\Awesome\\AcmeClass' => ['\\Awesome\\AcmeClass', '\\Awesome\\AcmeClass'];
yield '\\Foo' => ['\\Foo', '\\Foo'];
}
/**
* @test
* @dataProvider provideTypes
* @param string $type
* @param string $expectedOutput
*/
public function it_generates_type(string $type, string $expectedOutput): void
{
$type = TypeGenerator::fromTypeString($type);
$expectedOutput = <<<PHP
<?php
$expectedOutput
PHP;
$this->assertSame($expectedOutput, $this->printer->prettyPrintFile([$type->generate()]));
}
/**
* @test
* @dataProvider provideTypes
* @param string $type
* @param string $expectedOutput
*/
public function it_generates_nullable_type(string $type, string $expectedOutput): void
{
$type = TypeGenerator::fromTypeString('?'. $type);
$expectedOutput = <<<PHP
<?php
?$expectedOutput
PHP;
$this->assertSame($expectedOutput, $this->printer->prettyPrintFile([$type->generate()]));
}
}