Skip to content

Commit f97d17b

Browse files
authored
test Uri builder methods (#57549)
these assertions test the methods used to build URLs made by the `UrlGenerator`. these tests were added in addition to the feature in #57530. the feature was rejected, but figured I would try the tests separately.
1 parent cb047a6 commit f97d17b

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

tests/Support/SupportUriTest.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@
22

33
namespace Illuminate\Tests\Support;
44

5+
use Illuminate\Contracts\Routing\UrlGenerator;
56
use Illuminate\Support\Uri;
67
use PHPUnit\Framework\TestCase;
78

89
class SupportUriTest extends TestCase
910
{
11+
public function test_can_build_special_urls()
12+
{
13+
Uri::setUrlGeneratorResolver(fn () => new CustomUrlGeneratorResolver);
14+
15+
$this->assertEquals('https://laravel.com/to', Uri::to('')->value());
16+
$this->assertEquals('https://laravel.com/route', Uri::route('')->value());
17+
$this->assertEquals('https://laravel.com/signed-route', Uri::signedRoute('')->value());
18+
$this->assertEquals('https://laravel.com/signed-route', Uri::temporarySignedRoute('', '')->value());
19+
$this->assertEquals('https://laravel.com/action', Uri::action('')->value());
20+
}
21+
1022
public function test_basic_uri_interactions()
1123
{
1224
$uri = Uri::of($originalUri = 'https://laravel.com/docs/installation');
@@ -232,3 +244,66 @@ public function test_macroable()
232244
$this->assertSame('https://laravel.com/foobar', (string) $uri->myMacro());
233245
}
234246
}
247+
248+
class CustomUrlGeneratorResolver implements UrlGenerator
249+
{
250+
public function current()
251+
{
252+
return 'https://laravel.com/current';
253+
}
254+
255+
public function previous($fallback = false)
256+
{
257+
// TODO: Implement previous() method.
258+
}
259+
260+
public function to($path, $extra = [], $secure = null)
261+
{
262+
return 'https://laravel.com/to';
263+
}
264+
265+
public function secure($path, $parameters = [])
266+
{
267+
// TODO: Implement secure() method.
268+
}
269+
270+
public function asset($path, $secure = null)
271+
{
272+
// TODO: Implement asset() method.
273+
}
274+
275+
public function route($name, $parameters = [], $absolute = true)
276+
{
277+
return 'https://laravel.com/route';
278+
}
279+
280+
public function signedRoute($name, $parameters = [], $expiration = null, $absolute = true)
281+
{
282+
return 'https://laravel.com/signed-route';
283+
}
284+
285+
public function temporarySignedRoute($name, $expiration, $parameters = [], $absolute = true)
286+
{
287+
return 'https://laravel.com/temporary-signed-route';
288+
}
289+
290+
public function query($path, $query = [], $extra = [], $secure = null)
291+
{
292+
// TODO: Implement query() method.
293+
}
294+
295+
public function action($action, $parameters = [], $absolute = true)
296+
{
297+
return 'https://laravel.com/action';
298+
}
299+
300+
public function getRootControllerNamespace()
301+
{
302+
// TODO: Implement getRootControllerNamespace() method.
303+
}
304+
305+
public function setRootControllerNamespace($rootNamespace)
306+
{
307+
// TODO: Implement setRootControllerNamespace() method.
308+
}
309+
}

0 commit comments

Comments
 (0)