2020-04-21 11:53:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Helpers;
|
|
|
|
|
|
|
|
use Carbon\CarbonTimeZone;
|
|
|
|
use Engelsystem\Config\Config;
|
2020-04-21 12:39:54 +02:00
|
|
|
use Engelsystem\Exceptions\Handler;
|
2020-04-21 11:53:19 +02:00
|
|
|
use Engelsystem\Helpers\ConfigureEnvironmentServiceProvider;
|
|
|
|
use Engelsystem\Test\Unit\ServiceProviderTest;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
|
|
|
|
class ConfigureEnvironmentServiceProviderTest extends ServiceProviderTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Helpers\ConfigureEnvironmentServiceProvider::register
|
2020-04-21 12:39:54 +02:00
|
|
|
* @covers \Engelsystem\Helpers\ConfigureEnvironmentServiceProvider::setupDevErrorHandler
|
2020-04-21 11:53:19 +02:00
|
|
|
*/
|
|
|
|
public function testRegister(): void
|
|
|
|
{
|
2020-04-21 12:19:31 +02:00
|
|
|
$config = new Config(['timezone' => 'Australia/Eucla', 'environment' => 'production']);
|
2020-04-21 11:53:19 +02:00
|
|
|
$this->app->instance('config', $config);
|
|
|
|
|
2020-04-21 12:39:54 +02:00
|
|
|
$handler = new Handler();
|
|
|
|
$this->app->instance('error.handler', $handler);
|
|
|
|
|
2020-04-21 11:53:19 +02:00
|
|
|
/** @var ConfigureEnvironmentServiceProvider|MockObject $serviceProvider */
|
|
|
|
$serviceProvider = $this->getMockBuilder(ConfigureEnvironmentServiceProvider::class)
|
|
|
|
->setConstructorArgs([$this->app])
|
2020-04-21 12:19:31 +02:00
|
|
|
->onlyMethods(['setTimeZone', 'displayErrors', 'errorReporting'])
|
2020-04-21 11:53:19 +02:00
|
|
|
->getMock();
|
|
|
|
|
2020-04-21 12:19:31 +02:00
|
|
|
$serviceProvider->expects($this->exactly(2))
|
2020-04-21 11:53:19 +02:00
|
|
|
->method('setTimeZone')
|
|
|
|
->willReturnCallback(function (CarbonTimeZone $timeZone): void {
|
|
|
|
$this->assertEquals('Australia/Eucla', $timeZone->getName());
|
|
|
|
});
|
2020-04-21 12:19:31 +02:00
|
|
|
$serviceProvider->expects($this->exactly(3))
|
|
|
|
->method('displayErrors')
|
|
|
|
->withConsecutive([false], [false], [true]);
|
|
|
|
$serviceProvider->expects($this->exactly(1))
|
|
|
|
->method('errorReporting')
|
|
|
|
->with(E_ALL);
|
2020-04-21 11:53:19 +02:00
|
|
|
|
|
|
|
$serviceProvider->register();
|
2020-04-21 12:39:54 +02:00
|
|
|
$this->assertNotEquals(Handler::ENV_DEVELOPMENT, $handler->getEnvironment());
|
|
|
|
|
2020-04-21 12:19:31 +02:00
|
|
|
$config->set('environment', 'development');
|
|
|
|
$serviceProvider->register();
|
2020-04-21 12:39:54 +02:00
|
|
|
$this->assertEquals(Handler::ENV_DEVELOPMENT, $handler->getEnvironment());
|
2020-04-21 11:53:19 +02:00
|
|
|
}
|
|
|
|
}
|