Skip to content

Commit

Permalink
Merge pull request #7 from pmall/add-push-handler
Browse files Browse the repository at this point in the history
allow to push handlers
  • Loading branch information
victorstanciu committed Oct 29, 2018
2 parents 6509c3b + 569bdbc commit 6372b1b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/SlashTrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public function addHandler(EventHandler $handler)
$this->handlers[] = $handler;
}

public function prependHandler(EventHandler $handler)
{
$this->checkUniqueHandler($handler);
array_unshift($this->handlers, $handler);
}

/**
* Checks that a particular handler hasn't already been registered
*
Expand Down Expand Up @@ -113,4 +119,4 @@ public function setApplicationPath($path)
$handler->setApplicationPath($path);
}
}
}
}
29 changes: 24 additions & 5 deletions tests/SlashTraceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,34 @@ public function testNoHandlersByDefault()

public function testCanAddHandlers()
{
$handler = $this->createMock(EventHandler::class);
$handler1 = $this->createMock(EventHandler::class);
$handler2 = $this->createMock(EventHandler::class);

/** @noinspection PhpParamsInspection */
$this->slashtrace->addHandler($handler);
$this->slashtrace->addHandler($handler1);
$this->slashtrace->addHandler($handler2);

$handlers = $this->slashtrace->getHandlers();

$this->assertEquals(2, count($handlers));
$this->assertSame($handler1, $handlers[0]);
$this->assertSame($handler2, $handlers[1]);
}

public function testCanPrependHandlers()
{
$handler1 = $this->createMock(EventHandler::class);
$handler2 = $this->createMock(EventHandler::class);

/** @noinspection PhpParamsInspection */
$this->slashtrace->prependHandler($handler1);
$this->slashtrace->prependHandler($handler2);

$handlers = $this->slashtrace->getHandlers();

$this->assertEquals(1, count($handlers));
$this->assertSame($handler, $handlers[0]);
$this->assertEquals(2, count($handlers));
$this->assertSame($handler2, $handlers[0]);
$this->assertSame($handler1, $handlers[1]);
}

public function testAddingTheSameHandlerTwiceRaisesException()
Expand Down Expand Up @@ -242,4 +261,4 @@ public function testInstallsHandlers()
$this->assertTrue(is_callable($this->system->getExceptionHandler()));
$this->assertTrue(is_callable($this->system->getShutdownFunction()));
}
}
}

0 comments on commit 6372b1b

Please sign in to comment.