@@ -104,28 +104,50 @@ public function testNotPassedOptionalParameterInBetween()
104
104
$ this ->assertSame ('/app.php/ ' , $ this ->getGenerator ($ routes )->generate ('test ' ));
105
105
}
106
106
107
- public function testRelativeUrlWithExtraParameters ()
107
+ /**
108
+ * @dataProvider valuesProvider
109
+ */
110
+ public function testRelativeUrlWithExtraParameters (string $ expectedQueryString , string $ parameter , $ value )
108
111
{
109
112
$ routes = $ this ->getRoutes ('test ' , new Route ('/testing ' ));
110
- $ url = $ this ->getGenerator ($ routes )->generate ('test ' , [' foo ' => ' bar ' ], UrlGeneratorInterface::ABSOLUTE_PATH );
113
+ $ url = $ this ->getGenerator ($ routes )->generate ('test ' , [$ parameter => $ value ], UrlGeneratorInterface::ABSOLUTE_PATH );
111
114
112
- $ this ->assertEquals ('/app.php/testing?foo=bar ' , $ url );
115
+ $ this ->assertSame ('/app.php/testing ' . $ expectedQueryString , $ url );
113
116
}
114
117
115
- public function testAbsoluteUrlWithExtraParameters ()
118
+ /**
119
+ * @dataProvider valuesProvider
120
+ */
121
+ public function testAbsoluteUrlWithExtraParameters (string $ expectedQueryString , string $ parameter , $ value )
116
122
{
117
123
$ routes = $ this ->getRoutes ('test ' , new Route ('/testing ' ));
118
- $ url = $ this ->getGenerator ($ routes )->generate ('test ' , [' foo ' => ' bar ' ], UrlGeneratorInterface::ABSOLUTE_URL );
124
+ $ url = $ this ->getGenerator ($ routes )->generate ('test ' , [$ parameter => $ value ], UrlGeneratorInterface::ABSOLUTE_URL );
119
125
120
- $ this ->assertEquals ('http://localhost/app.php/testing?foo=bar ' , $ url );
126
+ $ this ->assertSame ('http://localhost/app.php/testing ' . $ expectedQueryString , $ url );
121
127
}
122
128
123
- public function testUrlWithNullExtraParameters ()
129
+ public function valuesProvider (): array
124
130
{
125
- $ routes = $ this -> getRoutes ( ' test ' , new Route ( ' /testing ' ) );
126
- $ url = $ this -> getGenerator ( $ routes )-> generate ( ' test ' , [ ' foo ' => null ], UrlGeneratorInterface:: ABSOLUTE_URL ) ;
131
+ $ stdClass = new \ stdClass ( );
132
+ $ stdClass -> baz = ' bar ' ;
127
133
128
- $ this ->assertEquals ('http://localhost/app.php/testing ' , $ url );
134
+ $ nestedStdClass = new \stdClass ();
135
+ $ nestedStdClass ->nested = $ stdClass ;
136
+
137
+ return [
138
+ 'null ' => ['' , 'foo ' , null ],
139
+ 'string ' => ['?foo=bar ' , 'foo ' , 'bar ' ],
140
+ 'boolean-false ' => ['?foo=0 ' , 'foo ' , false ],
141
+ 'boolean-true ' => ['?foo=1 ' , 'foo ' , true ],
142
+ 'object implementing __toString() ' => ['?foo=bar ' , 'foo ' , new StringableObject ()],
143
+ 'object implementing __toString() but has public property ' => ['?foo%5Bfoo%5D=property ' , 'foo ' , new StringableObjectWithPublicProperty ()],
144
+ 'object implementing __toString() in nested array ' => ['?foo%5Bbaz%5D=bar ' , 'foo ' , ['baz ' => new StringableObject ()]],
145
+ 'object implementing __toString() in nested array but has public property ' => ['?foo%5Bbaz%5D%5Bfoo%5D=property ' , 'foo ' , ['baz ' => new StringableObjectWithPublicProperty ()]],
146
+ 'stdClass ' => ['?foo%5Bbaz%5D=bar ' , 'foo ' , $ stdClass ],
147
+ 'stdClass in nested stdClass ' => ['?foo%5Bnested%5D%5Bbaz%5D=bar ' , 'foo ' , $ nestedStdClass ],
148
+ 'non stringable object ' => ['' , 'foo ' , new NonStringableObject ()],
149
+ 'non stringable object but has public property ' => ['?foo%5Bfoo%5D=property ' , 'foo ' , new NonStringableObjectWithPublicProperty ()],
150
+ ];
129
151
}
130
152
131
153
public function testUrlWithExtraParametersFromGlobals ()
@@ -898,3 +920,30 @@ protected function getRoutes($name, Route $route)
898
920
return $ routes ;
899
921
}
900
922
}
923
+
924
+ class StringableObject
925
+ {
926
+ public function __toString ()
927
+ {
928
+ return 'bar ' ;
929
+ }
930
+ }
931
+
932
+ class StringableObjectWithPublicProperty
933
+ {
934
+ public $ foo = 'property ' ;
935
+
936
+ public function __toString ()
937
+ {
938
+ return 'bar ' ;
939
+ }
940
+ }
941
+
942
+ class NonStringableObject
943
+ {
944
+ }
945
+
946
+ class NonStringableObjectWithPublicProperty
947
+ {
948
+ public $ foo = 'property ' ;
949
+ }
0 commit comments