diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2018-09-25 17:33:31 +0200 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2018-10-30 21:13:56 +0100 |
commit | 7f61dc95be4ac543986c7df2459532fd8f81368d (patch) | |
tree | 930497c659bbaa3e073313a261f3458348fd423d /tests/Unit/Config | |
parent | 63d1292bf80d88be40eec7695c1a59f29e6609c5 (diff) |
EventConfig: Merge event configuration from database to global config
Diffstat (limited to 'tests/Unit/Config')
-rw-r--r-- | tests/Unit/Config/ConfigServiceProviderTest.php | 81 |
1 files changed, 74 insertions, 7 deletions
diff --git a/tests/Unit/Config/ConfigServiceProviderTest.php b/tests/Unit/Config/ConfigServiceProviderTest.php index 925854be..b93e1b97 100644 --- a/tests/Unit/Config/ConfigServiceProviderTest.php +++ b/tests/Unit/Config/ConfigServiceProviderTest.php @@ -5,18 +5,22 @@ namespace Engelsystem\Test\Unit\Config; use Engelsystem\Application; use Engelsystem\Config\Config; use Engelsystem\Config\ConfigServiceProvider; +use Engelsystem\Models\EventConfig; use Engelsystem\Test\Unit\ServiceProviderTest; use Exception; -use PHPUnit_Framework_MockObject_MockObject; +use Illuminate\Database\Eloquent\Builder as EloquentBuilder; +use Illuminate\Database\QueryException; +use PHPUnit\Framework\MockObject\MockObject; class ConfigServiceProviderTest extends ServiceProviderTest { /** - * @covers \Engelsystem\Config\ConfigServiceProvider::register() + * @covers \Engelsystem\Config\ConfigServiceProvider::register + * @covers \Engelsystem\Config\ConfigServiceProvider::getConfigPath */ public function testRegister() { - /** @var PHPUnit_Framework_MockObject_MockObject|Config $config */ + /** @var MockObject|Config $config */ $config = $this->getMockBuilder(Config::class) ->getMock(); @@ -53,11 +57,11 @@ class ConfigServiceProviderTest extends ServiceProviderTest } /** - * @covers \Engelsystem\Config\ConfigServiceProvider::register() + * @covers \Engelsystem\Config\ConfigServiceProvider::register */ public function testRegisterException() { - /** @var PHPUnit_Framework_MockObject_MockObject|Config $config */ + /** @var MockObject|Config $config */ $config = $this->getMockBuilder(Config::class) ->getMock(); @@ -68,8 +72,8 @@ class ConfigServiceProviderTest extends ServiceProviderTest $app->expects($this->exactly(2)) ->method('instance') ->withConsecutive( - [Config::class, $config], - ['config', $config] + [Config::class, $config], + ['config', $config] ); $this->setExpects($app, 'get', ['path.config'], __DIR__ . '/not_existing', $this->atLeastOnce()); @@ -81,4 +85,67 @@ class ConfigServiceProviderTest extends ServiceProviderTest $serviceProvider = new ConfigServiceProvider($app); $serviceProvider->register(); } + + /** + * @covers \Engelsystem\Config\ConfigServiceProvider::__construct + * @covers \Engelsystem\Config\ConfigServiceProvider::boot + */ + public function testBoot() + { + $app = $this->getApp(['get']); + + /** @var EventConfig|MockObject $eventConfig */ + $eventConfig = $this->createMock(EventConfig::class); + /** @var EloquentBuilder|MockObject $eloquentBuilder */ + $eloquentBuilder = $this->getMockBuilder(EloquentBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $config = new Config(['foo' => 'bar', 'lorem' => ['ipsum' => 'dolor', 'bla' => 'foo']]); + + $configs = [ + new EventConfig(['name' => 'test', 'value' => 'testing']), + new EventConfig(['name' => 'lorem', 'value' => ['ipsum' => 'tester']]), + ]; + + $returnValue = $eloquentBuilder; + $eventConfig + ->expects($this->exactly(3)) + ->method('newQuery') + ->willReturnCallback(function () use (&$returnValue) { + if ($returnValue instanceof EloquentBuilder) { + $return = $returnValue; + $returnValue = null; + return $return; + } + + if (is_null($returnValue)) { + throw new QueryException('', [], new Exception()); + } + + return null; + }); + + $this->setExpects($eloquentBuilder, 'get', [['name', 'value']], $configs); + $this->setExpects($app, 'get', ['config'], $config, $this->exactly(3)); + + $serviceProvider = new ConfigServiceProvider($app); + $serviceProvider->boot(); + + $serviceProvider = new ConfigServiceProvider($app, $eventConfig); + $serviceProvider->boot(); + $serviceProvider->boot(); + $serviceProvider->boot(); + + $this->assertArraySubset( + [ + 'foo' => 'bar', + 'lorem' => [ + 'ipsum' => 'tester', + 'bla' => 'foo', + ], + 'test' => 'testing', + ], + $config->get(null) + ); + } } |