File tree 4 files changed +41
-2
lines changed
App/DecorateController/Controller
4 files changed +41
-2
lines changed Original file line number Diff line number Diff line change 7
7
"minimum-stability" : " stable" ,
8
8
"require" : {
9
9
"php" : " >=8.2" ,
10
- "yceruto/decorator" : " 1.2.* " ,
10
+ "yceruto/decorator" : " ^1.3 " ,
11
11
"symfony/framework-bundle" : " ^6.4|^7.0"
12
12
},
13
13
"require-dev" : {
Original file line number Diff line number Diff line change 15
15
16
16
use Yceruto \Decorator \Attribute \DecoratorAttribute ;
17
17
18
- #[\Attribute(\Attribute::TARGET_METHOD )]
18
+ #[\Attribute(\Attribute::TARGET_CLASS | \Attribute:: TARGET_METHOD )]
19
19
final class Serialize extends DecoratorAttribute
20
20
{
21
21
public function __construct (
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ /*
6
+ * This file is part of Decorator Bundle package.
7
+ *
8
+ * (c) Yonel Ceruto <open@yceruto.dev>
9
+ *
10
+ * For the full copyright and license information, please view the LICENSE
11
+ * file that was distributed with this source code.
12
+ */
13
+
14
+ namespace Yceruto \DecoratorBundle \Tests \Integration \App \DecorateController \Controller ;
15
+
16
+ use Symfony \Component \Routing \Attribute \Route ;
17
+ use Yceruto \DecoratorBundle \Decorator \Serializer \Serialize ;
18
+
19
+ #[Serialize]
20
+ #[Route('/serialize-decorator/invokable ' )]
21
+ class InvokableControllerWithSerializeDecorator
22
+ {
23
+ public function __invoke (): array
24
+ {
25
+ return ['success ' => true ];
26
+ }
27
+ }
Original file line number Diff line number Diff line change @@ -39,6 +39,18 @@ public function testSerializerDecoratorDefaultOptions(): void
39
39
self ::assertSame ('{"success":true} ' , $ client ->getInternalResponse ()->getContent ());
40
40
}
41
41
42
+ public function testSerializerDecoratorInInvokable (): void
43
+ {
44
+ $ client = self ::createClient ();
45
+ $ client ->request ('GET ' , '/serialize-decorator/invokable ' );
46
+
47
+ self ::assertResponseIsSuccessful ();
48
+ self ::assertResponseFormatSame ('json ' );
49
+ self ::assertResponseStatusCodeSame (200 );
50
+ self ::assertResponseHeaderSame ('Content-Type ' , 'application/json ' );
51
+ self ::assertSame ('{"success":true} ' , $ client ->getInternalResponse ()->getContent ());
52
+ }
53
+
42
54
public function testSerializerDecoratorEmptyResult (): void
43
55
{
44
56
$ client = self ::createClient ();
You can’t perform that action at this time.
0 commit comments