use events for budget calculation (#2544)

This commit is contained in:
Kevin Papst
2021-04-29 11:50:48 +02:00
committed by GitHub
parent bb94b11e37
commit e4b176a4d5
30 changed files with 384 additions and 92 deletions

View File

@@ -0,0 +1,36 @@
<?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\Event;
use App\Entity\Activity;
use App\Event\AbstractActivityEvent;
use App\Event\ActivityStatisticEvent;
use App\Model\ActivityStatistic;
/**
* @covers \App\Event\AbstractActivityEvent
* @covers \App\Event\ActivityStatisticEvent
*/
class ActivityStatisticEventTest extends AbstractActivityEventTest
{
protected function createActivityEvent(Activity $activity): AbstractActivityEvent
{
return new ActivityStatisticEvent($activity, new ActivityStatistic());
}
public function testStatistic()
{
$activity = new Activity();
$statistic = new ActivityStatistic();
$sut = new ActivityStatisticEvent($activity, $statistic);
self::assertSame($statistic, $sut->getStatistic());
}
}

View File

@@ -0,0 +1,36 @@
<?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\Event;
use App\Entity\Customer;
use App\Event\AbstractCustomerEvent;
use App\Event\CustomerStatisticEvent;
use App\Model\CustomerStatistic;
/**
* @covers \App\Event\AbstractCustomerEvent
* @covers \App\Event\CustomerStatisticEvent
*/
class CustomerStatisticEventTest extends AbstractCustomerEventTest
{
protected function createCustomerEvent(Customer $customer): AbstractCustomerEvent
{
return new CustomerStatisticEvent($customer, new CustomerStatistic());
}
public function testStatistic()
{
$customer = new Customer();
$statistic = new CustomerStatistic();
$sut = new CustomerStatisticEvent($customer, $statistic);
self::assertSame($statistic, $sut->getStatistic());
}
}

View File

@@ -0,0 +1,36 @@
<?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\Event;
use App\Entity\Project;
use App\Event\AbstractProjectEvent;
use App\Event\ProjectStatisticEvent;
use App\Model\ProjectStatistic;
/**
* @covers \App\Event\AbstractProjectEvent
* @covers \App\Event\ProjectStatisticEvent
*/
class ProjectStatisticEventTest extends AbstractProjectEventTest
{
protected function createProjectEvent(Project $project): AbstractProjectEvent
{
return new ProjectStatisticEvent($project, new ProjectStatistic());
}
public function testStatistic()
{
$project = new Project();
$statistic = new ProjectStatistic();
$sut = new ProjectStatisticEvent($project, $statistic);
self::assertSame($statistic, $sut->getStatistic());
}
}

View File

@@ -11,7 +11,7 @@ namespace App\Tests\Export\Renderer;
use App\Export\Renderer\HtmlRenderer;
use App\Export\Renderer\HtmlRendererFactory;
use App\Repository\ProjectRepository;
use App\Project\ProjectStatisticService;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Twig\Environment;
@@ -26,7 +26,7 @@ class HtmlRendererFactoryTest extends TestCase
$sut = new HtmlRendererFactory(
$this->createMock(Environment::class),
$this->createMock(EventDispatcherInterface::class),
$this->createMock(ProjectRepository::class)
$this->createMock(ProjectStatisticService::class)
);
$renderer = $sut->create('foo', 'bar.html.twig');

View File

@@ -10,7 +10,7 @@
namespace App\Tests\Export\Renderer;
use App\Export\Renderer\HtmlRenderer;
use App\Repository\ProjectRepository;
use App\Project\ProjectStatisticService;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Twig\Environment;
@@ -28,7 +28,7 @@ class HtmlRendererTest extends AbstractRendererTest
$sut = new HtmlRenderer(
$this->createMock(Environment::class),
new EventDispatcher(),
$this->createMock(ProjectRepository::class)
$this->createMock(ProjectStatisticService::class)
);
$this->assertEquals('html', $sut->getId());
@@ -46,7 +46,7 @@ class HtmlRendererTest extends AbstractRendererTest
$request->setLocale('en');
$stack->push($request);
$sut = new HtmlRenderer($twig, new EventDispatcher(), $this->createMock(ProjectRepository::class));
$sut = new HtmlRenderer($twig, new EventDispatcher(), $this->createMock(ProjectStatisticService::class));
$response = $this->render($sut);

View File

@@ -11,7 +11,7 @@ namespace App\Tests\Export\Renderer;
use App\Export\Renderer\PDFRenderer;
use App\Export\Renderer\PdfRendererFactory;
use App\Repository\ProjectRepository;
use App\Project\ProjectStatisticService;
use App\Utils\HtmlToPdfConverter;
use PHPUnit\Framework\TestCase;
use Twig\Environment;
@@ -26,7 +26,7 @@ class PdfRendererFactoryTest extends TestCase
$sut = new PdfRendererFactory(
$this->createMock(Environment::class),
$this->createMock(HtmlToPdfConverter::class),
$this->createMock(ProjectRepository::class)
$this->createMock(ProjectStatisticService::class)
);
$renderer = $sut->create('foo', 'bar.pdf.twig');

View File

@@ -10,7 +10,7 @@
namespace App\Tests\Export\Renderer;
use App\Export\Renderer\PDFRenderer;
use App\Repository\ProjectRepository;
use App\Project\ProjectStatisticService;
use App\Utils\HtmlToPdfConverter;
use App\Utils\MPdfConverter;
use Symfony\Component\HttpFoundation\Request;
@@ -29,7 +29,7 @@ class PdfRendererTest extends AbstractRendererTest
$sut = new PDFRenderer(
$this->createMock(Environment::class),
$this->createMock(HtmlToPdfConverter::class),
$this->createMock(ProjectRepository::class)
$this->createMock(ProjectStatisticService::class)
);
$this->assertEquals('pdf', $sut->getId());
@@ -54,7 +54,7 @@ class PdfRendererTest extends AbstractRendererTest
$request->setLocale('en');
$stack->push($request);
$sut = new PDFRenderer($twig, $converter, $this->createMock(ProjectRepository::class));
$sut = new PDFRenderer($twig, $converter, $this->createMock(ProjectStatisticService::class));
$response = $this->render($sut);

View File

@@ -12,7 +12,7 @@ namespace App\Tests\Export;
use App\Export\Renderer\HtmlRenderer;
use App\Export\ServiceExport;
use App\Export\Timesheet\HtmlRenderer as HtmlExporter;
use App\Repository\ProjectRepository;
use App\Project\ProjectStatisticService;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Twig\Environment;
@@ -37,7 +37,7 @@ class ServiceExportTest extends TestCase
{
$sut = new ServiceExport();
$renderer = new HtmlRenderer($this->createMock(Environment::class), new EventDispatcher(), $this->createMock(ProjectRepository::class));
$renderer = new HtmlRenderer($this->createMock(Environment::class), new EventDispatcher(), $this->createMock(ProjectStatisticService::class));
$sut->addRenderer($renderer);
self::assertEquals(1, \count($sut->getRenderer()));
@@ -48,7 +48,7 @@ class ServiceExportTest extends TestCase
{
$sut = new ServiceExport();
$exporter = new HtmlExporter($this->createMock(Environment::class), new EventDispatcher(), $this->createMock(ProjectRepository::class));
$exporter = new HtmlExporter($this->createMock(Environment::class), new EventDispatcher(), $this->createMock(ProjectStatisticService::class));
$sut->addTimesheetExporter($exporter);
self::assertEquals(1, \count($sut->getTimesheetExporter()));

View File

@@ -10,7 +10,7 @@
namespace App\Tests\Export\Timesheet;
use App\Export\Timesheet\HtmlRenderer;
use App\Repository\ProjectRepository;
use App\Project\ProjectStatisticService;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Twig\Environment;
@@ -26,7 +26,7 @@ class HtmlRendererTest extends AbstractRendererTest
$sut = new HtmlRenderer(
$this->createMock(Environment::class),
new EventDispatcher(),
$this->createMock(ProjectRepository::class)
$this->createMock(ProjectStatisticService::class)
);
$this->assertEquals('print', $sut->getId());
@@ -42,7 +42,7 @@ class HtmlRendererTest extends AbstractRendererTest
$request->setLocale('en');
$stack->push($request);
$sut = new HtmlRenderer($twig, new EventDispatcher(), $this->createMock(ProjectRepository::class));
$sut = new HtmlRenderer($twig, new EventDispatcher(), $this->createMock(ProjectStatisticService::class));
$response = $this->render($sut);

View File

@@ -10,7 +10,7 @@
namespace App\Tests\Export\Timesheet;
use App\Export\Timesheet\PDFRenderer;
use App\Repository\ProjectRepository;
use App\Project\ProjectStatisticService;
use App\Utils\HtmlToPdfConverter;
use App\Utils\MPdfConverter;
use Symfony\Component\HttpFoundation\Request;
@@ -29,7 +29,7 @@ class PdfRendererTest extends AbstractRendererTest
$sut = new PDFRenderer(
$this->createMock(Environment::class),
$this->createMock(HtmlToPdfConverter::class),
$this->createMock(ProjectRepository::class)
$this->createMock(ProjectStatisticService::class)
);
$this->assertEquals('pdf', $sut->getId());
@@ -47,7 +47,7 @@ class PdfRendererTest extends AbstractRendererTest
$request->setLocale('en');
$stack->push($request);
$sut = new PDFRenderer($twig, $converter, $this->createMock(ProjectRepository::class));
$sut = new PDFRenderer($twig, $converter, $this->createMock(ProjectStatisticService::class));
$response = $this->render($sut);

View File

@@ -9,7 +9,9 @@
namespace App\Tests\Validator;
use App\Activity\ActivityStatisticService;
use App\Configuration\SystemConfiguration;
use App\Customer\CustomerStatisticService;
use App\Entity\Activity;
use App\Entity\Customer;
use App\Entity\Project;
@@ -18,9 +20,7 @@ use App\Entity\User;
use App\Model\ActivityStatistic;
use App\Model\CustomerStatistic;
use App\Model\ProjectStatistic;
use App\Repository\ActivityRepository;
use App\Repository\CustomerRepository;
use App\Repository\ProjectRepository;
use App\Project\ProjectStatisticService;
use App\Repository\TimesheetRepository;
use App\Timesheet\Rate;
use App\Timesheet\RateService;
@@ -43,15 +43,15 @@ class TimesheetBudgetUsedValidatorTest extends ConstraintValidatorTestCase
$configuration = $this->createMock(SystemConfiguration::class);
$configuration->method('isTimesheetAllowOverbookingBudget')->willReturn($isAllowed);
$customerRepository = $this->createMock(CustomerRepository::class);
$customerRepository = $this->createMock(CustomerStatisticService::class);
$customerStatistic = $customerStatistic ?? new CustomerStatistic();
$customerRepository->method('getCustomerStatistics')->willReturn($customerStatistic);
$projectRepository = $this->createMock(ProjectRepository::class);
$projectRepository = $this->createMock(ProjectStatisticService::class);
$projectStatistic = $projectStatistic ?? new ProjectStatistic();
$projectRepository->method('getProjectStatistics')->willReturn($projectStatistic);
$activityRepository = $this->createMock(ActivityRepository::class);
$activityRepository = $this->createMock(ActivityStatisticService::class);
$activityStatistic = $activityStatistic ?? new ActivityStatistic();
$activityRepository->method('getActivityStatistics')->willReturn($activityStatistic);