Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 3865ba1

Browse files
committed
Ensure $fragmentIdentifier defaults to null
Prior to this, it defaulted to `''`, which is considered an invalid fragment under zend-expressive-helpers. It should properly default to `null` instead.
1 parent 1e0ef9c commit 3865ba1

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/UrlHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public function __construct(BaseHelper $helper)
2828
/**
2929
* Proxies to `Zend\Expressive\Helper\UrlHelper::generate()`
3030
*
31-
* @param string $routeName
31+
* @param null|string $routeName
3232
* @param array $routeParams
3333
* @param array $queryParams
34-
* @param string $fragmentIdentifier
34+
* @param null|string $fragmentIdentifier
3535
* @param array $options Can have the following keys:
3636
* - router (array): contains options to be passed to the router
3737
* - reuse_result_params (bool): indicates if the current RouteResult
@@ -42,7 +42,7 @@ public function __invoke(
4242
$routeName = null,
4343
array $routeParams = [],
4444
array $queryParams = [],
45-
$fragmentIdentifier = '',
45+
$fragmentIdentifier = null,
4646
array $options = []
4747
) {
4848
return $this->helper->generate($routeName, $routeParams, $queryParams, $fragmentIdentifier, $options);

test/UrlHelperTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function createHelper()
2525

2626
public function testInvocationProxiesToBaseHelper()
2727
{
28-
$this->baseHelper->generate('resource', ['id' => 'sha1'], [], '', [])->willReturn('/resource/sha1');
28+
$this->baseHelper->generate('resource', ['id' => 'sha1'], [], null, [])->willReturn('/resource/sha1');
2929
$helper = $this->createHelper();
3030
$this->assertEquals('/resource/sha1', $helper('resource', ['id' => 'sha1']));
3131
}
@@ -45,4 +45,23 @@ public function testUrlHelperAcceptsQueryParametersFragmentAndOptions()
4545
$helper('resource', ['id' => 'sha1'], ['foo' => 'bar'], 'fragment', ['reuse_result_params' => true])
4646
);
4747
}
48+
49+
/**
50+
* In particular, the fragment identifier needs to be null.
51+
*/
52+
public function testUrlHelperPassesExpectedDefaultsToBaseHelper()
53+
{
54+
$this->baseHelper->generate(
55+
null,
56+
[],
57+
[],
58+
null,
59+
[]
60+
)->willReturn('PATH');
61+
$helper = $this->createHelper();
62+
$this->assertEquals(
63+
'PATH',
64+
$helper()
65+
);
66+
}
4867
}

0 commit comments

Comments
 (0)