@@ -177,6 +177,57 @@ final class TestClass
177177 $ this ->assertSame ($ expected , $ this ->printer ->prettyPrintFile ($ nodeTraverser ->traverse ($ this ->parser ->parse ('' ))));
178178 }
179179
180+ /**
181+ * @test
182+ */
183+ public function it_supports_adding_of_class_constants_before_property (): void
184+ {
185+ $ code = <<<'EOF'
186+ <?php
187+
188+ declare (strict_types=1);
189+ namespace My\Awesome\Service;
190+
191+ final class TestClass
192+ {
193+ use TestTrait;
194+ protected $property;
195+
196+ public function test(): void
197+ {
198+ }
199+ }
200+ EOF;
201+
202+ $ ast = $ this ->parser ->parse ($ code );
203+
204+ $ classFactory = ClassBuilder::fromNodes (...$ ast );
205+ $ classFactory ->addConstant (ClassConstBuilder::fromScratch ('FIRST ' , 1 ));
206+ $ classFactory ->addConstant (ClassConstBuilder::fromScratch ('PUB ' , 'public ' ));
207+
208+ $ expected = <<<'EOF'
209+ <?php
210+
211+ declare (strict_types=1);
212+ namespace My\Awesome\Service;
213+
214+ final class TestClass
215+ {
216+ use TestTrait;
217+ public const FIRST = 1;
218+ public const PUB = 'public';
219+ protected $property;
220+ public function test() : void
221+ {
222+ }
223+ }
224+ EOF;
225+ $ nodeTraverser = new NodeTraverser ();
226+ $ classFactory ->injectVisitors ($ nodeTraverser , $ this ->parser );
227+
228+ $ this ->assertSame ($ expected , $ this ->printer ->prettyPrintFile ($ nodeTraverser ->traverse ($ this ->parser ->parse ('' ))));
229+ }
230+
180231 /**
181232 * @test
182233 */
@@ -191,6 +242,10 @@ public function it_supports_adding_of_class_constants(): void
191242final class TestClass
192243{
193244 protected const PROT = 'protected';
245+
246+ public function test(): void
247+ {
248+ }
194249}
195250EOF;
196251
@@ -211,6 +266,9 @@ final class TestClass
211266 protected const PROT = 'protected';
212267 public const FIRST = 1;
213268 public const PUB = 'public';
269+ public function test() : void
270+ {
271+ }
214272}
215273EOF;
216274 $ nodeTraverser = new NodeTraverser ();
0 commit comments