File tree Expand file tree Collapse file tree
tests/Unit/Utils/ReflectionApi Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,24 +45,24 @@ public function addArgument(RuntimeArgument $argument): self
4545 return $ this ;
4646 }
4747
48- public function setBody (string ...$ expression ): self
48+ public function setBody (string ...$ lines ): self
4949 {
5050 if ($ this ->abstract ) {
5151 throw ReflectionApiException::forAbstractMethodWithBody ($ this ->name );
5252 }
5353
54- $ this ->body = $ expression ;
54+ $ this ->body = $ lines ;
5555
5656 return $ this ;
5757 }
5858
59- public function addExpression (string $ expression ): self
59+ public function addLine (string $ line ): self
6060 {
6161 if ($ this ->abstract ) {
6262 throw ReflectionApiException::forAbstractMethodWithBody ($ this ->name );
6363 }
6464
65- $ this ->body [] = $ expression ;
65+ $ this ->body [] = $ line ;
6666
6767 return $ this ;
6868 }
@@ -106,7 +106,7 @@ public function generateCode(): string
106106 $ code .= "\n{ " ;
107107
108108 if ($ this ->body ) {
109- $ code .= "\n\t" . implode ("; \n\t" , $ this ->body ) . ' ; ' ;
109+ $ code .= "\n\t" . implode ("\n\t" , $ this ->body );
110110 }
111111
112112 $ code .= "\n} " ;
Original file line number Diff line number Diff line change @@ -45,8 +45,8 @@ public function testSetBody(): void
4545 {
4646 $ method = new RuntimeMethod ('doSomething ' );
4747 $ method ->setBody (
48- '$result = $a + $b ' ,
49- 'return $result '
48+ '$result = $a + $b; ' ,
49+ 'return $result; '
5050 );
5151
5252 self ::assertSame (
@@ -72,6 +72,11 @@ public function testCreatePrivateMethod(): void
7272
7373 public function testAddExpression (): void
7474 {
75+ $ method = new RuntimeMethod ('doSomething ' );
76+ $ method ->addLine ('if ($something) { ' );
77+ $ method ->addLine ("\techo 'test'; " );
78+ $ method ->addLine ('} ' );
7579
80+ self ::assertSame ("public function doSomething() \n{ \n\tif ( \$something) { \n\t\techo 'test'; \n\t} \n} " , $ method ->generateCode ());
7681 }
7782}
You can’t perform that action at this time.
0 commit comments