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:
Kevin Papst
2025-12-16 16:47:46 +01:00
committed by GitHub
parent 07ac6c308f
commit 595b5f4b25
43 changed files with 876 additions and 411 deletions

View File

@@ -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);

View File

@@ -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);
}
}

View 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());
}
}

View File

@@ -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
{