2424 */
2525class InputFilterAbstractServiceFactoryTest extends TestCase
2626{
27- /** @var ServiceManager */
27+ /**
28+ * @var ServiceManager
29+ */
2830 protected $ services ;
2931
30- /** @var InputFilterPluginManager */
32+ /**
33+ * @var InputFilterPluginManager
34+ */
3135 protected $ filters ;
3236
33- /** @var InputFilterAbstractServiceFactory */
37+ /**
38+ * @var InputFilterAbstractServiceFactory
39+ */
3440 protected $ factory ;
3541
3642 public function setUp ()
@@ -44,27 +50,48 @@ public function setUp()
4450
4551 public function testCannotCreateServiceIfNoConfigServicePresent ()
4652 {
47- $ this ->assertFalse ($ this ->factory ->canCreate ($ this ->getCompatContainer (), 'filter ' ));
48- // v2
49- $ this ->assertFalse ($ this ->factory ->canCreateServiceWithName ($ this ->getCompatContainer (), 'filter ' , 'filter ' ));
53+ if (method_exists ($ this ->services , 'configure ' )) {
54+ // v3
55+ $ method = 'canCreate ' ;
56+ $ args = [$ this ->getCompatContainer (), 'filter ' ];
57+ } else {
58+ // v2
59+ $ method = 'canCreateServiceWithName ' ;
60+ $ args = [$ this ->getCompatContainer (), 'filter ' , 'filter ' ];
61+ }
62+ $ this ->assertFalse (call_user_func_array ([$ this ->factory , $ method ], $ args ));
5063 }
5164
5265 public function testCannotCreateServiceIfConfigServiceDoesNotHaveInputFiltersConfiguration ()
5366 {
5467 $ this ->services ->setService ('config ' , []);
55- $ this ->assertFalse ($ this ->factory ->canCreate ($ this ->getCompatContainer (), 'filter ' ));
56- // v2
57- $ this ->assertFalse ($ this ->factory ->canCreateServiceWithName ($ this ->getCompatContainer (), 'filter ' , 'filter ' ));
68+ if (method_exists ($ this ->services , 'configure ' )) {
69+ // v3
70+ $ method = 'canCreate ' ;
71+ $ args = [$ this ->getCompatContainer (), 'filter ' ];
72+ } else {
73+ // v2
74+ $ method = 'canCreateServiceWithName ' ;
75+ $ args = [$ this ->getCompatContainer (), 'filter ' , 'filter ' ];
76+ }
77+ $ this ->assertFalse (call_user_func_array ([$ this ->factory , $ method ], $ args ));
5878 }
5979
6080 public function testCannotCreateServiceIfConfigInputFiltersDoesNotContainMatchingServiceName ()
6181 {
6282 $ this ->services ->setService ('config ' , [
6383 'input_filter_specs ' => [],
6484 ]);
65- $ this ->assertFalse ($ this ->factory ->canCreate ($ this ->getCompatContainer (), 'filter ' ));
66- // v2
67- $ this ->assertFalse ($ this ->factory ->canCreateServiceWithName ($ this ->getCompatContainer (), 'filter ' , 'filter ' ));
85+ if (method_exists ($ this ->services , 'configure ' )) {
86+ // v3
87+ $ method = 'canCreate ' ;
88+ $ args = [$ this ->getCompatContainer (), 'filter ' ];
89+ } else {
90+ // v2
91+ $ method = 'canCreateServiceWithName ' ;
92+ $ args = [$ this ->getCompatContainer (), 'filter ' , 'filter ' ];
93+ }
94+ $ this ->assertFalse (call_user_func_array ([$ this ->factory , $ method ], $ args ));
6895 }
6996
7097 public function testCanCreateServiceIfConfigInputFiltersContainsMatchingServiceName ()
@@ -74,9 +101,16 @@ public function testCanCreateServiceIfConfigInputFiltersContainsMatchingServiceN
74101 'filter ' => [],
75102 ],
76103 ]);
77- $ this ->assertTrue ($ this ->factory ->canCreate ($ this ->getCompatContainer (), 'filter ' ));
78- // v2
79- $ this ->assertTrue ($ this ->factory ->canCreateServiceWithName ($ this ->getCompatContainer (), 'filter ' , 'filter ' ));
104+ if (method_exists ($ this ->services , 'configure ' )) {
105+ // v3
106+ $ method = 'canCreate ' ;
107+ $ args = [$ this ->getCompatContainer (), 'filter ' ];
108+ } else {
109+ // v2
110+ $ method = 'canCreateServiceWithName ' ;
111+ $ args = [$ this ->getCompatContainer (), 'filter ' , 'filter ' ];
112+ }
113+ $ this ->assertTrue (call_user_func_array ([$ this ->factory , $ method ], $ args ));
80114 }
81115
82116 public function testCreatesInputFilterInstance ()
@@ -86,11 +120,17 @@ public function testCreatesInputFilterInstance()
86120 'filter ' => [],
87121 ],
88122 ]);
89- $ filter = $ this ->factory ->__invoke ($ this ->getCompatContainer (), 'filter ' );
123+ if (method_exists ($ this ->services , 'configure ' )) {
124+ // v3
125+ $ method = '__invoke ' ;
126+ $ args = [$ this ->getCompatContainer (), 'filter ' ];
127+ } else {
128+ // v2
129+ $ method = 'createServiceWithName ' ;
130+ $ args = [$ this ->getCompatContainer (), 'filter ' , 'filter ' ];
131+ }
132+ $ filter = call_user_func_array ([$ this ->factory , $ method ], $ args );
90133 $ this ->assertInstanceOf (InputFilterInterface::class, $ filter );
91- // v2
92- $ v2filter = $ this ->factory ->createServiceWithName ($ this ->getCompatContainer (), 'filter ' , 'filter ' );
93- $ this ->assertEquals ($ filter , $ v2filter );
94134 }
95135
96136 /**
@@ -128,11 +168,17 @@ public function testUsesConfiguredValidationAndFilterManagerServicesWhenCreating
128168 ]);
129169
130170
131- $ inputFilter = $ this ->factory ->__invoke ($ this ->getCompatContainer (), 'filter ' );
171+ if (method_exists ($ this ->services , 'configure ' )) {
172+ // v3
173+ $ method = '__invoke ' ;
174+ $ args = [$ this ->getCompatContainer (), 'filter ' ];
175+ } else {
176+ // v2
177+ $ method = 'createServiceWithName ' ;
178+ $ args = [$ this ->getCompatContainer (), 'filter ' , 'filter ' ];
179+ }
180+ $ inputFilter = call_user_func_array ([$ this ->factory , $ method ], $ args );
132181 $ this ->assertTrue ($ inputFilter ->has ('input ' ));
133- // v2
134- $ v2InputFilter = $ this ->factory ->createServiceWithName ($ this ->getCompatContainer (), 'filter ' , 'filter ' );
135- $ this ->assertEquals ($ inputFilter , $ v2InputFilter );
136182
137183 $ input = $ inputFilter ->get ('input ' );
138184
0 commit comments