[ 'rules' => [ 'allow_future_times' => false, ], 'mode' => 'duration_only', 'markdown_content' => false, 'active_entries' => [ 'hard_limit' => 99, 'soft_limit' => 15, ], ], 'defaults' => [ 'customer' => [ 'timezone' => 'Europe/London', 'currency' => 'GBP', 'country' => 'FR', ], ], ]; } protected function getDefaultLoaderSettings() { return [ (new Configuration())->setName('defaults.customer.timezone')->setValue('Russia/Moscov'), (new Configuration())->setName('defaults.customer.currency')->setValue('RUB'), (new Configuration())->setName('timesheet.rules.allow_future_times')->setValue('1'), (new Configuration())->setName('timesheet.mode')->setValue('default'), (new Configuration())->setName('timesheet.markdown_content')->setValue('1'), (new Configuration())->setName('timesheet.active_entries.hard_limit')->setValue('7'), (new Configuration())->setName('timesheet.active_entries.soft_limit')->setValue('3'), ]; } public function testPrefix() { $sut = $this->getSut($this->getDefaultSettings(), []); $this->assertEquals('kimai', $sut->getPrefix()); } public function testDefaultWithoutLoader() { $sut = $this->getSut($this->getDefaultSettings(), []); $this->assertEquals('Europe/London', $sut->find('defaults.customer.timezone')); $this->assertEquals('GBP', $sut->find('defaults.customer.currency')); $this->assertEquals(false, $sut->find('timesheet.rules.allow_future_times')); $this->assertEquals(99, $sut->find('timesheet.active_entries.hard_limit')); } public function testDefaultWithLoader() { $sut = $this->getSut($this->getDefaultSettings(), $this->getDefaultLoaderSettings()); $this->assertEquals('Russia/Moscov', $sut->find('defaults.customer.timezone')); $this->assertEquals('RUB', $sut->find('defaults.customer.currency')); $this->assertEquals(true, $sut->find('timesheet.rules.allow_future_times')); $this->assertEquals(7, $sut->find('timesheet.active_entries.hard_limit')); } public function testDefaultWithMixedConfigs() { $sut = $this->getSut($this->getDefaultSettings(), [ (new Configuration())->setName('timesheet.rules.allow_future_times')->setValue(''), ]); $this->assertEquals(false, $sut->find('timesheet.rules.allow_future_times')); } public function testUnknownConfigAreNotImportedAndFindingThemThrowsException() { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Unknown config: foo'); $sut = $this->getSut($this->getDefaultSettings(), [ (new Configuration())->setName('timesheet.foo')->setValue('hello'), ]); $this->assertEquals('hello', $sut->find('foo')); } }