@@ -16,7 +16,7 @@ class SettingsCastFactoryTest extends TestCase
16
16
/** @test */
17
17
public function it_will_not_resolve_a_cast_for_built_in_types ()
18
18
{
19
- $ fake = new class {
19
+ $ fake = new class () {
20
20
public int $ integer ;
21
21
};
22
22
@@ -30,7 +30,7 @@ public function it_will_not_resolve_a_cast_for_built_in_types()
30
30
/** @test */
31
31
public function it_can_resolve_a_global_cast ()
32
32
{
33
- $ fake = new class {
33
+ $ fake = new class () {
34
34
public DateTime $ datetime ;
35
35
};
36
36
@@ -44,7 +44,7 @@ public function it_can_resolve_a_global_cast()
44
44
/** @test */
45
45
public function it_can_resolve_a_global_cast_as_docblock ()
46
46
{
47
- $ fake = new class {
47
+ $ fake = new class () {
48
48
/** @var DateTime */
49
49
public $ datetime ;
50
50
};
@@ -59,7 +59,7 @@ public function it_can_resolve_a_global_cast_as_docblock()
59
59
/** @test */
60
60
public function it_can_have_no_type_and_no_cast ()
61
61
{
62
- $ fake = new class {
62
+ $ fake = new class () {
63
63
public $ noType ;
64
64
};
65
65
@@ -73,7 +73,7 @@ public function it_can_have_no_type_and_no_cast()
73
73
/** @test */
74
74
public function it_can_have_a_global_cast_with_an_array ()
75
75
{
76
- $ fake = new class {
76
+ $ fake = new class () {
77
77
/** @var \Spatie\LaravelSettings\Tests\TestClasses\DummyDto[] */
78
78
public array $ dto_array ;
79
79
};
@@ -88,7 +88,7 @@ public function it_can_have_a_global_cast_with_an_array()
88
88
/** @test */
89
89
public function it_can_have_a_global_cast_with_an_array_without_array_type ()
90
90
{
91
- $ fake = new class {
91
+ $ fake = new class () {
92
92
/** @var \Spatie\LaravelSettings\Tests\TestClasses\DummyDto[] */
93
93
public $ dto_array ;
94
94
};
@@ -103,7 +103,7 @@ public function it_can_have_a_global_cast_with_an_array_without_array_type()
103
103
/** @test */
104
104
public function it_can_have_a_plain_array_without_cast ()
105
105
{
106
- $ fake = new class {
106
+ $ fake = new class () {
107
107
public array $ array ;
108
108
};
109
109
@@ -117,7 +117,7 @@ public function it_can_have_a_plain_array_without_cast()
117
117
/** @test */
118
118
public function it_can_have_a_nullable_cast ()
119
119
{
120
- $ fake = new class {
120
+ $ fake = new class () {
121
121
public ?DateTime $ array ;
122
122
};
123
123
@@ -131,7 +131,7 @@ public function it_can_have_a_nullable_cast()
131
131
/** @test */
132
132
public function it_can_have_a_nullable_docblock_cast ()
133
133
{
134
- $ fake = new class {
134
+ $ fake = new class () {
135
135
/** @var ?\DateTime */
136
136
public $ array ;
137
137
};
@@ -148,7 +148,7 @@ public function it_can_create_a_local_cast_without_arguments()
148
148
{
149
149
$ this ->withoutGlobalCasts ();
150
150
151
- $ fake = new class {
151
+ $ fake = new class () {
152
152
public DateTime $ datetime ;
153
153
};
154
154
@@ -164,7 +164,7 @@ public function it_can_create_a_local_cast_without_arguments()
164
164
/** @test */
165
165
public function it_can_create_a_local_cast_with_class_identifier_and_arguments ()
166
166
{
167
- $ fake = new class {
167
+ $ fake = new class () {
168
168
public $ dto ;
169
169
};
170
170
@@ -180,7 +180,7 @@ public function it_can_create_a_local_cast_with_class_identifier_and_arguments()
180
180
/** @test */
181
181
public function it_can_create_a_local_cast_with_an_already_constructed_cast ()
182
182
{
183
- $ fake = new class {
183
+ $ fake = new class () {
184
184
public DummyDto $ dto ;
185
185
};
186
186
@@ -193,6 +193,29 @@ public function it_can_create_a_local_cast_with_an_already_constructed_cast()
193
193
$ this ->assertEquals (new DtoCast (DummyDto::class), $ cast );
194
194
}
195
195
196
+ /** @test */
197
+ public function it_will_not_resolve_a_cast_for_a_primitive_type ()
198
+ {
199
+ $ fake = new class () {
200
+ /** @var int */
201
+ public $ int ;
202
+
203
+ /** @var ?int */
204
+ public $ a_nullable_int ;
205
+
206
+ /** @var int|null */
207
+ public $ another_nullable_int ;
208
+
209
+ /** @var int[]|null */
210
+ public $ an_array_of_ints_or_null ;
211
+ };
212
+
213
+ $ this ->assertNull (SettingsCastFactory::resolve (new ReflectionProperty ($ fake , 'int ' ), []));
214
+ $ this ->assertNull (SettingsCastFactory::resolve (new ReflectionProperty ($ fake , 'a_nullable_int ' ), []));
215
+ $ this ->assertNull (SettingsCastFactory::resolve (new ReflectionProperty ($ fake , 'another_nullable_int ' ), []));
216
+ $ this ->assertNull (SettingsCastFactory::resolve (new ReflectionProperty ($ fake , 'an_array_of_ints_or_null ' ), []));
217
+ }
218
+
196
219
private function withoutGlobalCasts ()
197
220
{
198
221
config ()->set ('settings.global_casts ' , []);
0 commit comments