diff options
author | msquare <msquare@notrademark.de> | 2017-11-26 11:07:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-26 11:07:27 +0100 |
commit | eda7f7788ea8012bd8be46405c56a666c11f3fa5 (patch) | |
tree | 50cf84d7d07d11bd65b45c2c17f37632f6cd8eff /tests/Unit/Exceptions/ExceptionsServiceProviderTest.php | |
parent | e54a10b81679bae9d19337617d6c58310d2f7a58 (diff) | |
parent | b9bc03a1bdf146e0b4ef6529ebe814a0ac9c930d (diff) |
Merge pull request #364 from MyIgel/master
Refactored error handling, changed tests from MySQL to MariaDB
Diffstat (limited to 'tests/Unit/Exceptions/ExceptionsServiceProviderTest.php')
-rw-r--r-- | tests/Unit/Exceptions/ExceptionsServiceProviderTest.php | 94 |
1 files changed, 87 insertions, 7 deletions
diff --git a/tests/Unit/Exceptions/ExceptionsServiceProviderTest.php b/tests/Unit/Exceptions/ExceptionsServiceProviderTest.php index 9c943d52..4f2ae654 100644 --- a/tests/Unit/Exceptions/ExceptionsServiceProviderTest.php +++ b/tests/Unit/Exceptions/ExceptionsServiceProviderTest.php @@ -3,27 +3,107 @@ namespace Engelsystem\Test\Unit\Exceptions; use Engelsystem\Exceptions\ExceptionsServiceProvider; -use Engelsystem\Exceptions\Handler as ExceptionHandler; +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(); + $app->expects($this->exactly(3)) + ->method('instance') + ->withConsecutive( + ['error.handler.production', $legacyHandler], + ['error.handler.development', $whoopsHandler], + ['error.handler', $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'] + ); - $this->setExpects($app, 'make', [ExceptionHandler::class], $exceptionHandler); - $this->setExpects($app, 'instance', ['error.handler', $exceptionHandler]); + $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(); + } } |