removeFirstHandler and removeLastHandler

This commit is contained in:
Denis Sokolov
2019-12-29 12:00:00 +02:00
parent 6b4c19e941
commit 48810fbdb5
2 changed files with 42 additions and 2 deletions
+18 -2
View File
@@ -72,8 +72,7 @@ final class Run implements RunInterface
}
/**
* Removes the last handler in the stack and returns it.
* Returns null if there"s nothing else to pop.
* See removeFirstHandler and removeLastHandler
* @return null|HandlerInterface
*/
public function popHandler()
@@ -81,6 +80,23 @@ final class Run implements RunInterface
return array_pop($this->handlerStack);
}
/**
* Removes the first handler
*/
public function removeFirstHandler()
{
array_pop($this->handlerStack);
}
/**
* Removes the last handler
*/
public function removeLastHandler()
{
array_shift($this->handlerStack);
}
/**
* Returns an array with all handlers, in the
* order they were added to the stack.
+24
View File
@@ -141,6 +141,30 @@ class RunTest extends TestCase
$this->assertEmpty($run->getHandlers());
}
/**
* @covers Whoops\Run::removeFirstHandler
* @covers Whoops\Run::removeLastHandler
* @covers Whoops\Run::getHandlers
*/
public function testRemoveHandler()
{
$run = $this->getRunInstance();
$handlerOne = $this->getHandler();
$handlerTwo = $this->getHandler();
$handlerThree = $this->getHandler();
$run->pushHandler($handlerOne);
$run->pushHandler($handlerTwo);
$run->pushHandler($handlerThree);
$run->removeLastHandler();
$this->assertSame($handlerTwo, $run->getHandlers()[0]);
$run->removeFirstHandler();
$this->assertSame($handlerTwo, $run->getHandlers()[0]);
$this->assertCount(1, $run->getHandlers());
}
/**
* @covers Whoops\Run::register
*/