engelsystem/tests/Unit/Exceptions/ExceptionsServiceProviderTe...

110 lines
3.5 KiB
PHP
Raw Normal View History

2017-10-31 13:40:13 +01:00
<?php
namespace Engelsystem\Test\Unit\Exceptions;
2017-10-31 13:40:13 +01:00
use Engelsystem\Exceptions\ExceptionsServiceProvider;
2017-11-20 17:08:05 +01:00
use Engelsystem\Exceptions\Handler;
2017-11-24 15:08:43 +01:00
use Engelsystem\Exceptions\Handlers\HandlerInterface;
use Engelsystem\Exceptions\Handlers\Legacy;
use Engelsystem\Exceptions\Handlers\LegacyDevelopment;
use Engelsystem\Exceptions\Handlers\Whoops;
use Engelsystem\Http\Request;
2017-10-31 14:15:19 +01:00
use Engelsystem\Test\Unit\ServiceProviderTest;
use PHPUnit\Framework\MockObject\MockObject;
2017-10-31 13:40:13 +01:00
2017-10-31 14:15:19 +01:00
class ExceptionsServiceProviderTest extends ServiceProviderTest
2017-10-31 13:40:13 +01:00
{
/**
* @covers \Engelsystem\Exceptions\ExceptionsServiceProvider::register()
2017-11-24 15:08:43 +01:00
* @covers \Engelsystem\Exceptions\ExceptionsServiceProvider::addProductionHandler()
* @covers \Engelsystem\Exceptions\ExceptionsServiceProvider::addDevelopmentHandler()
2017-10-31 13:40:13 +01:00
*/
public function testRegister()
{
2017-11-24 15:08:43 +01:00
$app = $this->getApp(['make', 'instance', 'bind']);
/** @var Handler|MockObject $handler */
2017-11-24 15:08:43 +01:00
$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])
2017-10-31 13:40:13 +01:00
->getMock();
2017-11-24 15:08:43 +01:00
$app->expects($this->exactly(3))
->method('instance')
->withConsecutive(
['error.handler.production', $legacyHandler],
['error.handler.development', $whoopsHandler],
['error.handler', $handler]
);
2017-10-31 13:40:13 +01:00
2017-11-24 15:08:43 +01:00
$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]
);
2017-10-31 13:40:13 +01:00
$serviceProvider = new ExceptionsServiceProvider($app);
$serviceProvider->register();
}
2017-11-24 15:08:43 +01:00
/**
* @covers \Engelsystem\Exceptions\ExceptionsServiceProvider::boot()
*/
public function testBoot()
{
/** @var Handler|MockObject $handler */
2017-11-24 15:08:43 +01:00
$handler = $this->createMock(Handler::class);
/** @var Request|MockObject $request */
2017-11-24 15:08:43 +01:00
$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();
}
2017-10-31 13:40:13 +01:00
}