@@ -228,6 +228,74 @@ public function test() : void
228228 $ this ->assertSame ($ expected , $ this ->printer ->prettyPrintFile ($ nodeTraverser ->traverse ($ this ->parser ->parse ('' ))));
229229 }
230230
231+ /**
232+ * @test
233+ */
234+ public function it_supports_adding_of_class_constants_before_methods_with_doc_blocks (): void
235+ {
236+ $ code = <<<'EOF'
237+ <?php
238+
239+ declare (strict_types=1);
240+ namespace My\Awesome\Service;
241+
242+ final class TestClass
243+ {
244+ /**
245+ * Define aggregate names using constants
246+ *
247+ * @example
248+ *
249+ * const USER = 'User';
250+ */
251+
252+
253+ /**
254+ * @param EventEngine $eventEngine
255+ */
256+ public static function describe(EventEngine $eventEngine): void
257+ {
258+ }
259+ }
260+ EOF;
261+
262+ $ ast = $ this ->parser ->parse ($ code );
263+
264+ $ classFactory = ClassBuilder::fromScratch ('TestClass ' , 'My\Awesome\Service ' );
265+ $ classFactory ->addConstant (ClassConstBuilder::fromScratch ('FIRST ' , 1 ));
266+ $ classFactory ->addConstant (ClassConstBuilder::fromScratch ('PUB ' , 'public ' ));
267+
268+ $ expected = <<<'EOF'
269+ <?php
270+
271+ declare (strict_types=1);
272+ namespace My\Awesome\Service;
273+
274+ final class TestClass
275+ {
276+ public const FIRST = 1;
277+ public const PUB = 'public';
278+ /**
279+ * Define aggregate names using constants
280+ *
281+ * @example
282+ *
283+ * const USER = 'User';
284+ */
285+ /**
286+ * @param EventEngine $eventEngine
287+ */
288+ public static function describe(EventEngine $eventEngine) : void
289+ {
290+ }
291+ }
292+ EOF;
293+ $ nodeTraverser = new NodeTraverser ();
294+ $ classFactory ->injectVisitors ($ nodeTraverser , $ this ->parser );
295+
296+ $ this ->assertSame ($ expected , $ this ->printer ->prettyPrintFile ($ nodeTraverser ->traverse ($ ast )));
297+ }
298+
231299 /**
232300 * @test
233301 */
0 commit comments