How to use getGenerator method of name class

Best Mockery code snippet using name.getGenerator

UrlGeneratorTest.php

Source:UrlGeneratorTest.php Github

copy

Full Screen

...18{19 public function testAbsoluteUrlWithPort80()20 {21 $routes = $this->getRoutes('test', new Route('/testing'));22 $url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);23 $this->assertEquals('http://localhost/app.php/testing', $url);24 }25 public function testAbsoluteSecureUrlWithPort443()26 {27 $routes = $this->getRoutes('test', new Route('/testing'));28 $url = $this->getGenerator($routes, ['scheme' => 'https'])->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);29 $this->assertEquals('https://localhost/app.php/testing', $url);30 }31 public function testAbsoluteUrlWithNonStandardPort()32 {33 $routes = $this->getRoutes('test', new Route('/testing'));34 $url = $this->getGenerator($routes, ['httpPort' => 8080])->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);35 $this->assertEquals('http://localhost:8080/app.php/testing', $url);36 }37 public function testAbsoluteSecureUrlWithNonStandardPort()38 {39 $routes = $this->getRoutes('test', new Route('/testing'));40 $url = $this->getGenerator($routes, ['httpsPort' => 8080, 'scheme' => 'https'])->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);41 $this->assertEquals('https://localhost:8080/app.php/testing', $url);42 }43 public function testRelativeUrlWithoutParameters()44 {45 $routes = $this->getRoutes('test', new Route('/testing'));46 $url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH);47 $this->assertEquals('/app.php/testing', $url);48 }49 public function testRelativeUrlWithParameter()50 {51 $routes = $this->getRoutes('test', new Route('/testing/{foo}'));52 $url = $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_PATH);53 $this->assertEquals('/app.php/testing/bar', $url);54 }55 public function testRelativeUrlWithNullParameter()56 {57 $routes = $this->getRoutes('test', new Route('/testing.{format}', ['format' => null]));58 $url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH);59 $this->assertEquals('/app.php/testing', $url);60 }61 public function testRelativeUrlWithNullParameterButNotOptional()62 {63 $this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');64 $routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', ['foo' => null]));65 // This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params.66 // Generating path "/testing//bar" would be wrong as matching this route would fail.67 $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH);68 }69 public function testRelativeUrlWithOptionalZeroParameter()70 {71 $routes = $this->getRoutes('test', new Route('/testing/{page}'));72 $url = $this->getGenerator($routes)->generate('test', ['page' => 0], UrlGeneratorInterface::ABSOLUTE_PATH);73 $this->assertEquals('/app.php/testing/0', $url);74 }75 public function testNotPassedOptionalParameterInBetween()76 {77 $routes = $this->getRoutes('test', new Route('/{slug}/{page}', ['slug' => 'index', 'page' => 0]));78 $this->assertSame('/app.php/index/1', $this->getGenerator($routes)->generate('test', ['page' => 1]));79 $this->assertSame('/app.php/', $this->getGenerator($routes)->generate('test'));80 }81 public function testRelativeUrlWithExtraParameters()82 {83 $routes = $this->getRoutes('test', new Route('/testing'));84 $url = $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_PATH);85 $this->assertEquals('/app.php/testing?foo=bar', $url);86 }87 public function testAbsoluteUrlWithExtraParameters()88 {89 $routes = $this->getRoutes('test', new Route('/testing'));90 $url = $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);91 $this->assertEquals('http://localhost/app.php/testing?foo=bar', $url);92 }93 public function testUrlWithNullExtraParameters()94 {95 $routes = $this->getRoutes('test', new Route('/testing'));96 $url = $this->getGenerator($routes)->generate('test', ['foo' => null], UrlGeneratorInterface::ABSOLUTE_URL);97 $this->assertEquals('http://localhost/app.php/testing', $url);98 }99 public function testUrlWithExtraParametersFromGlobals()100 {101 $routes = $this->getRoutes('test', new Route('/testing'));102 $generator = $this->getGenerator($routes);103 $context = new RequestContext('/app.php');104 $context->setParameter('bar', 'bar');105 $generator->setContext($context);106 $url = $generator->generate('test', ['foo' => 'bar']);107 $this->assertEquals('/app.php/testing?foo=bar', $url);108 }109 public function testUrlWithGlobalParameter()110 {111 $routes = $this->getRoutes('test', new Route('/testing/{foo}'));112 $generator = $this->getGenerator($routes);113 $context = new RequestContext('/app.php');114 $context->setParameter('foo', 'bar');115 $generator->setContext($context);116 $url = $generator->generate('test', []);117 $this->assertEquals('/app.php/testing/bar', $url);118 }119 public function testGlobalParameterHasHigherPriorityThanDefault()120 {121 $routes = $this->getRoutes('test', new Route('/{_locale}', ['_locale' => 'en']));122 $generator = $this->getGenerator($routes);123 $context = new RequestContext('/app.php');124 $context->setParameter('_locale', 'de');125 $generator->setContext($context);126 $url = $generator->generate('test', []);127 $this->assertSame('/app.php/de', $url);128 }129 public function testGenerateWithDefaultLocale()130 {131 $routes = new RouteCollection();132 $route = new Route('');133 $name = 'test';134 foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {135 $localizedRoute = clone $route;136 $localizedRoute->setDefault('_locale', $locale);137 $localizedRoute->setDefault('_canonical_route', $name);138 $localizedRoute->setPath($path);139 $routes->add($name.'.'.$locale, $localizedRoute);140 }141 $generator = $this->getGenerator($routes, [], null, 'hr');142 $this->assertSame(143 'http://localhost/app.php/foo',144 $generator->generate($name, [], UrlGeneratorInterface::ABSOLUTE_URL)145 );146 }147 public function testGenerateWithOverriddenParameterLocale()148 {149 $routes = new RouteCollection();150 $route = new Route('');151 $name = 'test';152 foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {153 $localizedRoute = clone $route;154 $localizedRoute->setDefault('_locale', $locale);155 $localizedRoute->setDefault('_canonical_route', $name);156 $localizedRoute->setPath($path);157 $routes->add($name.'.'.$locale, $localizedRoute);158 }159 $generator = $this->getGenerator($routes, [], null, 'hr');160 $this->assertSame(161 'http://localhost/app.php/bar',162 $generator->generate($name, ['_locale' => 'en'], UrlGeneratorInterface::ABSOLUTE_URL)163 );164 }165 public function testGenerateWithOverriddenParameterLocaleFromRequestContext()166 {167 $routes = new RouteCollection();168 $route = new Route('');169 $name = 'test';170 foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {171 $localizedRoute = clone $route;172 $localizedRoute->setDefault('_locale', $locale);173 $localizedRoute->setDefault('_canonical_route', $name);174 $localizedRoute->setPath($path);175 $routes->add($name.'.'.$locale, $localizedRoute);176 }177 $generator = $this->getGenerator($routes, [], null, 'hr');178 $context = new RequestContext('/app.php');179 $context->setParameter('_locale', 'en');180 $generator->setContext($context);181 $this->assertSame(182 'http://localhost/app.php/bar',183 $generator->generate($name, [], UrlGeneratorInterface::ABSOLUTE_URL)184 );185 }186 public function testGenerateWithoutRoutes()187 {188 $this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');189 $routes = $this->getRoutes('foo', new Route('/testing/{foo}'));190 $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);191 }192 public function testGenerateWithInvalidLocale()193 {194 $this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');195 $routes = new RouteCollection();196 $route = new Route('');197 $name = 'test';198 foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {199 $localizedRoute = clone $route;200 $localizedRoute->setDefault('_locale', $locale);201 $localizedRoute->setDefault('_canonical_route', $name);202 $localizedRoute->setPath($path);203 $routes->add($name.'.'.$locale, $localizedRoute);204 }205 $generator = $this->getGenerator($routes, [], null, 'fr');206 $generator->generate($name);207 }208 public function testGenerateForRouteWithoutMandatoryParameter()209 {210 $this->expectException('Symfony\Component\Routing\Exception\MissingMandatoryParametersException');211 $routes = $this->getRoutes('test', new Route('/testing/{foo}'));212 $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);213 }214 public function testGenerateForRouteWithInvalidOptionalParameter()215 {216 $this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');217 $routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));218 $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);219 }220 public function testGenerateForRouteWithInvalidParameter()221 {222 $this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');223 $routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '1|2']));224 $this->getGenerator($routes)->generate('test', ['foo' => '0'], UrlGeneratorInterface::ABSOLUTE_URL);225 }226 public function testGenerateForRouteWithInvalidOptionalParameterNonStrict()227 {228 $routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));229 $generator = $this->getGenerator($routes);230 $generator->setStrictRequirements(false);231 $this->assertSame('', $generator->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL));232 }233 public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger()234 {235 $routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));236 $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();237 $logger->expects($this->once())238 ->method('error');239 $generator = $this->getGenerator($routes, [], $logger);240 $generator->setStrictRequirements(false);241 $this->assertSame('', $generator->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL));242 }243 public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsCheck()244 {245 $routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));246 $generator = $this->getGenerator($routes);247 $generator->setStrictRequirements(null);248 $this->assertSame('/app.php/testing/bar', $generator->generate('test', ['foo' => 'bar']));249 }250 public function testGenerateForRouteWithInvalidMandatoryParameter()251 {252 $this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');253 $routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => 'd+']));254 $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);255 }256 public function testGenerateForRouteWithInvalidUtf8Parameter()257 {258 $this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');259 $routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '\pL+'], ['utf8' => true]));260 $this->getGenerator($routes)->generate('test', ['foo' => 'abc123'], UrlGeneratorInterface::ABSOLUTE_URL);261 }262 public function testRequiredParamAndEmptyPassed()263 {264 $this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');265 $routes = $this->getRoutes('test', new Route('/{slug}', [], ['slug' => '.+']));266 $this->getGenerator($routes)->generate('test', ['slug' => '']);267 }268 public function testSchemeRequirementDoesNothingIfSameCurrentScheme()269 {270 $routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['http']));271 $this->assertEquals('/app.php/', $this->getGenerator($routes)->generate('test'));272 $routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['https']));273 $this->assertEquals('/app.php/', $this->getGenerator($routes, ['scheme' => 'https'])->generate('test'));274 }275 public function testSchemeRequirementForcesAbsoluteUrl()276 {277 $routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['https']));278 $this->assertEquals('https://localhost/app.php/', $this->getGenerator($routes)->generate('test'));279 $routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['http']));280 $this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, ['scheme' => 'https'])->generate('test'));281 }282 public function testSchemeRequirementCreatesUrlForFirstRequiredScheme()283 {284 $routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['Ftp', 'https']));285 $this->assertEquals('ftp://localhost/app.php/', $this->getGenerator($routes)->generate('test'));286 }287 public function testPathWithTwoStartingSlashes()288 {289 $routes = $this->getRoutes('test', new Route('//path-and-not-domain'));290 // this must not generate '//path-and-not-domain' because that would be a network path291 $this->assertSame('/path-and-not-domain', $this->getGenerator($routes, ['BaseUrl' => ''])->generate('test'));292 }293 public function testNoTrailingSlashForMultipleOptionalParameters()294 {295 $routes = $this->getRoutes('test', new Route('/category/{slug1}/{slug2}/{slug3}', ['slug2' => null, 'slug3' => null]));296 $this->assertEquals('/app.php/category/foo', $this->getGenerator($routes)->generate('test', ['slug1' => 'foo']));297 }298 public function testWithAnIntegerAsADefaultValue()299 {300 $routes = $this->getRoutes('test', new Route('/{default}', ['default' => 0]));301 $this->assertEquals('/app.php/foo', $this->getGenerator($routes)->generate('test', ['default' => 'foo']));302 }303 public function testNullForOptionalParameterIsIgnored()304 {305 $routes = $this->getRoutes('test', new Route('/test/{default}', ['default' => 0]));306 $this->assertEquals('/app.php/test', $this->getGenerator($routes)->generate('test', ['default' => null]));307 }308 public function testQueryParamSameAsDefault()309 {310 $routes = $this->getRoutes('test', new Route('/test', ['page' => 1]));311 $this->assertSame('/app.php/test?page=2', $this->getGenerator($routes)->generate('test', ['page' => 2]));312 $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['page' => 1]));313 $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['page' => '1']));314 $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));315 }316 public function testArrayQueryParamSameAsDefault()317 {318 $routes = $this->getRoutes('test', new Route('/test', ['array' => ['foo', 'bar']]));319 $this->assertSame('/app.php/test?array%5B0%5D=bar&array%5B1%5D=foo', $this->getGenerator($routes)->generate('test', ['array' => ['bar', 'foo']]));320 $this->assertSame('/app.php/test?array%5Ba%5D=foo&array%5Bb%5D=bar', $this->getGenerator($routes)->generate('test', ['array' => ['a' => 'foo', 'b' => 'bar']]));321 $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['array' => ['foo', 'bar']]));322 $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['array' => [1 => 'bar', 0 => 'foo']]));323 $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));324 }325 public function testGenerateWithSpecialRouteName()326 {327 $routes = $this->getRoutes('$péß^a|', new Route('/bar'));328 $this->assertSame('/app.php/bar', $this->getGenerator($routes)->generate('$péß^a|'));329 }330 public function testUrlEncoding()331 {332 $expectedPath = '/app.php/@:%5B%5D/%28%29*%27%22%20+,;-._~%26%24%3C%3E|%7B%7D%25%5C%5E%60!%3Ffoo=bar%23id'333 .'/@:%5B%5D/%28%29*%27%22%20+,;-._~%26%24%3C%3E|%7B%7D%25%5C%5E%60!%3Ffoo=bar%23id'334 .'?query=@:%5B%5D/%28%29*%27%22%20%2B,;-._~%26%24%3C%3E%7C%7B%7D%25%5C%5E%60!?foo%3Dbar%23id';335 // This tests the encoding of reserved characters that are used for delimiting of URI components (defined in RFC 3986)336 // and other special ASCII chars. These chars are tested as static text path, variable path and query param.337 $chars = '@:[]/()*\'" +,;-._~&$<>|{}%\\^`!?foo=bar#id';338 $routes = $this->getRoutes('test', new Route("/$chars/{varpath}", [], ['varpath' => '.+']));339 $this->assertSame($expectedPath, $this->getGenerator($routes)->generate('test', [340 'varpath' => $chars,341 'query' => $chars,342 ]));343 }344 public function testEncodingOfRelativePathSegments()345 {346 $routes = $this->getRoutes('test', new Route('/dir/../dir/..'));347 $this->assertSame('/app.php/dir/%2E%2E/dir/%2E%2E', $this->getGenerator($routes)->generate('test'));348 $routes = $this->getRoutes('test', new Route('/dir/./dir/.'));349 $this->assertSame('/app.php/dir/%2E/dir/%2E', $this->getGenerator($routes)->generate('test'));350 $routes = $this->getRoutes('test', new Route('/a./.a/a../..a/...'));351 $this->assertSame('/app.php/a./.a/a../..a/...', $this->getGenerator($routes)->generate('test'));352 }353 public function testAdjacentVariables()354 {355 $routes = $this->getRoutes('test', new Route('/{x}{y}{z}.{_format}', ['z' => 'default-z', '_format' => 'html'], ['y' => '\d+']));356 $generator = $this->getGenerator($routes);357 $this->assertSame('/app.php/foo123', $generator->generate('test', ['x' => 'foo', 'y' => '123']));358 $this->assertSame('/app.php/foo123bar.xml', $generator->generate('test', ['x' => 'foo', 'y' => '123', 'z' => 'bar', '_format' => 'xml']));359 // The default requirement for 'x' should not allow the separator '.' in this case because it would otherwise match everything360 // and following optional variables like _format could never match.361 $this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');362 $generator->generate('test', ['x' => 'do.t', 'y' => '123', 'z' => 'bar', '_format' => 'xml']);363 }364 public function testOptionalVariableWithNoRealSeparator()365 {366 $routes = $this->getRoutes('test', new Route('/get{what}', ['what' => 'All']));367 $generator = $this->getGenerator($routes);368 $this->assertSame('/app.php/get', $generator->generate('test'));369 $this->assertSame('/app.php/getSites', $generator->generate('test', ['what' => 'Sites']));370 }371 public function testRequiredVariableWithNoRealSeparator()372 {373 $routes = $this->getRoutes('test', new Route('/get{what}Suffix'));374 $generator = $this->getGenerator($routes);375 $this->assertSame('/app.php/getSitesSuffix', $generator->generate('test', ['what' => 'Sites']));376 }377 public function testDefaultRequirementOfVariable()378 {379 $routes = $this->getRoutes('test', new Route('/{page}.{_format}'));380 $generator = $this->getGenerator($routes);381 $this->assertSame('/app.php/index.mobile.html', $generator->generate('test', ['page' => 'index', '_format' => 'mobile.html']));382 }383 public function testImportantVariable()384 {385 $routes = $this->getRoutes('test', (new Route('/{page}.{!_format}'))->addDefaults(['_format' => 'mobile.html']));386 $generator = $this->getGenerator($routes);387 $this->assertSame('/app.php/index.xml', $generator->generate('test', ['page' => 'index', '_format' => 'xml']));388 $this->assertSame('/app.php/index.mobile.html', $generator->generate('test', ['page' => 'index', '_format' => 'mobile.html']));389 $this->assertSame('/app.php/index.mobile.html', $generator->generate('test', ['page' => 'index']));390 }391 public function testImportantVariableWithNoDefault()392 {393 $this->expectException('Symfony\Component\Routing\Exception\MissingMandatoryParametersException');394 $routes = $this->getRoutes('test', new Route('/{page}.{!_format}'));395 $generator = $this->getGenerator($routes);396 $generator->generate('test', ['page' => 'index']);397 }398 public function testDefaultRequirementOfVariableDisallowsSlash()399 {400 $this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');401 $routes = $this->getRoutes('test', new Route('/{page}.{_format}'));402 $this->getGenerator($routes)->generate('test', ['page' => 'index', '_format' => 'sl/ash']);403 }404 public function testDefaultRequirementOfVariableDisallowsNextSeparator()405 {406 $this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');407 $routes = $this->getRoutes('test', new Route('/{page}.{_format}'));408 $this->getGenerator($routes)->generate('test', ['page' => 'do.t', '_format' => 'html']);409 }410 public function testWithHostDifferentFromContext()411 {412 $routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com'));413 $this->assertEquals('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', ['name' => 'Fabien', 'locale' => 'fr']));414 }415 public function testWithHostSameAsContext()416 {417 $routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com'));418 $this->assertEquals('/app.php/Fabien', $this->getGenerator($routes, ['host' => 'fr.example.com'])->generate('test', ['name' => 'Fabien', 'locale' => 'fr']));419 }420 public function testWithHostSameAsContextAndAbsolute()421 {422 $routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com'));423 $this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, ['host' => 'fr.example.com'])->generate('test', ['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::ABSOLUTE_URL));424 }425 public function testUrlWithInvalidParameterInHost()426 {427 $this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');428 $routes = $this->getRoutes('test', new Route('/', [], ['foo' => 'bar'], [], '{foo}.example.com'));429 $this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);430 }431 public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue()432 {433 $this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');434 $routes = $this->getRoutes('test', new Route('/', ['foo' => 'bar'], ['foo' => 'bar'], [], '{foo}.example.com'));435 $this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);436 }437 public function testUrlWithInvalidParameterEqualsDefaultValueInHost()438 {439 $this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');440 $routes = $this->getRoutes('test', new Route('/', ['foo' => 'baz'], ['foo' => 'bar'], [], '{foo}.example.com'));441 $this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);442 }443 public function testUrlWithInvalidParameterInHostInNonStrictMode()444 {445 $routes = $this->getRoutes('test', new Route('/', [], ['foo' => 'bar'], [], '{foo}.example.com'));446 $generator = $this->getGenerator($routes);447 $generator->setStrictRequirements(false);448 $this->assertSame('', $generator->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH));449 }450 public function testHostIsCaseInsensitive()451 {452 $routes = $this->getRoutes('test', new Route('/', [], ['locale' => 'en|de|fr'], [], '{locale}.FooBar.com'));453 $generator = $this->getGenerator($routes);454 $this->assertSame('//EN.FooBar.com/app.php/', $generator->generate('test', ['locale' => 'EN'], UrlGeneratorInterface::NETWORK_PATH));455 }456 public function testDefaultHostIsUsedWhenContextHostIsEmpty()457 {458 $routes = $this->getRoutes('test', new Route('/path', ['domain' => 'my.fallback.host'], ['domain' => '.+'], [], '{domain}'));459 $generator = $this->getGenerator($routes);460 $generator->getContext()->setHost('');461 $this->assertSame('http://my.fallback.host/app.php/path', $generator->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL));462 }463 public function testDefaultHostIsUsedWhenContextHostIsEmptyAndPathReferenceType()464 {465 $routes = $this->getRoutes('test', new Route('/path', ['domain' => 'my.fallback.host'], ['domain' => '.+'], [], '{domain}'));466 $generator = $this->getGenerator($routes);467 $generator->getContext()->setHost('');468 $this->assertSame('//my.fallback.host/app.php/path', $generator->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH));469 }470 public function testAbsoluteUrlFallbackToPathIfHostIsEmptyAndSchemeIsHttp()471 {472 $routes = $this->getRoutes('test', new Route('/route'));473 $generator = $this->getGenerator($routes);474 $generator->getContext()->setHost('');475 $generator->getContext()->setScheme('https');476 $this->assertSame('/app.php/route', $generator->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL));477 }478 public function testAbsoluteUrlFallbackToNetworkIfSchemeIsEmptyAndHostIsNot()479 {480 $routes = $this->getRoutes('test', new Route('/path'));481 $generator = $this->getGenerator($routes);482 $generator->getContext()->setHost('example.com');483 $generator->getContext()->setScheme('');484 $this->assertSame('//example.com/app.php/path', $generator->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL));485 }486 public function testAbsoluteUrlFallbackToPathIfSchemeAndHostAreEmpty()487 {488 $routes = $this->getRoutes('test', new Route('/path'));489 $generator = $this->getGenerator($routes);490 $generator->getContext()->setHost('');491 $generator->getContext()->setScheme('');492 $this->assertSame('/app.php/path', $generator->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL));493 }494 public function testAbsoluteUrlWithNonHttpSchemeAndEmptyHost()495 {496 $routes = $this->getRoutes('test', new Route('/path', [], [], [], '', ['file']));497 $generator = $this->getGenerator($routes);498 $generator->getContext()->setBaseUrl('');499 $generator->getContext()->setHost('');500 $this->assertSame('file:///path', $generator->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL));501 }502 public function testGenerateNetworkPath()503 {504 $routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com', ['http']));505 $this->assertSame('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test',506 ['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::NETWORK_PATH), 'network path with different host'507 );508 $this->assertSame('//fr.example.com/app.php/Fabien?query=string', $this->getGenerator($routes, ['host' => 'fr.example.com'])->generate('test',509 ['name' => 'Fabien', 'locale' => 'fr', 'query' => 'string'], UrlGeneratorInterface::NETWORK_PATH), 'network path although host same as context'510 );511 $this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, ['scheme' => 'https'])->generate('test',512 ['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::NETWORK_PATH), 'absolute URL because scheme requirement does not match context'513 );514 $this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test',515 ['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::ABSOLUTE_URL), 'absolute URL with same scheme because it is requested'516 );517 }518 public function testGenerateRelativePath()519 {520 $routes = new RouteCollection();521 $routes->add('article', new Route('/{author}/{article}/'));522 $routes->add('comments', new Route('/{author}/{article}/comments'));523 $routes->add('host', new Route('/{article}', [], [], [], '{author}.example.com'));524 $routes->add('scheme', new Route('/{author}/blog', [], [], [], '', ['https']));525 $routes->add('unrelated', new Route('/about'));526 $generator = $this->getGenerator($routes, ['host' => 'example.com', 'pathInfo' => '/fabien/symfony-is-great/']);527 $this->assertSame('comments', $generator->generate('comments',528 ['author' => 'fabien', 'article' => 'symfony-is-great'], UrlGeneratorInterface::RELATIVE_PATH)529 );530 $this->assertSame('comments?page=2', $generator->generate('comments',531 ['author' => 'fabien', 'article' => 'symfony-is-great', 'page' => 2], UrlGeneratorInterface::RELATIVE_PATH)532 );533 $this->assertSame('../twig-is-great/', $generator->generate('article',534 ['author' => 'fabien', 'article' => 'twig-is-great'], UrlGeneratorInterface::RELATIVE_PATH)535 );536 $this->assertSame('../../bernhard/forms-are-great/', $generator->generate('article',537 ['author' => 'bernhard', 'article' => 'forms-are-great'], UrlGeneratorInterface::RELATIVE_PATH)538 );539 $this->assertSame('//bernhard.example.com/app.php/forms-are-great', $generator->generate('host',540 ['author' => 'bernhard', 'article' => 'forms-are-great'], UrlGeneratorInterface::RELATIVE_PATH)541 );542 $this->assertSame('https://example.com/app.php/bernhard/blog', $generator->generate('scheme',543 ['author' => 'bernhard'], UrlGeneratorInterface::RELATIVE_PATH)544 );545 $this->assertSame('../../about', $generator->generate('unrelated',546 [], UrlGeneratorInterface::RELATIVE_PATH)547 );548 }549 /**550 * @dataProvider provideRelativePaths551 */552 public function testGetRelativePath($sourcePath, $targetPath, $expectedPath)553 {554 $this->assertSame($expectedPath, UrlGenerator::getRelativePath($sourcePath, $targetPath));555 }556 public function provideRelativePaths()557 {558 return [559 [560 '/same/dir/',561 '/same/dir/',562 '',563 ],564 [565 '/same/file',566 '/same/file',567 '',568 ],569 [570 '/',571 '/file',572 'file',573 ],574 [575 '/',576 '/dir/file',577 'dir/file',578 ],579 [580 '/dir/file.html',581 '/dir/different-file.html',582 'different-file.html',583 ],584 [585 '/same/dir/extra-file',586 '/same/dir/',587 './',588 ],589 [590 '/parent/dir/',591 '/parent/',592 '../',593 ],594 [595 '/parent/dir/extra-file',596 '/parent/',597 '../',598 ],599 [600 '/a/b/',601 '/x/y/z/',602 '../../x/y/z/',603 ],604 [605 '/a/b/c/d/e',606 '/a/c/d',607 '../../../c/d',608 ],609 [610 '/a/b/c//',611 '/a/b/c/',612 '../',613 ],614 [615 '/a/b/c/',616 '/a/b/c//',617 './/',618 ],619 [620 '/root/a/b/c/',621 '/root/x/b/c/',622 '../../../x/b/c/',623 ],624 [625 '/a/b/c/d/',626 '/a',627 '../../../../a',628 ],629 [630 '/special-chars/sp%20ce/1€/mäh/e=mc²',631 '/special-chars/sp%20ce/1€/<µ>/e=mc²',632 '../<µ>/e=mc²',633 ],634 [635 'not-rooted',636 'dir/file',637 'dir/file',638 ],639 [640 '//dir/',641 '',642 '../../',643 ],644 [645 '/dir/',646 '/dir/file:with-colon',647 './file:with-colon',648 ],649 [650 '/dir/',651 '/dir/subdir/file:with-colon',652 'subdir/file:with-colon',653 ],654 [655 '/dir/',656 '/dir/:subdir/',657 './:subdir/',658 ],659 ];660 }661 public function testFragmentsCanBeAppendedToUrls()662 {663 $routes = $this->getRoutes('test', new Route('/testing'));664 $url = $this->getGenerator($routes)->generate('test', ['_fragment' => 'frag ment'], UrlGeneratorInterface::ABSOLUTE_PATH);665 $this->assertEquals('/app.php/testing#frag%20ment', $url);666 $url = $this->getGenerator($routes)->generate('test', ['_fragment' => '0'], UrlGeneratorInterface::ABSOLUTE_PATH);667 $this->assertEquals('/app.php/testing#0', $url);668 }669 public function testFragmentsDoNotEscapeValidCharacters()670 {671 $routes = $this->getRoutes('test', new Route('/testing'));672 $url = $this->getGenerator($routes)->generate('test', ['_fragment' => '?/'], UrlGeneratorInterface::ABSOLUTE_PATH);673 $this->assertEquals('/app.php/testing#?/', $url);674 }675 public function testFragmentsCanBeDefinedAsDefaults()676 {677 $routes = $this->getRoutes('test', new Route('/testing', ['_fragment' => 'fragment']));678 $url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH);679 $this->assertEquals('/app.php/testing#fragment', $url);680 }681 /**682 * @dataProvider provideLookAroundRequirementsInPath683 */684 public function testLookRoundRequirementsInPath($expected, $path, $requirement)685 {686 $routes = $this->getRoutes('test', new Route($path, [], ['foo' => $requirement, 'baz' => '.+?']));687 $this->assertSame($expected, $this->getGenerator($routes)->generate('test', ['foo' => 'a/b', 'baz' => 'c/d/e']));688 }689 public function provideLookAroundRequirementsInPath()690 {691 yield ['/app.php/a/b/b%28ar/c/d/e', '/{foo}/b(ar/{baz}', '.+(?=/b\\(ar/)'];692 yield ['/app.php/a/b/bar/c/d/e', '/{foo}/bar/{baz}', '.+(?!$)'];693 yield ['/app.php/bar/a/b/bam/c/d/e', '/bar/{foo}/bam/{baz}', '(?<=/bar/).+'];694 yield ['/app.php/bar/a/b/bam/c/d/e', '/bar/{foo}/bam/{baz}', '(?<!^).+'];695 }696 protected function getGenerator(RouteCollection $routes, array $parameters = [], $logger = null, string $defaultLocale = null)697 {698 $context = new RequestContext('/app.php');699 foreach ($parameters as $key => $value) {700 $method = 'set'.$key;701 $context->$method($value);702 }703 return new UrlGenerator($routes, $context, $logger, $defaultLocale);704 }705 protected function getRoutes($name, Route $route)706 {707 $routes = new RouteCollection();708 $routes->add($name, $route);709 return $routes;710 }...

Full Screen

Full Screen

getGenerator

Using AI Code Generation

copy

Full Screen

1$generator = Name::getGenerator();2echo $generator->generateName();3$generator = Name::getGenerator();4echo $generator->generateName();5$generator = Name::getGenerator();6echo $generator->generateName();7$generator = Name::getGenerator();8echo $generator->generateName();9$generator = Name::getGenerator();10echo $generator->generateName();11$generator = Name::getGenerator();12echo $generator->generateName();13$generator = Name::getGenerator();14echo $generator->generateName();15$generator = Name::getGenerator();16echo $generator->generateName();17$generator = Name::getGenerator();18echo $generator->generateName();19$generator = Name::getGenerator();20echo $generator->generateName();21$generator = Name::getGenerator();22echo $generator->generateName();23$generator = Name::getGenerator();24echo $generator->generateName();25$generator = Name::getGenerator();26echo $generator->generateName();27$generator = Name::getGenerator();28echo $generator->generateName();29$generator = Name::getGenerator();30echo $generator->generateName();

Full Screen

Full Screen

getGenerator

Using AI Code Generation

copy

Full Screen

1include("name.php");2$gen = name::getGenerator();3echo $gen->getName();4include("name.php");5$gen = name::getGenerator();6echo $gen->getName();7include("name.php");8$gen = name::getGenerator();9echo $gen->getName();10include("name.php");11$gen = name::getGenerator();12echo $gen->getName();13include("name.php");14$gen = name::getGenerator();15echo $gen->getName();16include("name.php");17$gen = name::getGenerator();18echo $gen->getName();19include("name.php");20$gen = name::getGenerator();21echo $gen->getName();22include("name.php");23$gen = name::getGenerator();24echo $gen->getName();25include("name.php");26$gen = name::getGenerator();27echo $gen->getName();28include("name.php");29$gen = name::getGenerator();30echo $gen->getName();31include("name.php");32$gen = name::getGenerator();33echo $gen->getName();34include("name.php");35$gen = name::getGenerator();36echo $gen->getName();37include("name.php");38$gen = name::getGenerator();39echo $gen->getName();40include("name.php");41$gen = name::getGenerator();

Full Screen

Full Screen

getGenerator

Using AI Code Generation

copy

Full Screen

1$generator = Name::getGenerator();2$generator1 = Name::getGenerator();3$generator2 = Name::getGenerator();4$generator3 = Name::getGenerator();5$generator4 = Name::getGenerator();6$generator5 = Name::getGenerator();7$generator6 = Name::getGenerator();8$generator7 = Name::getGenerator();9$generator8 = Name::getGenerator();10$generator9 = Name::getGenerator();11$generator10 = Name::getGenerator();12$generator11 = Name::getGenerator();13$generator12 = Name::getGenerator();14$generator13 = Name::getGenerator();15$generator14 = Name::getGenerator();16$generator15 = Name::getGenerator();17$generator16 = Name::getGenerator();18$generator17 = Name::getGenerator();19$generator18 = Name::getGenerator();20$generator19 = Name::getGenerator();21$generator20 = Name::getGenerator();22$generator21 = Name::getGenerator();23$generator22 = Name::getGenerator();24$generator23 = Name::getGenerator();25$generator24 = Name::getGenerator();

Full Screen

Full Screen

getGenerator

Using AI Code Generation

copy

Full Screen

1require_once('name.php');2$generator = Name::getGenerator();3echo $generator->getName();4require_once('name.php');5$generator = Name::getGenerator();6echo $generator->getName();7require_once('name.php');8$generator = Name::getGenerator();9echo $generator->getName();10require_once('name.php');11$generator = Name::getGenerator();12echo $generator->getName();13require_once('name.php');14$generator = Name::getGenerator();15echo $generator->getName();16require_once('name.php');17$generator = Name::getGenerator();18echo $generator->getName();19require_once('name.php');20$generator = Name::getGenerator();21echo $generator->getName();22require_once('name.php');23$generator = Name::getGenerator();24echo $generator->getName();25require_once('name.php');26$generator = Name::getGenerator();27echo $generator->getName();28require_once('name.php');29$generator = Name::getGenerator();30echo $generator->getName();31require_once('name.php');32$generator = Name::getGenerator();33echo $generator->getName();34require_once('name.php');35$generator = Name::getGenerator();36echo $generator->getName();37require_once('name.php');38$generator = Name::getGenerator();39echo $generator->getName();40require_once('name

Full Screen

Full Screen

getGenerator

Using AI Code Generation

copy

Full Screen

1$obj = new name();2$gen = $obj->getGenerator();3foreach ($gen as $value) {4 echo $value;5 echo "<br>";6}7$obj = new name();8$gen = $obj->getGenerator();9foreach ($gen as $value) {10 echo $value;11 echo "<br>";12}13function getGenerator()14{15 yield 'A';16 yield 'B';17 yield 'C';18}19function getGenerator1()20{21 yield 'D';22 yield 'E';23 yield 'F';24}25function getGenerator2()26{27 yield from getGenerator();28 yield from getGenerator1();29}30$gen = getGenerator2();31foreach ($gen as $value) {32 echo $value;33 echo "<br>";34}35function getGenerator()36{37 yield 'A';38 yield 'B';39 yield 'C';40}41function getGenerator1()42{43 yield 'D';44 yield 'E';45 yield 'F';46}47function getGenerator2()48{49 yield from getGenerator();50 yield from getGenerator1();51}52$gen = getGenerator2();

Full Screen

Full Screen

getGenerator

Using AI Code Generation

copy

Full Screen

1$object = new name;2$object->getGenerator();3$object = new name;4$object->getGenerator();5$object = new name;6$object->getGenerator();7$object = new name;8$object->getGenerator();9$object = new name;10$object->getGenerator();11$object = new name;12$object->getGenerator();13$object = new name;14$object->getGenerator();15$object = new name;16$object->getGenerator();17$object = new name;18$object->getGenerator();19$object = new name;20$object->getGenerator();21$object = new name;22$object->getGenerator();23$object = new name;24$object->getGenerator();25$object = new name;26$object->getGenerator();27$object = new name;28$object->getGenerator();

Full Screen

Full Screen

getGenerator

Using AI Code Generation

copy

Full Screen

1foreach (name::getGenerator() as $value) {2";3}4foreach (name::getGenerator() as $value) {5";6}

Full Screen

Full Screen

getGenerator

Using AI Code Generation

copy

Full Screen

1$name = new Name();2$generator = $name->getGenerator();3$generator->getName();4$name = new Name();5$generator = $name->getGenerator();6$generator->getName();7$name = new Name();8$generator = $name->getGenerator();9$generator->getName();10$name = new Name();11$generator = $name->getGenerator();12$generator->getName();13$name = new Name();14$generator = $name->getGenerator();15$generator->getName();16$name = new Name();17$generator = $name->getGenerator();18$generator->getName();19$name = new Name();20$generator = $name->getGenerator();21$generator->getName();22$name = new Name();23$generator = $name->getGenerator();24$generator->getName();25$name = new Name();26$generator = $name->getGenerator();27$generator->getName();28$name = new Name();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mockery automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger getGenerator code on LambdaTest Cloud Grid

Execute automation tests with getGenerator on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful