Commit 010caf20 authored by Timo Hund's avatar Timo Hund Committed by Markus Kalkbrenner

[TASK] Add method removeParam to AbstractQuery (#617)

* Add's the method removeParam to the AbstractQuery class
* Add's unit tests for the method

Fixes: #579
parent 6ab37266
...@@ -156,6 +156,24 @@ abstract class AbstractQuery extends Configurable implements QueryInterface ...@@ -156,6 +156,24 @@ abstract class AbstractQuery extends Configurable implements QueryInterface
return $this; return $this;
} }
/**
* Removes a param that was previously added by addParam.
*
* Note: This can not be used to remove known default parameters of the solarium api.
*
* @param string $name
*
* @return self Provides fluent interface
*/
public function removeParam($name)
{
if (isset($this->params[$name])) {
unset($this->params[$name]);
}
return $this;
}
/** /**
* Get extra params. * Get extra params.
* *
......
...@@ -45,6 +45,22 @@ class QueryTest extends TestCase ...@@ -45,6 +45,22 @@ class QueryTest extends TestCase
); );
} }
public function testAddAndRemoveParam()
{
$query = new TestQuery();
$query->addParam('foo', 'bar');
$this->assertSame('bar', $query->getParams()['foo']);
$query->removeParam('foo');
$this->assertEmpty($query->getParams());
}
public function testRemoveUnknownParamDoesNotTriggerError()
{
$query = new TestQuery();
$query->removeParam('unknown');
$this->assertEmpty($query->getParams());
}
public function testGetDefaultResponseWriter() public function testGetDefaultResponseWriter()
{ {
$query = new TestQuery(); $query = new TestQuery();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment