Skip to content

Commit

Permalink
Feat: Append params (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpolaszek authored Oct 5, 2022
1 parent 9f663a2 commit 9f56859
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/QueryString.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@ public function withParam(string $key, $value): self
* @param array $params
* @return QueryString
*/
public function withParams(array $params): self
public function withParams(array $params, bool $append = false): self
{
$clone = clone $this;
$clone->params = [];
if (!$append) {
$clone->params = [];
}
foreach ($params as $key => $value) {
$clone->params[(string) $key] = $value;
}
Expand Down
7 changes: 7 additions & 0 deletions tests/QueryStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ public function testReplaceParams(): void
$this->assertEquals(['bar' => 'baz'], $qs->getParams());
}

public function testAppendParams(): void
{
$qs = query_string(['foo' => 'bar']);
$qs = $qs->withParams(['bar' => 'baz'], true);
$this->assertEquals(['foo' => 'bar', 'bar' => 'baz'], $qs->getParams());
}

public function testSimpleGetParam(): void
{
$qs = query_string(['foo' => 'bar']);
Expand Down

0 comments on commit 9f56859

Please sign in to comment.