-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDeclarationTest.php
More file actions
126 lines (106 loc) · 3.59 KB
/
Copy pathDeclarationTest.php
File metadata and controls
126 lines (106 loc) · 3.59 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
declare(strict_types=1);
namespace Component;
use Dot\Maker\Component\Declaration;
use Dot\Maker\Component\Parameter;
use PHPUnit\Framework\TestCase;
class DeclarationTest extends TestCase
{
private string $declarationName = 'getParam';
public function testWillInstantiate(): void
{
$declaration = new Declaration($this->declarationName);
$this->assertContainsOnlyInstancesOf(Declaration::class, [$declaration]);
$this->assertSame($this->declarationName, $declaration->name);
}
public function testWillAddParameter(): void
{
$declaration = new Declaration($this->declarationName);
$this->assertCount(0, $declaration->getParameters());
$declaration->addParameter(
new Parameter('param', 'string')
);
$this->assertCount(1, $declaration->getParameters());
}
public function testWillSetComment(): void
{
$comment = <<<COMM
/**
* This is a comment
*/
COMM;
$declaration = new Declaration($this->declarationName);
$this->assertSame('', $declaration->getComment());
$declaration->setComment($comment);
$this->assertSame($comment, $declaration->getComment());
}
public function testWillSetNullable(): void
{
$declaration = new Declaration($this->declarationName);
$this->assertFalse($declaration->isNullable());
$declaration->setNullable(true);
$this->assertTrue($declaration->isNullable());
}
public function testWillSetReturnType(): void
{
$declaration = new Declaration($this->declarationName);
$this->assertSame('void', $declaration->getReturnType());
$declaration->setReturnType('self');
$this->assertSame('self', $declaration->getReturnType());
}
public function testWillRenderParameters(): void
{
$declaration = new Declaration($this->declarationName);
$this->assertSame('', $declaration->renderParameters());
$declaration->addParameter(
new Parameter('param', 'string')
);
$this->assertSame(' string $param,', $declaration->renderParameters());
$declaration->addParameter(
new Parameter('other', 'string')
);
$this->assertSame(<<<BODY
string \$param,
string \$other,
BODY, $declaration->renderParameters());
}
public function testWillRenderSignature(): void
{
$declaration = new Declaration($this->declarationName);
$this->assertSame(': void', $declaration->renderSignature());
$declaration->setReturnType('');
$this->assertSame('', $declaration->renderSignature());
$declaration->setReturnType('self');
$this->assertSame(': self', $declaration->renderSignature());
$declaration->setReturnType('string');
$declaration->setNullable(true);
$this->assertSame(': ?string', $declaration->renderSignature());
}
public function testWillRender(): void
{
$comment = <<<COMM
/**
* @param string \$param
*/
COMM;
$declaration = (new Declaration($this->declarationName))
->setComment($comment)
->setNullable(true)
->setReturnType('self')
->addParameter(
new Parameter('param', 'string')
);
$this->assertSame($this->dataProviderRenderedDeclaration(), (string) $declaration);
}
private function dataProviderRenderedDeclaration(): string
{
return <<<BODY
/**
* @param string \$param
*/
public function getParam(
string \$param,
): ?self;
BODY;
}
}