2017-10-31 13:40:13 +01:00
|
|
|
<?php
|
|
|
|
|
2017-10-31 14:23:23 +01:00
|
|
|
namespace Engelsystem\Test\Unit\Config;
|
2017-10-31 13:40:13 +01:00
|
|
|
|
|
|
|
use Engelsystem\Application;
|
|
|
|
use Engelsystem\Config\Config;
|
|
|
|
use Engelsystem\Config\ConfigServiceProvider;
|
2017-10-31 14:15:19 +01:00
|
|
|
use Engelsystem\Test\Unit\ServiceProviderTest;
|
2018-08-10 15:02:07 +02:00
|
|
|
use Exception;
|
2017-10-31 13:40:13 +01:00
|
|
|
use PHPUnit_Framework_MockObject_MockObject;
|
|
|
|
|
2017-10-31 14:15:19 +01:00
|
|
|
class ConfigServiceProviderTest extends ServiceProviderTest
|
2017-10-31 13:40:13 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Config\ConfigServiceProvider::register()
|
|
|
|
*/
|
|
|
|
public function testRegister()
|
|
|
|
{
|
|
|
|
/** @var PHPUnit_Framework_MockObject_MockObject|Config $config */
|
|
|
|
$config = $this->getMockBuilder(Config::class)
|
|
|
|
->getMock();
|
|
|
|
|
2017-10-31 14:15:19 +01:00
|
|
|
$app = $this->getApp(['make', 'instance', 'get']);
|
2017-10-31 13:40:13 +01:00
|
|
|
Application::setInstance($app);
|
|
|
|
|
2017-10-31 14:15:19 +01:00
|
|
|
$this->setExpects($app, 'make', [Config::class], $config);
|
|
|
|
$this->setExpects($app, 'instance', ['config', $config]);
|
|
|
|
$this->setExpects($app, 'get', ['path.config'], __DIR__ . '/../../../config', $this->atLeastOnce());
|
2017-10-31 13:40:13 +01:00
|
|
|
|
2017-10-31 14:15:19 +01:00
|
|
|
$this->setExpects($config, 'set', null, null, $this->exactly(2));
|
2018-08-10 15:02:07 +02:00
|
|
|
$config->expects($this->exactly(3))
|
|
|
|
->method('get')
|
|
|
|
->with(null)
|
|
|
|
->willReturnOnConsecutiveCalls([], [], ['lor' => 'em']);
|
2017-10-31 13:40:13 +01:00
|
|
|
|
2017-10-31 15:13:37 +01:00
|
|
|
$configFile = __DIR__ . '/../../../config/config.php';
|
|
|
|
$configExists = file_exists($configFile);
|
|
|
|
if (!$configExists) {
|
2018-08-10 15:02:07 +02:00
|
|
|
file_put_contents($configFile, '<?php return ["lor"=>"em"];');
|
2017-10-31 15:13:37 +01:00
|
|
|
}
|
|
|
|
|
2017-10-31 13:40:13 +01:00
|
|
|
$serviceProvider = new ConfigServiceProvider($app);
|
|
|
|
$serviceProvider->register();
|
2017-10-31 15:13:37 +01:00
|
|
|
|
|
|
|
if (!$configExists) {
|
|
|
|
unlink($configFile);
|
|
|
|
}
|
2017-10-31 13:40:13 +01:00
|
|
|
}
|
2018-08-10 15:02:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Config\ConfigServiceProvider::register()
|
|
|
|
*/
|
|
|
|
public function testRegisterException()
|
|
|
|
{
|
|
|
|
/** @var PHPUnit_Framework_MockObject_MockObject|Config $config */
|
|
|
|
$config = $this->getMockBuilder(Config::class)
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$app = $this->getApp(['make', 'instance', 'get']);
|
|
|
|
Application::setInstance($app);
|
|
|
|
|
|
|
|
$this->setExpects($app, 'make', [Config::class], $config);
|
|
|
|
$this->setExpects($app, 'instance', ['config', $config]);
|
|
|
|
$this->setExpects($app, 'get', ['path.config'], __DIR__ . '/not_existing', $this->atLeastOnce());
|
|
|
|
|
|
|
|
$this->setExpects($config, 'set', null, null, $this->never());
|
|
|
|
$this->setExpects($config, 'get', [null], []);
|
|
|
|
|
|
|
|
$this->expectException(Exception::class);
|
|
|
|
|
|
|
|
$serviceProvider = new ConfigServiceProvider($app);
|
|
|
|
$serviceProvider->register();
|
|
|
|
}
|
2017-10-31 13:40:13 +01:00
|
|
|
}
|