-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathMethodGeneratorTest.php
103 lines (74 loc) · 2.95 KB
/
MethodGeneratorTest.php
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
<?php
namespace gossi\codegen\tests\generator;
use gossi\codegen\generator\ModelGenerator;
use gossi\codegen\model\PhpMethod;
use gossi\codegen\model\PhpParameter;
/**
* @group generator
*/
class MethodGeneratorTest extends \PHPUnit_Framework_TestCase {
public function testPublic() {
$expected = "public function foo() {\n}\n";
$method = PhpMethod::create('foo');
$generator = new ModelGenerator();
$code = $generator->generate($method);
$this->assertEquals($expected, $code);
}
public function testProtected() {
$expected = "protected function foo() {\n}\n";
$method = PhpMethod::create('foo')->setVisibility(PhpMethod::VISIBILITY_PROTECTED);
$generator = new ModelGenerator();
$code = $generator->generate($method);
$this->assertEquals($expected, $code);
}
public function testPrivate() {
$expected = "private function foo() {\n}\n";
$method = PhpMethod::create('foo')->setVisibility(PhpMethod::VISIBILITY_PRIVATE);
$generator = new ModelGenerator();
$code = $generator->generate($method);
$this->assertEquals($expected, $code);
}
public function testStatic() {
$expected = "public static function foo() {\n}\n";
$method = PhpMethod::create('foo')->setStatic(true);
$generator = new ModelGenerator();
$code = $generator->generate($method);
$this->assertEquals($expected, $code);
}
public function testAbstract() {
$expected = "abstract public function foo();\n";
$method = PhpMethod::create('foo')->setAbstract(true);
$generator = new ModelGenerator();
$code = $generator->generate($method);
$this->assertEquals($expected, $code);
}
public function testReferenceReturned() {
$expected = "public function & foo() {\n}\n";
$method = PhpMethod::create('foo')->setReferenceReturned(true);
$generator = new ModelGenerator();
$code = $generator->generate($method);
$this->assertEquals($expected, $code);
}
public function testParameters() {
$generator = new ModelGenerator();
$method = PhpMethod::create('foo')->addParameter(PhpParameter::create('bar'));
$this->assertEquals("public function foo(\$bar) {\n}\n", $generator->generate($method));
$method = PhpMethod::create('foo')
->addParameter(PhpParameter::create('bar'))
->addParameter(PhpParameter::create('baz'));
$this->assertEquals("public function foo(\$bar, \$baz) {\n}\n", $generator->generate($method));
}
public function testReturnType() {
$expected = "public function foo(): int {\n}\n";
$generator = new ModelGenerator(['generateReturnTypeHints' => true, 'generateDocblock' => false]);
$method = PhpMethod::create('foo')->setType('int');
$this->assertEquals($expected, $generator->generate($method));
}
public function testPsrCode() {
$expected = "public function foo()\n{\n}\n";
$method = PhpMethod::create('foo');
$generator = new ModelGenerator(['generatePsrCode' => true, 'generateDocblock' => false]);
$code = $generator->generate($method);
$this->assertEquals($expected, $code);
}
}