10
10
use Cycle \ORM \Tests \Fixtures \Enum \CustomStringable ;
11
11
use Cycle \ORM \Tests \Fixtures \Enum \TypeIntEnum ;
12
12
use Cycle \ORM \Tests \Fixtures \Enum \TypeStringEnum ;
13
+ use Cycle \ORM \Tests \Fixtures \StaticCallableRule ;
13
14
use Cycle \ORM \Tests \Fixtures \Uuid ;
14
15
use Mockery as m ;
15
16
use PHPUnit \Framework \TestCase ;
@@ -29,6 +30,7 @@ public function testSetRules(): void
29
30
'slug ' => fn (string $ value ) => strtolower ($ value ),
30
31
'title ' => 'strtoupper ' ,
31
32
'test ' => [Uuid::class, 'create ' ],
33
+ 'callable ' => [StaticCallableRule::class, 'invoke ' , ['foo ' => 'bar ' ]],
32
34
'uuid ' => 'uuid ' ,
33
35
'settings ' => 'json ' ,
34
36
];
@@ -151,6 +153,21 @@ public function testCastCallableValue(): void
151
153
$ this ->assertSame ('71ceb213-ec3d-4ae5-911b-ba042abfb204 ' , $ result ['uuid ' ]->toString ());
152
154
}
153
155
156
+ public function testCastCallableWithArguments (): void
157
+ {
158
+ $ this ->typecast ->setRules (['callable ' => [StaticCallableRule::class, 'invoke ' , ['foo ' => 'bar ' ]]]);
159
+
160
+ $ result = $ this ->typecast ->cast (['callable ' => 'baz ' ]);
161
+
162
+ $ this ->assertIsArray ($ result ['callable ' ]);
163
+ $ this ->assertArrayHasKey ('value ' , $ result ['callable ' ]);
164
+ $ this ->assertArrayHasKey ('database ' , $ result ['callable ' ]);
165
+ $ this ->assertArrayHasKey ('arguments ' , $ result ['callable ' ]);
166
+ $ this ->assertSame ('baz ' , $ result ['callable ' ]['value ' ]);
167
+ $ this ->assertInstanceOf (DatabaseInterface::class, $ result ['callable ' ]['database ' ]);
168
+ $ this ->assertSame (['foo ' => 'bar ' ], $ result ['callable ' ]['arguments ' ]);
169
+ }
170
+
154
171
public function testCastJsonValue (): void
155
172
{
156
173
$ this ->typecast ->setRules (['foo ' => 'json ' , 'baz ' => 'json ' ]);
0 commit comments