Configurable rate rounding (#5734)
* added invoice hydration of the issuer object * added "rate calculator" mode * new config to select rounding mode * replace static calls with dependency injection
This commit is contained in:
@@ -10,11 +10,12 @@
|
||||
namespace App\Tests\Mocks;
|
||||
|
||||
use PHPUnit\Framework\MockObject\MockBuilder;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
abstract class AbstractMockFactory
|
||||
{
|
||||
public function __construct(private TestCase $testCase)
|
||||
public function __construct(private readonly TestCase $testCase)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -23,11 +24,19 @@ abstract class AbstractMockFactory
|
||||
return $this->testCase;
|
||||
}
|
||||
|
||||
protected function createMock(string $className)
|
||||
/**
|
||||
* @template T of object
|
||||
* @param class-string<T> $className
|
||||
* @return T&MockObject
|
||||
*/
|
||||
protected function createMock(string $className): object
|
||||
{
|
||||
return $this->getMockBuilder($className)->disableOriginalConstructor()->getMock();
|
||||
return $this->getMockBuilder($className)->disableOriginalConstructor()->getMock(); // @phpstan-ignore return.type
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string $className
|
||||
*/
|
||||
protected function getMockBuilder(string $className): MockBuilder
|
||||
{
|
||||
return new MockBuilder($this->testCase, $className);
|
||||
|
||||
@@ -13,6 +13,7 @@ use App\Activity\ActivityStatisticService;
|
||||
use App\Customer\CustomerStatisticService;
|
||||
use App\Invoice\InvoiceModelFactory;
|
||||
use App\Project\ProjectStatisticService;
|
||||
use App\Timesheet\RateCalculator\DecimalRateCalculator;
|
||||
|
||||
class InvoiceModelFactoryFactory extends AbstractMockFactory
|
||||
{
|
||||
@@ -24,7 +25,8 @@ class InvoiceModelFactoryFactory extends AbstractMockFactory
|
||||
$projectStatistic = $this->getMockBuilder(ProjectStatisticService::class)->disableOriginalConstructor()->getMock();
|
||||
/** @var ActivityStatisticService $activityStatistic */
|
||||
$activityStatistic = $this->getMockBuilder(ActivityStatisticService::class)->disableOriginalConstructor()->getMock();
|
||||
$rateMode = new DecimalRateCalculator();
|
||||
|
||||
return new InvoiceModelFactory($customerStatistic, $projectStatistic, $activityStatistic);
|
||||
return new InvoiceModelFactory($customerStatistic, $projectStatistic, $activityStatistic, $rateMode);
|
||||
}
|
||||
}
|
||||
|
||||
27
tests/Mocks/RateServiceFactory.php
Normal file
27
tests/Mocks/RateServiceFactory.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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\Mocks;
|
||||
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Timesheet\RateCalculator\ClassicRateCalculator;
|
||||
use App\Timesheet\RateService;
|
||||
|
||||
class RateServiceFactory extends AbstractMockFactory
|
||||
{
|
||||
public function create(array $rules = [], array $rates = []): RateService
|
||||
{
|
||||
$mock = $this->createMock(TimesheetRepository::class);
|
||||
if (!empty($rates)) {
|
||||
$mock->expects($this->getTestCase()->any())->method('findMatchingRates')->willReturn($rates);
|
||||
}
|
||||
|
||||
return new RateService($rules, $mock, new ClassicRateCalculator());
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@ class SystemConfigurationFactory
|
||||
{
|
||||
/**
|
||||
* @param array<mixed> $settings
|
||||
* @return SystemConfiguration
|
||||
*/
|
||||
public static function create(ConfigLoaderInterface $repository, array $settings): SystemConfiguration
|
||||
{
|
||||
@@ -26,7 +25,6 @@ class SystemConfigurationFactory
|
||||
|
||||
/**
|
||||
* @param array<mixed> $settings
|
||||
* @return SystemConfiguration
|
||||
*/
|
||||
public static function createStub(array $settings = []): SystemConfiguration
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user