events: extend system configurations and set invoice formatter (#1995)

This commit is contained in:
Kevin Papst
2020-09-25 19:51:23 +02:00
committed by GitHub
parent 23f484a14d
commit 2b033710e2
10 changed files with 119 additions and 41 deletions

View File

@@ -86,14 +86,13 @@ class FormConfigurationTest extends TestCase
$this->assertEquals('FR', $sut->find('defaults.customer.country'));
}
public function testUnknownConfigAreNotImportedAndFindingThemThrowsException()
public function testUnknownConfigAreImported()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Unknown config: foobar');
$sut = $this->getSut($this->getDefaultSettings(), [
(new Configuration())->setName('defaults.customer.foobar')->setValue('hello'),
]);
$this->assertTrue($sut->has('customer.foobar'));
$this->assertFalse($sut->has('xxxx.foobar'));
$this->assertEquals('hello', $sut->find('customer.foobar'));
}
}

View File

@@ -129,15 +129,14 @@ class SystemConfigurationTest extends TestCase
$this->assertEquals(false, $sut->find('timesheet.rules.allow_future_times'));
}
public function testUnknownConfigAreNotImportedAndFindingThemThrowsException()
public function testUnknownConfigs()
{
$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'));
$this->assertEquals('hello', $sut->find('timesheet.foo'));
$this->assertFalse($sut->has('xxxxxxxx.yyyyyyyyy'));
$this->assertNull($sut->find('xxxxxxxx.yyyyyyyyy'));
}
public function testCalendarWithoutLoader()

View File

@@ -116,14 +116,12 @@ class TimesheetConfigurationTest extends TestCase
$this->assertEquals(false, $sut->find('timesheet.rules.allow_future_times'));
}
public function testUnknownConfigAreNotImportedAndFindingThemThrowsException()
public function testUnknownConfigAreImported()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Unknown config: foo');
$sut = $this->getSut($this->getDefaultSettings(), [
(new Configuration())->setName('timesheet.foo')->setValue('hello'),
]);
$this->assertTrue($sut->has('foo'));
$this->assertEquals('hello', $sut->find('foo'));
}
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Form\Model;
use App\Form\Model\Configuration;
use App\Form\Model\SystemConfiguration;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Form\Model\SystemConfiguration
*/
class SystemConfigurationTest extends TestCase
{
public function testDefaultValues()
{
$sut = new SystemConfiguration();
self::assertNull($sut->getSection());
self::assertEquals([], $sut->getConfiguration());
}
public function testSetterAndGetter()
{
$sut = new SystemConfiguration();
self::assertInstanceOf(SystemConfiguration::class, $sut->setSection('foo'));
self::assertEquals('foo', $sut->getSection());
self::assertInstanceOf(SystemConfiguration::class, $sut->setConfiguration([]));
self::assertEquals([], $sut->getConfiguration());
$config = new Configuration();
self::assertInstanceOf(SystemConfiguration::class, $sut->setConfiguration([$config]));
self::assertEquals([$config], $sut->getConfiguration());
self::assertInstanceOf(SystemConfiguration::class, $sut->setConfiguration([$config, $config]));
self::assertEquals([$config, $config], $sut->getConfiguration());
self::assertInstanceOf(SystemConfiguration::class, $sut->addConfiguration($config));
self::assertEquals([$config, $config, $config], $sut->getConfiguration());
}
}

View File

@@ -41,6 +41,11 @@ class InvoiceModelTest extends TestCase
self::assertInstanceOf(\DateTime::class, $sut->getInvoiceDate());
self::assertSame($formatter, $sut->getFormatter());
$newFormatter = new DebugFormatter();
$sut->setFormatter($newFormatter);
self::assertNotSame($formatter, $sut->getFormatter());
self::assertSame($newFormatter, $sut->getFormatter());
}
public function testEmptyObjectThrowsExceptionOnNumberGenerator()