9
9
10
10
class InterfaceTest extends \PHPUnit \Framework \TestCase
11
11
{
12
- /** @var Interface_ */
13
- protected $ builder ;
14
-
15
- protected function setUp () {
16
- $ this ->builder = new Interface_ ('Contract ' );
12
+ protected function createInterfaceBuilder () {
13
+ return new Interface_ ('Contract ' );
17
14
}
18
15
19
16
private function dump ($ node ) {
@@ -22,13 +19,14 @@ private function dump($node) {
22
19
}
23
20
24
21
public function testEmpty () {
25
- $ contract = $ this ->builder ->getNode ();
22
+ $ contract = $ this ->createInterfaceBuilder () ->getNode ();
26
23
$ this ->assertInstanceOf (Stmt \Interface_::class, $ contract );
27
24
$ this ->assertEquals (new Node \Identifier ('Contract ' ), $ contract ->name );
28
25
}
29
26
30
27
public function testExtending () {
31
- $ contract = $ this ->builder ->extend ('Space\Root1 ' , 'Root2 ' )->getNode ();
28
+ $ contract = $ this ->createInterfaceBuilder ()
29
+ ->extend ('Space\Root1 ' , 'Root2 ' )->getNode ();
32
30
$ this ->assertEquals (
33
31
new Stmt \Interface_ ('Contract ' , [
34
32
'extends ' => [
@@ -41,15 +39,15 @@ public function testExtending() {
41
39
42
40
public function testAddMethod () {
43
41
$ method = new Stmt \ClassMethod ('doSomething ' );
44
- $ contract = $ this ->builder ->addStmt ($ method )->getNode ();
42
+ $ contract = $ this ->createInterfaceBuilder () ->addStmt ($ method )->getNode ();
45
43
$ this ->assertSame ([$ method ], $ contract ->stmts );
46
44
}
47
45
48
46
public function testAddConst () {
49
47
$ const = new Stmt \ClassConst ([
50
48
new Node \Const_ ('SPEED_OF_LIGHT ' , new DNumber (299792458.0 ))
51
49
]);
52
- $ contract = $ this ->builder ->addStmt ($ const )->getNode ();
50
+ $ contract = $ this ->createInterfaceBuilder () ->addStmt ($ const )->getNode ();
53
51
$ this ->assertSame (299792458.0 , $ contract ->stmts [0 ]->consts [0 ]->value ->value );
54
52
}
55
53
@@ -58,7 +56,7 @@ public function testOrder() {
58
56
new Node \Const_ ('SPEED_OF_LIGHT ' , new DNumber (299792458 ))
59
57
]);
60
58
$ method = new Stmt \ClassMethod ('doSomething ' );
61
- $ contract = $ this ->builder
59
+ $ contract = $ this ->createInterfaceBuilder ()
62
60
->addStmt ($ method )
63
61
->addStmt ($ const )
64
62
->getNode ()
@@ -69,7 +67,7 @@ public function testOrder() {
69
67
}
70
68
71
69
public function testDocComment () {
72
- $ node = $ this ->builder
70
+ $ node = $ this ->createInterfaceBuilder ()
73
71
->setDocComment ('/** Test */ ' )
74
72
->getNode ();
75
73
@@ -81,15 +79,15 @@ public function testDocComment() {
81
79
public function testInvalidStmtError () {
82
80
$ this ->expectException (\LogicException::class);
83
81
$ this ->expectExceptionMessage ('Unexpected node of type "Stmt_PropertyProperty" ' );
84
- $ this ->builder ->addStmt (new Stmt \PropertyProperty ('invalid ' ));
82
+ $ this ->createInterfaceBuilder () ->addStmt (new Stmt \PropertyProperty ('invalid ' ));
85
83
}
86
84
87
85
public function testFullFunctional () {
88
86
$ const = new Stmt \ClassConst ([
89
87
new Node \Const_ ('SPEED_OF_LIGHT ' , new DNumber (299792458 ))
90
88
]);
91
89
$ method = new Stmt \ClassMethod ('doSomething ' );
92
- $ contract = $ this ->builder
90
+ $ contract = $ this ->createInterfaceBuilder ()
93
91
->addStmt ($ method )
94
92
->addStmt ($ const )
95
93
->getNode ()
0 commit comments