2
2
3
3
namespace SMS \FluidComponents \Tests \Unit \Utility ;
4
4
5
+ use SMS \FluidComponents \Interfaces \ConstructibleFromArray ;
5
6
use SMS \FluidComponents \Utility \ComponentArgumentConverter ;
6
- use SMS \FluidComponents \Tests \Helpers \ComponentArgumentConverter \DummyConversionInterface ;
7
+ use SMS \FluidComponents \Tests \Helpers \ComponentArgumentConverter \BaseObject ;
7
8
use SMS \FluidComponents \Tests \Helpers \ComponentArgumentConverter \DummyValue ;
9
+ use SMS \FluidComponents \Tests \Helpers \ComponentArgumentConverter \SpecificObject ;
10
+ use SMS \FluidComponents \Tests \Helpers \ComponentArgumentConverter \DummyConversionInterface ;
11
+ use SMS \FluidComponents \Tests \Helpers \ComponentArgumentConverter \BaseObjectConversionInterface ;
8
12
9
13
class ComponentArgumentConverterTest extends \TYPO3 \TestingFramework \Core \Unit \UnitTestCase
10
14
{
15
+ protected ComponentArgumentConverter $ converter ;
16
+
11
17
protected function setUp (): void
12
18
{
13
19
parent ::setUp ();
@@ -61,8 +67,9 @@ public function resolveTypeAliasCollection()
61
67
public function addRemoveConversionInterface ()
62
68
{
63
69
$ this ->assertEquals (
64
- false ,
65
- $ this ->converter ->canTypeBeConvertedToType ('string ' , DummyValue::class)
70
+ [],
71
+ $ this ->converter ->canTypeBeConvertedToType ('string ' , DummyValue::class),
72
+ 'before conversion interface registration '
66
73
);
67
74
68
75
$ this ->converter ->addConversionInterface (
@@ -72,15 +79,17 @@ public function addRemoveConversionInterface()
72
79
);
73
80
74
81
$ this ->assertEquals (
75
- true ,
76
- $ this ->converter ->canTypeBeConvertedToType ('string ' , DummyValue::class)
82
+ [DummyConversionInterface::class, 'fromString ' ],
83
+ $ this ->converter ->canTypeBeConvertedToType ('string ' , DummyValue::class),
84
+ 'after conversion interface registration '
77
85
);
78
86
79
87
$ this ->converter ->removeConversionInterface ('string ' );
80
88
81
89
$ this ->assertEquals (
82
- false ,
83
- $ this ->converter ->canTypeBeConvertedToType ('string ' , DummyValue::class)
90
+ [],
91
+ $ this ->converter ->canTypeBeConvertedToType ('string ' , DummyValue::class),
92
+ 'after conversion interface removal '
84
93
);
85
94
}
86
95
@@ -94,43 +103,58 @@ public function canTypeBeConvertedToType()
94
103
DummyConversionInterface::class,
95
104
'fromString '
96
105
);
106
+ $ this ->converter ->addConversionInterface (
107
+ BaseObject::class,
108
+ BaseObjectConversionInterface::class,
109
+ 'fromBaseObject '
110
+ );
97
111
98
112
$ this ->assertEquals (
99
- true ,
113
+ [DummyConversionInterface::class, ' fromString ' ] ,
100
114
$ this ->converter ->canTypeBeConvertedToType ('string ' , DummyValue::class)
101
115
);
102
116
$ this ->assertEquals (
103
- false ,
117
+ [] ,
104
118
$ this ->converter ->canTypeBeConvertedToType (DummyValue::class, 'string ' )
105
119
);
106
120
$ this ->assertEquals (
107
- false ,
121
+ [] ,
108
122
$ this ->converter ->canTypeBeConvertedToType ('array ' , DummyValue::class)
109
123
);
110
124
$ this ->assertEquals (
111
- false ,
125
+ [] ,
112
126
$ this ->converter ->canTypeBeConvertedToType (DummyValue::class, 'array ' )
113
127
);
114
128
115
129
// No conversion necessary
116
130
$ this ->assertEquals (
117
- false ,
131
+ [] ,
118
132
$ this ->converter ->canTypeBeConvertedToType ('string ' , 'string ' )
119
133
);
120
134
121
135
// Collections
122
136
$ this ->assertEquals (
123
- true ,
137
+ [ConstructibleFromArray::class, ' fromArray ' ] ,
124
138
$ this ->converter ->canTypeBeConvertedToType ('array ' , DummyValue::class . '[] ' )
125
139
);
126
140
$ this ->assertEquals (
127
- true ,
141
+ [ConstructibleFromArray::class, ' fromArray ' ] ,
128
142
$ this ->converter ->canTypeBeConvertedToType (\ArrayIterator::class, DummyValue::class . '[] ' )
129
143
);
130
144
$ this ->assertEquals (
131
- false ,
145
+ [] ,
132
146
$ this ->converter ->canTypeBeConvertedToType ('string ' , DummyValue::class . '[] ' )
133
147
);
148
+
149
+ // Class inheritance
150
+ $ this ->assertEquals (
151
+ [BaseObjectConversionInterface::class, 'fromBaseObject ' ],
152
+ $ this ->converter ->canTypeBeConvertedToType (BaseObject::class, DummyValue::class)
153
+ );
154
+ $ this ->assertEquals (
155
+ [BaseObjectConversionInterface::class, 'fromBaseObject ' ],
156
+ $ this ->converter ->canTypeBeConvertedToType (SpecificObject::class, DummyValue::class)
157
+ );
134
158
}
135
159
136
160
/**
@@ -146,13 +170,13 @@ public function canTypeBeConvertedToTypeCached()
146
170
147
171
// Uncached result
148
172
$ this ->assertEquals (
149
- true ,
173
+ [DummyConversionInterface::class, ' fromString ' ] ,
150
174
$ this ->converter ->canTypeBeConvertedToType ('string ' , DummyValue::class)
151
175
);
152
176
153
177
// Cached result
154
178
$ this ->assertEquals (
155
- true ,
179
+ [DummyConversionInterface::class, ' fromString ' ] ,
156
180
$ this ->converter ->canTypeBeConvertedToType ('string ' , DummyValue::class)
157
181
);
158
182
}
@@ -196,6 +220,27 @@ public function convertValueToType()
196
220
);
197
221
}
198
222
223
+ /**
224
+ * @test
225
+ */
226
+ public function convertChildClassToType ()
227
+ {
228
+ $ this ->converter ->addConversionInterface (
229
+ BaseObject::class,
230
+ BaseObjectConversionInterface::class,
231
+ 'fromBaseObject '
232
+ );
233
+
234
+ $ this ->assertEquals (
235
+ 'My value ' ,
236
+ $ this ->converter ->convertValueToType (new BaseObject ('My value ' ), DummyValue::class)->value
237
+ );
238
+ $ this ->assertEquals (
239
+ 'My value ' ,
240
+ $ this ->converter ->convertValueToType (new SpecificObject ('My value ' ), DummyValue::class)->value
241
+ );
242
+ }
243
+
199
244
/**
200
245
* @test
201
246
*/
0 commit comments