summaryrefslogtreecommitdiff
path: root/tests/Unit/Exceptions/ExceptionsServiceProviderTest.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2017-11-24 15:08:43 +0100
committerIgor Scheller <igor.scheller@igorshp.de>2017-11-25 11:27:38 +0100
commit25e434bce4986b48bd72729a55aa1096e5a76be3 (patch)
treeb254fafaf789b4ebcc980fec8281675415706750 /tests/Unit/Exceptions/ExceptionsServiceProviderTest.php
parent6eea072376cc9fd1034342a0e1d2173681268138 (diff)
Refactored ExceptionHandler
Diffstat (limited to 'tests/Unit/Exceptions/ExceptionsServiceProviderTest.php')
-rw-r--r--tests/Unit/Exceptions/ExceptionsServiceProviderTest.php94
1 files changed, 86 insertions, 8 deletions
diff --git a/tests/Unit/Exceptions/ExceptionsServiceProviderTest.php b/tests/Unit/Exceptions/ExceptionsServiceProviderTest.php
index 01fb2f11..4f2ae654 100644
--- a/tests/Unit/Exceptions/ExceptionsServiceProviderTest.php
+++ b/tests/Unit/Exceptions/ExceptionsServiceProviderTest.php
@@ -2,30 +2,108 @@
namespace Engelsystem\Test\Unit\Exceptions;
-use Engelsystem\Exceptions\BasicHandler as ExceptionHandler;
use Engelsystem\Exceptions\ExceptionsServiceProvider;
use Engelsystem\Exceptions\Handler;
+use Engelsystem\Exceptions\Handlers\HandlerInterface;
+use Engelsystem\Exceptions\Handlers\Legacy;
+use Engelsystem\Exceptions\Handlers\LegacyDevelopment;
+use Engelsystem\Exceptions\Handlers\Whoops;
+use Engelsystem\Http\Request;
use Engelsystem\Test\Unit\ServiceProviderTest;
-use PHPUnit_Framework_MockObject_MockObject;
+use PHPUnit_Framework_MockObject_MockObject as MockObject;
class ExceptionsServiceProviderTest extends ServiceProviderTest
{
/**
* @covers \Engelsystem\Exceptions\ExceptionsServiceProvider::register()
+ * @covers \Engelsystem\Exceptions\ExceptionsServiceProvider::addProductionHandler()
+ * @covers \Engelsystem\Exceptions\ExceptionsServiceProvider::addDevelopmentHandler()
*/
public function testRegister()
{
- /** @var PHPUnit_Framework_MockObject_MockObject|ExceptionHandler $exceptionHandler */
- $exceptionHandler = $this->getMockBuilder(ExceptionHandler::class)
+ $app = $this->getApp(['make', 'instance', 'bind']);
+
+ /** @var MockObject|Handler $handler */
+ $handler = $this->createMock(Handler::class);
+ $this->setExpects($handler, 'register');
+ /** @var Legacy|MockObject $legacyHandler */
+ $legacyHandler = $this->createMock(Legacy::class);
+ /** @var LegacyDevelopment|MockObject $developmentHandler */
+ $developmentHandler = $this->createMock(LegacyDevelopment::class);
+
+ $whoopsHandler = $this->getMockBuilder(Whoops::class)
+ ->setConstructorArgs([$app])
->getMock();
- $app = $this->getApp(['make', 'instance', 'bind']);
+ $app->expects($this->exactly(3))
+ ->method('instance')
+ ->withConsecutive(
+ ['error.handler.production', $legacyHandler],
+ ['error.handler.development', $whoopsHandler],
+ ['error.handler', $handler]
+ );
- $this->setExpects($app, 'make', [ExceptionHandler::class], $exceptionHandler);
- $this->setExpects($app, 'instance', ['error.handler', $exceptionHandler]);
- $this->setExpects($app, 'bind', [Handler::class, 'error.handler']);
+ $app->expects($this->exactly(4))
+ ->method('make')
+ ->withConsecutive(
+ [Handler::class],
+ [Legacy::class],
+ [LegacyDevelopment::class],
+ [Whoops::class]
+ )
+ ->willReturnOnConsecutiveCalls(
+ $handler,
+ $legacyHandler,
+ $developmentHandler,
+ $whoopsHandler
+ );
+
+ $app->expects($this->exactly(2))
+ ->method('bind')
+ ->withConsecutive(
+ [HandlerInterface::class, 'error.handler.production'],
+ [Handler::class, 'error.handler']
+ );
+
+ $handler->expects($this->exactly(2))
+ ->method('setHandler')
+ ->withConsecutive(
+ [Handler::ENV_PRODUCTION, $legacyHandler],
+ [Handler::ENV_DEVELOPMENT, $whoopsHandler]
+ );
$serviceProvider = new ExceptionsServiceProvider($app);
$serviceProvider->register();
}
+
+ /**
+ * @covers \Engelsystem\Exceptions\ExceptionsServiceProvider::boot()
+ */
+ public function testBoot()
+ {
+ /** @var MockObject|Handler $handler */
+ $handler = $this->createMock(Handler::class);
+
+ /** @var MockObject|Request $request */
+ $request = $this->createMock(Request::class);
+
+ $handler->expects($this->once())
+ ->method('setRequest')
+ ->with($request);
+
+ $app = $this->getApp(['get']);
+ $app->expects($this->exactly(2))
+ ->method('get')
+ ->withConsecutive(
+ ['error.handler'],
+ ['request']
+ )
+ ->willReturnOnConsecutiveCalls(
+ $handler,
+ $request
+ );
+
+ $provider = new ExceptionsServiceProvider($app);
+ $provider->boot();
+ }
}