Skip to content

Commit

Permalink
removeFirstHandler and removeLastHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-sokolov committed Dec 29, 2019
1 parent 6b4c19e commit 48810fb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Whoops/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,31 @@ public function pushHandler($handler)
}

/**
* 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()
{
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.
Expand Down
24 changes: 24 additions & 0 deletions tests/Whoops/RunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,30 @@ public function testPopHandler()
$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
*/
Expand Down

0 comments on commit 48810fb

Please sign in to comment.