Release 2.33.0 (#5438)

This commit is contained in:
Kevin Papst
2025-04-22 20:43:22 +02:00
committed by GitHub
parent a70c803158
commit e663cc2b02
58 changed files with 1404 additions and 899 deletions

View File

@@ -35,7 +35,8 @@ class ActivityServiceTest extends TestCase
private function getSut(
?EventDispatcherInterface $dispatcher = null,
?ValidatorInterface $validator = null,
?ActivityRepository $repository = null
?ActivityRepository $repository = null,
array $configuration = []
): ActivityService {
if ($repository === null) {
$repository = $this->createMock(ActivityRepository::class);
@@ -50,7 +51,7 @@ class ActivityServiceTest extends TestCase
$validator->method('validate')->willReturn(new ConstraintViolationList());
}
$configuration = SystemConfigurationFactory::createStub(['activity' => []]);
$configuration = SystemConfigurationFactory::createStub(['activity' => $configuration]);
$service = new ActivityService($repository, $configuration, $dispatcher, $validator);
@@ -155,4 +156,71 @@ class ActivityServiceTest extends TestCase
$project = $sut->createNewActivity();
self::assertNull($project->getProject());
}
/**
* @dataProvider getTestData
*/
public function testActivityNumber(string $format, int|string $expected): void
{
$sut = $this->getSut(null, null, null, ['number_format' => $format]);
$activity = $sut->createNewActivity();
self::assertEquals((string) $expected, $activity->getNumber());
}
/**
* @return array<int, array<int, string|\DateTime|int>>
*/
public static function getTestData(): array
{
$dateTime = new \DateTime();
$yearLong = (int) $dateTime->format('Y');
$yearShort = (int) $dateTime->format('y');
$monthLong = $dateTime->format('m');
$monthShort = (int) $dateTime->format('n');
$dayLong = $dateTime->format('d');
$dayShort = (int) $dateTime->format('j');
return [
// simple tests for single calls
['{ac,1}', '2'],
['{ac,2}', '02'],
['{ac,3}', '002'],
['{ac,4}', '0002'],
['{Y}', $yearLong],
['{y}', $yearShort],
['{M}', $monthLong],
['{m}', $monthShort],
['{D}', $dayLong],
['{d}', $dayShort],
// number formatting (not testing the lower case versions, as the tests might break depending on the date)
['{Y,6}', '00' . $yearLong],
['{M,3}', '0' . $monthLong],
['{D,3}', '0' . $dayLong],
// increment dates
['{YY}', $yearLong + 1],
['{YY+1}', $yearLong + 1],
['{YY+2}', $yearLong + 2],
['{YY+3}', $yearLong + 3],
['{YY-1}', $yearLong - 1],
['{YY-2}', $yearLong - 2],
['{YY-3}', $yearLong - 3],
['{yy}', $yearShort + 1],
['{yy+1}', $yearShort + 1],
['{yy+2}', $yearShort + 2],
['{yy+3}', $yearShort + 3],
['{yy-1}', $yearShort - 1],
['{yy-2}', $yearShort - 2],
['{yy-3}', $yearShort - 3],
['{MM}', $monthShort + 1], // cast to int removes leading zero
['{MM+1}', $monthShort + 1], // cast to int removes leading zero
['{MM+2}', $monthShort + 2], // cast to int removes leading zero
['{MM+3}', $monthShort + 3], // cast to int removes leading zero
['{DD}', $dayShort + 1], // cast to int removes leading zero
['{DD+1}', $dayShort + 1], // cast to int removes leading zero
['{DD+2}', $dayShort + 2], // cast to int removes leading zero
['{DD+3}', $dayShort + 3], // cast to int removes leading zero
];
}
}

View File

@@ -157,4 +157,84 @@ class CustomerServiceTest extends TestCase
$Customer = new Customer('foo');
$sut->saveNewCustomer($Customer);
}
/**
* @dataProvider getTestData
*/
public function testCustomerNumber(string $format, int|string $expected): void
{
$configuration = SystemConfigurationFactory::createStub([
'defaults' => [
'customer' => [
'timezone' => 'Europe/Vienna',
'country' => 'IN',
'currency' => 'RUB',
]
],
'customer' => [
'number_format' => $format
]
]);
$sut = $this->getSut(null, null, null, $configuration);
$customer = $sut->createNewCustomer('Test');
self::assertEquals((string) $expected, $customer->getNumber());
}
/**
* @return array<int, array<int, string|\DateTime|int>>
*/
public static function getTestData(): array
{
$dateTime = new \DateTime();
$yearLong = (int) $dateTime->format('Y');
$yearShort = (int) $dateTime->format('y');
$monthLong = $dateTime->format('m');
$monthShort = (int) $dateTime->format('n');
$dayLong = $dateTime->format('d');
$dayShort = (int) $dateTime->format('j');
return [
// simple tests for single calls
['{cc,1}', '2'],
['{cc,2}', '02'],
['{cc,3}', '002'],
['{cc,4}', '0002'],
['{Y}', $yearLong],
['{y}', $yearShort],
['{M}', $monthLong],
['{m}', $monthShort],
['{D}', $dayLong],
['{d}', $dayShort],
// number formatting (not testing the lower case versions, as the tests might break depending on the date)
['{Y,6}', '00' . $yearLong],
['{M,3}', '0' . $monthLong],
['{D,3}', '0' . $dayLong],
// increment dates
['{YY}', $yearLong + 1],
['{YY+1}', $yearLong + 1],
['{YY+2}', $yearLong + 2],
['{YY+3}', $yearLong + 3],
['{YY-1}', $yearLong - 1],
['{YY-2}', $yearLong - 2],
['{YY-3}', $yearLong - 3],
['{yy}', $yearShort + 1],
['{yy+1}', $yearShort + 1],
['{yy+2}', $yearShort + 2],
['{yy+3}', $yearShort + 3],
['{yy-1}', $yearShort - 1],
['{yy-2}', $yearShort - 2],
['{yy-3}', $yearShort - 3],
['{MM}', $monthShort + 1], // cast to int removes leading zero
['{MM+1}', $monthShort + 1], // cast to int removes leading zero
['{MM+2}', $monthShort + 2], // cast to int removes leading zero
['{MM+3}', $monthShort + 3], // cast to int removes leading zero
['{DD}', $dayShort + 1], // cast to int removes leading zero
['{DD+1}', $dayShort + 1], // cast to int removes leading zero
['{DD+2}', $dayShort + 2], // cast to int removes leading zero
['{DD+3}', $dayShort + 3], // cast to int removes leading zero
];
}
}

View File

@@ -173,15 +173,13 @@ class InvoiceTest extends TestCase
$user1->method('getUsername')->willReturn('foo-bar');
$timesheet = new Timesheet();
$timesheet
->setDuration(3600)
->setRate(293.27)
->setUser($user1)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
;
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser($user1);
$timesheet->setActivity($activity);
$timesheet->setProject($project);
$timesheet->setBegin(new \DateTime());
$timesheet->setEnd(new \DateTime());
$entries = [$timesheet];

View File

@@ -28,10 +28,13 @@ use Symfony\Contracts\Translation\TranslatorInterface;
*/
class CsvRendererTest extends AbstractRendererTestCase
{
protected function getAbstractRenderer(): CsvRenderer
protected function getAbstractRenderer(bool $exportDecimal = false): CsvRenderer
{
$user = $this->createMock(User::class);
$user->expects($this->any())->method('isExportDecimal')->willReturn($exportDecimal);
$security = $this->createMock(Security::class);
$security->expects($this->any())->method('getUser')->willReturn(new User());
$security->expects($this->any())->method('getUser')->willReturn($user);
$security->expects($this->any())->method('isGranted')->willReturn(true);
$translator = $this->createMock(TranslatorInterface::class);
@@ -53,16 +56,17 @@ class CsvRendererTest extends AbstractRendererTestCase
public static function getTestModel(): array
{
return [
['400', '2437.12', '1947.99', 7, 6, 1, 2, 2]
['400', '2437.12', '1947.99', 7, 6, 1, 2, 2, false],
['400', '2437.12', '1947.99', 7, 6, 1, 2, 2, true]
];
}
/**
* @dataProvider getTestModel
*/
public function testRender(string $totalDuration, string $totalRate, string $expectedRate, int $expectedRows, int $expectedDescriptions, int $expectedUser1, int $expectedUser2, int $expectedUser3): void
public function testRender(string $totalDuration, string $totalRate, string $expectedRate, int $expectedRows, int $expectedDescriptions, int $expectedUser1, int $expectedUser2, int $expectedUser3, bool $exportDecimal): void
{
$sut = $this->getAbstractRenderer();
$sut = $this->getAbstractRenderer($exportDecimal);
/** @var BinaryFileResponse $response */
$response = $this->render($sut);
@@ -102,7 +106,7 @@ class CsvRendererTest extends AbstractRendererTestCase
'2019-06-16',
'12:00',
'12:06',
'0:06',
($exportDecimal ? '0.11' : '0:06:40'),
//'0.11',
'EUR',
'0',
@@ -136,7 +140,7 @@ class CsvRendererTest extends AbstractRendererTestCase
'2019-06-16',
'12:00',
'12:06',
'0:06',
($exportDecimal ? '0.11' : '0:06:40'),
//'0.11',
'EUR',
'0',

View File

@@ -17,6 +17,12 @@ use PHPUnit\Framework\TestCase;
*/
class DateFormatterTest extends TestCase
{
public function testGetFormat(): void
{
$formatter = new DateFormatter();
self::assertEquals('yyyy-mm-dd', $formatter->getFormat());
}
public function testFormatValueReturnsFormattedDateForDateTime(): void
{
$formatter = new DateFormatter();

View File

@@ -17,38 +17,57 @@ use PHPUnit\Framework\TestCase;
*/
class DurationFormatterTest extends TestCase
{
public function testGetFormat(): void
{
$formatter = new DurationFormatter();
self::assertEquals('[hh]:mm:ss', $formatter->getFormat());
}
public function testFormatValueReturnsFormattedDurationQuiteLong(): void
{
$formatter = new DurationFormatter();
$result = $formatter->formatValue(701213);
self::assertInstanceOf(\DateInterval::class, $result);
self::assertEquals('194:46:53', $result->format('%r%H:%I:%S'));
}
public function testFormatValueReturnsFormattedDurationForNumericValue(): void
{
$formatter = new DurationFormatter();
$result = $formatter->formatValue(7200);
self::assertEquals('2:00', $result);
$result = $formatter->formatValue(7213);
self::assertInstanceOf(\DateInterval::class, $result);
self::assertEquals('02:00:13', $result->format('%r%H:%I:%S'));
}
public function testFormatValueReturnsZeroForNonNumericValue(): void
{
$formatter = new DurationFormatter();
$result = $formatter->formatValue('not a number');
self::assertEquals('0:00', $result);
self::assertInstanceOf(\DateInterval::class, $result);
self::assertEquals('00:00:00', $result->format('%r%H:%I:%S'));
}
public function testFormatValueReturnsFormattedDurationForFloatValue(): void
{
$formatter = new DurationFormatter();
$result = $formatter->formatValue(4500.5);
self::assertEquals('1:15', $result);
$result = $formatter->formatValue(4521.5);
self::assertInstanceOf(\DateInterval::class, $result);
self::assertEquals('01:15:21', $result->format('%r%H:%I:%S'));
}
public function testFormatValueReturnsZeroForNullValue(): void
{
$formatter = new DurationFormatter();
$result = $formatter->formatValue(null);
self::assertEquals('0:00', $result);
self::assertInstanceOf(\DateInterval::class, $result);
self::assertEquals('00:00:00', $result->format('%r%H:%I:%S'));
}
public function testFormatValueReturnsFormattedDurationForNegativeValue(): void
{
$formatter = new DurationFormatter();
$result = $formatter->formatValue(-3600);
self::assertEquals('-1:00', $result);
self::assertInstanceOf(\DateInterval::class, $result);
self::assertEquals('-01:00:00', $result->format('%r%H:%I:%S'));
}
}

View File

@@ -0,0 +1,61 @@
<?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\Export\Package\CellFormatter;
use App\Export\Package\CellFormatter\DurationPlainFormatter;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Export\Package\CellFormatter\DurationPlainFormatter
*/
class DurationPlainFormatterTest extends TestCase
{
public function testFormatValueReturnsFormattedDurationQuiteLong(): void
{
$formatter = new DurationPlainFormatter();
$result = $formatter->formatValue(701213);
self::assertEquals('194:46:53', $result);
}
public function testFormatValueReturnsFormattedDurationForNumericValue(): void
{
$formatter = new DurationPlainFormatter();
$result = $formatter->formatValue(8246);
self::assertEquals('2:17:26', $result);
}
public function testFormatValueReturnsZeroForNonNumericValue(): void
{
$formatter = new DurationPlainFormatter();
$result = $formatter->formatValue('not a number');
self::assertEquals('0:00:00', $result);
}
public function testFormatValueReturnsFormattedDurationForFloatValue(): void
{
$formatter = new DurationPlainFormatter();
$result = $formatter->formatValue(44513.5);
self::assertEquals('12:21:53', $result);
}
public function testFormatValueReturnsZeroForNullValue(): void
{
$formatter = new DurationPlainFormatter();
$result = $formatter->formatValue(null);
self::assertEquals('0:00:00', $result);
}
public function testFormatValueReturnsFormattedDurationForNegativeValue(): void
{
$formatter = new DurationPlainFormatter();
$result = $formatter->formatValue(-3600);
self::assertEquals('-1:00:00', $result);
}
}

View File

@@ -11,6 +11,7 @@ namespace App\Tests\Export\Package;
use App\Entity\ExportableItem;
use App\Export\Package\CellFormatter\CellFormatterInterface;
use App\Export\Package\CellFormatter\DateFormatter;
use App\Export\Package\Column;
use PHPUnit\Framework\TestCase;
@@ -85,4 +86,17 @@ class ColumnTest extends TestCase
$column = new Column('testName', $formatter);
self::assertEquals('testName', $column->getHeader());
}
public function testWithFormatReturnsNull(): void
{
$formatter = $this->createMock(CellFormatterInterface::class);
$column = new Column('testName', $formatter);
self::assertNull($column->getFormat());
}
public function testWithFormatReturnsValueFromFormatter(): void
{
$column = new Column('testName', new DateFormatter());
self::assertEquals('yyyy-mm-dd', $column->getFormat());
}
}

View File

@@ -67,84 +67,72 @@ abstract class AbstractRendererTestCase extends KernelTestCase
$user2->method('getUsername')->willReturn('hello-world');
$timesheet = new Timesheet();
$timesheet
->setDuration(3600) // 60 minutes
->setRate(293.27)
->setUser($user1)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
;
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser($user1);
$timesheet->setActivity($activity);
$timesheet->setProject($project);
$timesheet->setBegin(new \DateTime());
$timesheet->setEnd(new \DateTime());
$timesheet2 = new Timesheet();
$timesheet2
->setDuration(400)
->setRate(84.75)
->setUser($user2)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
;
$timesheet2->setDuration(400);
$timesheet2->setRate(84.75);
$timesheet2->setUser($user2);
$timesheet2->setActivity($activity);
$timesheet2->setProject($project);
$timesheet2->setBegin(new \DateTime());
$timesheet2->setEnd(new \DateTime());
$timesheet3 = new Timesheet();
$timesheet3
->setDuration(1800)
->setRate(111.11)
->setUser($user1)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
;
$timesheet3->setDuration(1800);
$timesheet3->setRate(111.11);
$timesheet3->setUser($user1);
$timesheet3->setActivity($activity);
$timesheet3->setProject($project);
$timesheet3->setBegin(new \DateTime());
$timesheet3->setEnd(new \DateTime());
$timesheet4 = new Timesheet();
$timesheet4
->setDuration(400)
->setRate(1947.99)
->setUser($user2)
->setDescription('== jhg ljhg ') // make sure that spreadsheets don't render it as formula
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
->addTag((new Tag())->setName('foo'))
;
$timesheet4->setDuration(400);
$timesheet4->setRate(1947.99);
$timesheet4->setUser($user2);
$timesheet4->setDescription('== jhg ljhg '); // make sure that spreadsheets don't render it as formula
$timesheet4->setActivity($activity);
$timesheet4->setProject($project);
$timesheet4->setBegin(new \DateTime());
$timesheet4->setEnd(new \DateTime());
$timesheet4->addTag((new Tag())->setName('foo'));
$userKevin = new User();
$userKevin->setAlias('Kevin');
$userKevin->setUserIdentifier('kevin');
$timesheet5 = new Timesheet();
$timesheet5
->setDuration(400)
->setFixedRate(84)
->setUser($userKevin)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime('2019-06-16 12:00:00'))
->setEnd(new \DateTime('2019-06-16 12:06:40'))
->addTag((new Tag())->setName('foo'))
->addTag((new Tag())->setName('bar'))
->setMetaField((new TimesheetMeta())->setName('foo')->setValue('meta-bar')->setIsVisible(true))
->setMetaField((new TimesheetMeta())->setName('foo2')->setValue('meta-bar2')->setIsVisible(true))
;
$timesheet5->setDuration(400);
$timesheet5->setFixedRate(84);
$timesheet5->setUser($userKevin);
$timesheet5->setActivity($activity);
$timesheet5->setProject($project);
$timesheet5->setBegin(new \DateTime('2019-06-16 12:00:00'));
$timesheet5->setEnd(new \DateTime('2019-06-16 12:06:40'));
$timesheet5->addTag((new Tag())->setName('foo'));
$timesheet5->addTag((new Tag())->setName('bar'));
$timesheet5->setMetaField((new TimesheetMeta())->setName('foo')->setValue('meta-bar')->setIsVisible(true));
$timesheet5->setMetaField((new TimesheetMeta())->setName('foo2')->setValue('meta-bar2')->setIsVisible(true));
$userNivek = new User();
$userNivek->setAlias('niveK');
$userNivek->setUserIdentifier('nivek');
$timesheet6 = new Timesheet();
$timesheet6
->setDuration(400)
->setFixedRate(-100.92)
->setUser($userNivek)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime('2019-06-16 12:00:00'))
->setEnd(new \DateTime('2019-06-16 12:06:40'))
;
$timesheet6->setDuration(400);
$timesheet6->setFixedRate(-100.92);
$timesheet6->setUser($userNivek);
$timesheet6->setActivity($activity);
$timesheet6->setProject($project);
$timesheet6->setBegin(new \DateTime('2019-06-16 12:00:00'));
$timesheet6->setEnd(new \DateTime('2019-06-16 12:06:40'));
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5, $timesheet6];

View File

@@ -65,67 +65,57 @@ abstract class AbstractRendererTestCase extends KernelTestCase
$user2->method('getUserIdentifier')->willReturn('hello-world');
$timesheet = new Timesheet();
$timesheet
->setDuration(3600)
->setRate(293.27)
->setUser($user1)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
;
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser($user1);
$timesheet->setActivity($activity);
$timesheet->setProject($project);
$timesheet->setBegin(new \DateTime());
$timesheet->setEnd(new \DateTime());
$timesheet2 = new Timesheet();
$timesheet2
->setDuration(400)
->setRate(84.75)
->setUser($user2)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
;
$timesheet2->setDuration(400);
$timesheet2->setRate(84.75);
$timesheet2->setUser($user2);
$timesheet2->setActivity($activity);
$timesheet2->setProject($project);
$timesheet2->setBegin(new \DateTime());
$timesheet2->setEnd(new \DateTime());
$timesheet3 = new Timesheet();
$timesheet3
->setDuration(1800)
->setRate(111.11)
->setUser($user1)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
;
$timesheet3->setDuration(1800);
$timesheet3->setRate(111.11);
$timesheet3->setUser($user1);
$timesheet3->setActivity($activity);
$timesheet3->setProject($project);
$timesheet3->setBegin(new \DateTime());
$timesheet3->setEnd(new \DateTime());
$timesheet4 = new Timesheet();
$timesheet4
->setDuration(400)
->setRate(1947.99)
->setUser($user2)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
->addTag((new Tag())->setName('foo'))
;
$timesheet4->setDuration(400);
$timesheet4->setRate(1947.99);
$timesheet4->setUser($user2);
$timesheet4->setActivity($activity);
$timesheet4->setProject($project);
$timesheet4->setBegin(new \DateTime());
$timesheet4->setEnd(new \DateTime());
$timesheet4->addTag((new Tag())->setName('foo'));
$user = new User();
$user->setUserIdentifier('kevin');
$timesheet5 = new Timesheet();
$timesheet5
->setDuration(400)
->setFixedRate(84)
->setUser($user)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime('2019-06-16 12:00:00'))
->setEnd(new \DateTime('2019-06-16 12:06:40'))
->addTag((new Tag())->setName('foo'))
->addTag((new Tag())->setName('bar'))
->setMetaField((new TimesheetMeta())->setName('foo')->setValue('meta-bar')->setIsVisible(true))
->setMetaField((new TimesheetMeta())->setName('foo2')->setValue('meta-bar2')->setIsVisible(true))
;
$timesheet5->setDuration(400);
$timesheet5->setFixedRate(84);
$timesheet5->setUser($user);
$timesheet5->setActivity($activity);
$timesheet5->setProject($project);
$timesheet5->setBegin(new \DateTime('2019-06-16 12:00:00'));
$timesheet5->setEnd(new \DateTime('2019-06-16 12:06:40'));
$timesheet5->addTag((new Tag())->setName('foo'));
$timesheet5->addTag((new Tag())->setName('bar'));
$timesheet5->setMetaField((new TimesheetMeta())->setName('foo')->setValue('meta-bar')->setIsVisible(true));
$timesheet5->setMetaField((new TimesheetMeta())->setName('foo2')->setValue('meta-bar2')->setIsVisible(true));
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];

View File

@@ -86,14 +86,13 @@ abstract class AbstractCalculatorTestCase extends TestCase
}
$timesheet = new Timesheet();
$timesheet
->setDescription('timesheet description')
->setBegin(new \DateTime())
->setDuration(3600)
->setRate(293.27)
->setUser($user)
->setActivity($activity)
->setProject($project);
$timesheet->setDescription('timesheet description');
$timesheet->setBegin(new \DateTime());
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser($user);
$timesheet->setActivity($activity);
$timesheet->setProject($project);
$model = (new InvoiceModelFactoryFactory($this))->create()->createModel(new DebugFormatter(), $customer, $template, $query);
$model->addEntries([$timesheet]);

View File

@@ -54,82 +54,74 @@ class ActivityInvoiceCalculatorTest extends AbstractCalculatorTestCase
$activity3->method('getId')->willReturn(3);
$timesheet = new Timesheet();
$timesheet
->setBegin(new \DateTime('2018-11-29'))
->setEnd(new \DateTime())
->setDuration(3600)
->setRate(293.27)
->setUser($user)
->setActivity($activity1)
->setProject((new Project())->setName('bar'));
$timesheet->setBegin(new \DateTime('2018-11-29'));
$timesheet->setEnd(new \DateTime());
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser($user);
$timesheet->setActivity($activity1);
$timesheet->setProject((new Project())->setName('bar'));
$timesheet2 = new Timesheet();
$timesheet2
->setBegin(clone $date)
->setEnd(new \DateTime())
->setDuration(400)
->setRate(84.75)
->setUser($user)
->setActivity($activity2)
->setProject((new Project())->setName('bar'));
$timesheet2->setBegin(clone $date);
$timesheet2->setEnd(new \DateTime());
$timesheet2->setDuration(400);
$timesheet2->setRate(84.75);
$timesheet2->setUser($user);
$timesheet2->setActivity($activity2);
$timesheet2->setProject((new Project())->setName('bar'));
$timesheet3 = new Timesheet();
$timesheet3
->setBegin(new \DateTime('2018-11-28'))
->setEnd(new \DateTime())
->setDuration(1800)
->setRate(111.11)
->setUser($user)
->setActivity($activity1)
->setProject((new Project())->setName('bar'));
$timesheet3->setBegin(new \DateTime('2018-11-28'));
$timesheet3->setEnd(new \DateTime());
$timesheet3->setDuration(1800);
$timesheet3->setRate(111.11);
$timesheet3->setUser($user);
$timesheet3->setActivity($activity1);
$timesheet3->setProject((new Project())->setName('bar'));
$timesheet4 = new Timesheet();
$timesheet4
->setBegin(new \DateTime('2018-11-28'))
->setEnd(new \DateTime())
->setDuration(400)
->setRate(1947.99)
->setUser($user)
->setActivity($activity2)
->setProject((new Project())->setName('bar'));
$timesheet4->setBegin(new \DateTime('2018-11-28'));
$timesheet4->setEnd(new \DateTime());
$timesheet4->setDuration(400);
$timesheet4->setRate(1947.99);
$timesheet4->setUser($user);
$timesheet4->setActivity($activity2);
$timesheet4->setProject((new Project())->setName('bar'));
$timesheet5 = new Timesheet();
$timesheet5
->setBegin(new \DateTime('2018-11-29'))
->setEnd(new \DateTime())
->setDuration(400)
->setRate(84)
->setUser(new User())
->setActivity($activity3)
->setProject((new Project())->setName('bar'));
$timesheet5->setBegin(new \DateTime('2018-11-29'));
$timesheet5->setEnd(new \DateTime());
$timesheet5->setDuration(400);
$timesheet5->setRate(84);
$timesheet5->setUser(new User());
$timesheet5->setActivity($activity3);
$timesheet5->setProject((new Project())->setName('bar'));
$timesheet6 = new Timesheet();
$timesheet6
->setBegin(clone $date)
->setEnd(new \DateTime())
->setDuration(0)
->setRate(0)
->setUser(new User())
->setProject((new Project())->setName('bar'));
$timesheet6->setBegin(clone $date);
$timesheet6->setEnd(new \DateTime());
$timesheet6->setDuration(0);
$timesheet6->setRate(0);
$timesheet6->setUser(new User());
$timesheet6->setProject((new Project())->setName('bar'));
$timesheet7 = new Timesheet();
$timesheet7
->setBegin(clone $date)
->setEnd(new \DateTime('2018-11-18'))
->setDuration(0)
->setRate(0)
->setUser(new User())
->setActivity(new Activity())
->setProject((new Project())->setName('bar'));
$timesheet7->setBegin(clone $date);
$timesheet7->setEnd(new \DateTime('2018-11-18'));
$timesheet7->setDuration(0);
$timesheet7->setRate(0);
$timesheet7->setUser(new User());
$timesheet7->setActivity(new Activity());
$timesheet7->setProject((new Project())->setName('bar'));
$timesheet8 = new Timesheet();
$timesheet8
->setBegin(clone $date)
->setEnd(new \DateTime())
->setDuration(0)
->setRate(0)
->setUser(new User())
->setProject((new Project())->setName('bar'));
$timesheet8->setBegin(clone $date);
$timesheet8->setEnd(new \DateTime());
$timesheet8->setDuration(0);
$timesheet8->setRate(0);
$timesheet8->setUser(new User());
$timesheet8->setProject((new Project())->setName('bar'));
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5, $timesheet6, $timesheet7, $timesheet8];

View File

@@ -57,92 +57,83 @@ class ActivityUserInvoiceCalculatorTest extends AbstractCalculatorTestCase
$activity3->method('getId')->willReturn(3);
$timesheet = new Timesheet();
$timesheet
->setBegin(new \DateTime())
->setEnd(new \DateTime())
->setDuration(3600)
->setRate(293.27)
->setUser($user1)
->setActivity($activity1)
->setProject((new Project())->setName('bar'));
$timesheet->setBegin(new \DateTime());
$timesheet->setEnd(new \DateTime());
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser($user1);
$timesheet->setActivity($activity1);
$timesheet->setProject((new Project())->setName('bar'));
$timesheet2 = new Timesheet();
$timesheet2
->setBegin(new \DateTime('2018-11-18'))
->setEnd(new \DateTime())
->setDuration(400)
->setRate(84.75)
->setUser($user1)
->setActivity($activity2)
->setProject((new Project())->setName('bar'));
$timesheet2->setBegin(new \DateTime('2018-11-18'));
$timesheet2->setEnd(new \DateTime());
$timesheet2->setDuration(400);
$timesheet2->setRate(84.75);
$timesheet2->setUser($user1);
$timesheet2->setActivity($activity2);
$timesheet2->setProject((new Project())->setName('bar'));
$timesheet3 = new Timesheet();
$timesheet3
->setBegin(clone $date)
->setEnd(new \DateTime())
->setDuration(1800)
->setRate(111.11)
->setUser($user1)
->setActivity($activity1)
->setProject((new Project())->setName('bar'));
$timesheet3->setBegin(clone $date);
$timesheet3->setEnd(new \DateTime());
$timesheet3->setDuration(1800);
$timesheet3->setRate(111.11);
$timesheet3->setUser($user1);
$timesheet3->setActivity($activity1);
$timesheet3->setProject((new Project())->setName('bar'));
$timesheet4 = new Timesheet();
$timesheet4
->setBegin(new \DateTime('2018-11-29'))
->setEnd(new \DateTime())
->setDuration(400)
->setRate(1947.99)
->setUser($user1)
->setActivity($activity2)
->setProject((new Project())->setName('bar'));
$timesheet4->setBegin(new \DateTime('2018-11-29'));
$timesheet4->setEnd(new \DateTime());
$timesheet4->setDuration(400);
$timesheet4->setRate(1947.99);
$timesheet4->setUser($user1);
$timesheet4->setActivity($activity2);
$timesheet4->setProject((new Project())->setName('bar'));
$timesheet5 = new Timesheet();
$timesheet5
->setBegin(new \DateTime('2018-11-18'))
->setEnd(new \DateTime())
->setDuration(400)
->setRate(84)
->setUser($user2)
->setActivity($activity3)
->setProject((new Project())->setName('bar'));
$timesheet5->setBegin(new \DateTime('2018-11-18'));
$timesheet5->setEnd(new \DateTime());
$timesheet5->setDuration(400);
$timesheet5->setRate(84);
$timesheet5->setUser($user2);
$timesheet5->setActivity($activity3);
$timesheet5->setProject((new Project())->setName('bar'));
$timesheet5a = new Timesheet();
$timesheet5a
->setBegin(new \DateTime('2018-11-08'))
->setEnd(new \DateTime())
->setDuration(400)
->setRate(84)
->setUser($user1)
->setActivity($activity3)
->setProject((new Project())->setName('bar'));
$timesheet5a->setBegin(new \DateTime('2018-11-08'));
$timesheet5a->setEnd(new \DateTime());
$timesheet5a->setDuration(400);
$timesheet5a->setRate(84);
$timesheet5a->setUser($user1);
$timesheet5a->setActivity($activity3);
$timesheet5a->setProject((new Project())->setName('bar'));
$timesheet6 = new Timesheet();
$timesheet6
->setBegin(clone $date)
->setEnd(new \DateTime())
->setDuration(0)
->setRate(0)
->setUser($user1)
->setProject((new Project())->setName('bar'));
$timesheet6->setBegin(clone $date);
$timesheet6->setEnd(new \DateTime());
$timesheet6->setDuration(0);
$timesheet6->setRate(0);
$timesheet6->setUser($user1);
$timesheet6->setProject((new Project())->setName('bar'));
$timesheet7 = new Timesheet();
$timesheet7
->setBegin(clone $date)
->setEnd(new \DateTime())
->setDuration(0)
->setRate(0)
->setUser($user2)
->setActivity(new Activity())
->setProject((new Project())->setName('bar'));
$timesheet7->setBegin(clone $date);
$timesheet7->setEnd(new \DateTime());
$timesheet7->setDuration(0);
$timesheet7->setRate(0);
$timesheet7->setUser($user2);
$timesheet7->setActivity(new Activity());
$timesheet7->setProject((new Project())->setName('bar'));
$timesheet8 = new Timesheet();
$timesheet8
->setBegin(clone $date)
->setEnd(new \DateTime())
->setDuration(0)
->setRate(0)
->setUser($user2)
->setProject((new Project())->setName('bar'));
$timesheet8->setBegin(clone $date);
$timesheet8->setEnd(new \DateTime());
$timesheet8->setDuration(0);
$timesheet8->setRate(0);
$timesheet8->setUser($user2);
$timesheet8->setProject((new Project())->setName('bar'));
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5, $timesheet5a, $timesheet6, $timesheet7, $timesheet8];

View File

@@ -55,54 +55,49 @@ class DateInvoiceCalculatorTest extends AbstractCalculatorTestCase
$project3->method('getId')->willReturn(3);
$timesheet = new Timesheet();
$timesheet
->setBegin(new DateTime('2018-11-29'))
->setEnd(new DateTime())
->setDuration(3600)
->setRate(293.27)
->setUser($user)
->setActivity((new Activity())->setName('sdsd'))
->setProject($project1);
$timesheet->setBegin(new DateTime('2018-11-29'));
$timesheet->setEnd(new DateTime());
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser($user);
$timesheet->setActivity((new Activity())->setName('sdsd'));
$timesheet->setProject($project1);
$timesheet2 = new Timesheet();
$timesheet2
->setBegin(new DateTime('2018-11-29'))
->setEnd(new DateTime())
->setDuration(400)
->setRate(84.75)
->setUser($user)
->setActivity((new Activity())->setName('bar'))
->setProject($project2);
$timesheet2->setBegin(new DateTime('2018-11-29'));
$timesheet2->setEnd(new DateTime());
$timesheet2->setDuration(400);
$timesheet2->setRate(84.75);
$timesheet2->setUser($user);
$timesheet2->setActivity((new Activity())->setName('bar'));
$timesheet2->setProject($project2);
$timesheet3 = new Timesheet();
$timesheet3
->setBegin(new DateTime('2018-11-28'))
->setEnd(new DateTime())
->setDuration(1800)
->setRate(111.11)
->setUser($user)
->setActivity((new Activity())->setName('foo'))
->setProject($project1);
$timesheet3->setBegin(new DateTime('2018-11-28'));
$timesheet3->setEnd(new DateTime());
$timesheet3->setDuration(1800);
$timesheet3->setRate(111.11);
$timesheet3->setUser($user);
$timesheet3->setActivity((new Activity())->setName('foo'));
$timesheet3->setProject($project1);
$timesheet4 = new Timesheet();
$timesheet4
->setBegin($date)
->setEnd(new DateTime('2018-11-28'))
->setDuration(400)
->setRate(1947.99)
->setUser($user)
->setActivity((new Activity())->setName('blub'))
->setProject($project2);
$timesheet4->setBegin($date);
$timesheet4->setEnd(new DateTime('2018-11-28'));
$timesheet4->setDuration(400);
$timesheet4->setRate(1947.99);
$timesheet4->setUser($user);
$timesheet4->setActivity((new Activity())->setName('blub'));
$timesheet4->setProject($project2);
$timesheet5 = new Timesheet();
$timesheet5
->setBegin(new DateTime('2018-11-28'))
->setEnd(new DateTime())
->setDuration(400)
->setRate(84)
->setUser(new User())
->setActivity(new Activity())
->setProject($project3);
$timesheet5->setBegin(new DateTime('2018-11-28'));
$timesheet5->setEnd(new DateTime());
$timesheet5->setDuration(400);
$timesheet5->setRate(84);
$timesheet5->setUser(new User());
$timesheet5->setActivity(new Activity());
$timesheet5->setProject($project3);
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];

View File

@@ -57,54 +57,49 @@ class DateUserInvoiceCalculatorTest extends AbstractCalculatorTestCase
$project3->method('getId')->willReturn(3);
$timesheet = new Timesheet();
$timesheet
->setBegin(new DateTime('2018-11-29'))
->setEnd(new DateTime())
->setDuration(3600)
->setRate(293.27)
->setUser($user1)
->setActivity((new Activity())->setName('sdsd'))
->setProject($project1);
$timesheet->setBegin(new DateTime('2018-11-29'));
$timesheet->setEnd(new DateTime());
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser($user1);
$timesheet->setActivity((new Activity())->setName('sdsd'));
$timesheet->setProject($project1);
$timesheet2 = new Timesheet();
$timesheet2
->setBegin(new DateTime('2018-11-29'))
->setEnd(new DateTime())
->setDuration(400)
->setRate(84.75)
->setUser($user1)
->setActivity((new Activity())->setName('bar'))
->setProject($project2);
$timesheet2->setBegin(new DateTime('2018-11-29'));
$timesheet2->setEnd(new DateTime());
$timesheet2->setDuration(400);
$timesheet2->setRate(84.75);
$timesheet2->setUser($user1);
$timesheet2->setActivity((new Activity())->setName('bar'));
$timesheet2->setProject($project2);
$timesheet3 = new Timesheet();
$timesheet3
->setBegin(new DateTime('2018-11-28'))
->setEnd(new DateTime())
->setDuration(1800)
->setRate(111.11)
->setUser($user1)
->setActivity((new Activity())->setName('foo'))
->setProject($project1);
$timesheet3->setBegin(new DateTime('2018-11-28'));
$timesheet3->setEnd(new DateTime());
$timesheet3->setDuration(1800);
$timesheet3->setRate(111.11);
$timesheet3->setUser($user1);
$timesheet3->setActivity((new Activity())->setName('foo'));
$timesheet3->setProject($project1);
$timesheet4 = new Timesheet();
$timesheet4
->setBegin(new DateTime())
->setEnd(new DateTime())
->setDuration(400)
->setRate(1947.99)
->setUser($user1)
->setActivity((new Activity())->setName('blub'))
->setProject($project2);
$timesheet4->setBegin(new DateTime());
$timesheet4->setEnd(new DateTime());
$timesheet4->setDuration(400);
$timesheet4->setRate(1947.99);
$timesheet4->setUser($user1);
$timesheet4->setActivity((new Activity())->setName('blub'));
$timesheet4->setProject($project2);
$timesheet5 = new Timesheet();
$timesheet5
->setBegin(new DateTime('2018-11-28'))
->setEnd(new DateTime())
->setDuration(400)
->setRate(84)
->setUser($user2)
->setActivity(new Activity())
->setProject($project3);
$timesheet5->setBegin(new DateTime('2018-11-28'));
$timesheet5->setEnd(new DateTime());
$timesheet5->setDuration(400);
$timesheet5->setRate(84);
$timesheet5->setUser($user2);
$timesheet5->setActivity(new Activity());
$timesheet5->setProject($project3);
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];

View File

@@ -54,58 +54,53 @@ class PriceInvoiceCalculatorTest extends AbstractCalculatorTestCase
$project3->method('getId')->willReturn(3);
$timesheet = new Timesheet();
$timesheet
->setBegin(new DateTime('2018-11-29'))
->setEnd(new DateTime())
->setDuration(3600)
->setHourlyRate(293.27)
->setRate(293.27)
->setUser($user)
->setActivity((new Activity())->setName('sdsd'))
->setProject($project1);
$timesheet->setBegin(new DateTime('2018-11-29'));
$timesheet->setEnd(new DateTime());
$timesheet->setDuration(3600);
$timesheet->setHourlyRate(293.27);
$timesheet->setRate(293.27);
$timesheet->setUser($user);
$timesheet->setActivity((new Activity())->setName('sdsd'));
$timesheet->setProject($project1);
$timesheet2 = new Timesheet();
$timesheet2
->setBegin(new DateTime('2018-11-29'))
->setEnd(new DateTime())
->setDuration(400)
->setHourlyRate(293.27)
->setRate(84.75)
->setUser($user)
->setActivity((new Activity())->setName('bar'))
->setProject($project2);
$timesheet2->setBegin(new DateTime('2018-11-29'));
$timesheet2->setEnd(new DateTime());
$timesheet2->setDuration(400);
$timesheet2->setHourlyRate(293.27);
$timesheet2->setRate(84.75);
$timesheet2->setUser($user);
$timesheet2->setActivity((new Activity())->setName('bar'));
$timesheet2->setProject($project2);
$timesheet3 = new Timesheet();
$timesheet3
->setBegin(new DateTime('2018-11-28'))
->setEnd(new DateTime())
->setDuration(1800)
->setFixedRate(111.11)
->setRate(111.11)
->setUser($user)
->setActivity((new Activity())->setName('foo'))
->setProject($project1);
$timesheet3->setBegin(new DateTime('2018-11-28'));
$timesheet3->setEnd(new DateTime());
$timesheet3->setDuration(1800);
$timesheet3->setFixedRate(111.11);
$timesheet3->setRate(111.11);
$timesheet3->setUser($user);
$timesheet3->setActivity((new Activity())->setName('foo'));
$timesheet3->setProject($project1);
$timesheet4 = new Timesheet();
$timesheet4
->setBegin(new DateTime('2018-11-28'))
->setEnd(new DateTime())
->setDuration(400)
->setHourlyRate(0)
->setRate(1947.99)
->setUser($user)
->setActivity((new Activity())->setName('blub'))
->setProject($project2);
$timesheet4->setBegin(new DateTime('2018-11-28'));
$timesheet4->setEnd(new DateTime());
$timesheet4->setDuration(400);
$timesheet4->setHourlyRate(0);
$timesheet4->setRate(1947.99);
$timesheet4->setUser($user);
$timesheet4->setActivity((new Activity())->setName('blub'));
$timesheet4->setProject($project2);
$timesheet5 = new Timesheet();
$timesheet5
->setBegin(new DateTime('2018-11-28'))
->setEnd(new DateTime())
->setDuration(400)
->setRate(84)
->setUser(new User())
->setActivity(new Activity())
->setProject($project3);
$timesheet5->setBegin(new DateTime('2018-11-28'));
$timesheet5->setEnd(new DateTime());
$timesheet5->setDuration(400);
$timesheet5->setRate(84);
$timesheet5->setUser(new User());
$timesheet5->setActivity(new Activity());
$timesheet5->setProject($project3);
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];

View File

@@ -54,54 +54,49 @@ class ProjectInvoiceCalculatorTest extends AbstractCalculatorTestCase
$project3->method('getId')->willReturn(3);
$timesheet = new Timesheet();
$timesheet
->setBegin(new DateTime('2018-11-29'))
->setEnd(new DateTime())
->setDuration(3600)
->setRate(293.27)
->setUser($user)
->setActivity((new Activity())->setName('sdsd'))
->setProject($project1);
$timesheet->setBegin(new DateTime('2018-11-29'));
$timesheet->setEnd(new DateTime());
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser($user);
$timesheet->setActivity((new Activity())->setName('sdsd'));
$timesheet->setProject($project1);
$timesheet2 = new Timesheet();
$timesheet2
->setBegin(new DateTime('2018-11-28'))
->setEnd(new DateTime())
->setDuration(400)
->setRate(84.75)
->setUser($user)
->setActivity((new Activity())->setName('bar'))
->setProject($project2);
$timesheet2->setBegin(new DateTime('2018-11-28'));
$timesheet2->setEnd(new DateTime());
$timesheet2->setDuration(400);
$timesheet2->setRate(84.75);
$timesheet2->setUser($user);
$timesheet2->setActivity((new Activity())->setName('bar'));
$timesheet2->setProject($project2);
$timesheet3 = new Timesheet();
$timesheet3
->setBegin(new DateTime('2018-11-29'))
->setEnd(new DateTime())
->setDuration(1800)
->setRate(111.11)
->setUser($user)
->setActivity((new Activity())->setName('foo'))
->setProject($project1);
$timesheet3->setBegin(new DateTime('2018-11-29'));
$timesheet3->setEnd(new DateTime());
$timesheet3->setDuration(1800);
$timesheet3->setRate(111.11);
$timesheet3->setUser($user);
$timesheet3->setActivity((new Activity())->setName('foo'));
$timesheet3->setProject($project1);
$timesheet4 = new Timesheet();
$timesheet4
->setBegin(new DateTime('2018-11-08'))
->setEnd(new DateTime())
->setDuration(400)
->setRate(1947.99)
->setUser($user)
->setActivity((new Activity())->setName('blub'))
->setProject($project2);
$timesheet4->setBegin(new DateTime('2018-11-08'));
$timesheet4->setEnd(new DateTime());
$timesheet4->setDuration(400);
$timesheet4->setRate(1947.99);
$timesheet4->setUser($user);
$timesheet4->setActivity((new Activity())->setName('blub'));
$timesheet4->setProject($project2);
$timesheet5 = new Timesheet();
$timesheet5
->setBegin(new DateTime('2018-11-28'))
->setEnd(new DateTime())
->setDuration(400)
->setRate(84)
->setUser(new User())
->setActivity(new Activity())
->setProject($project3);
$timesheet5->setBegin(new DateTime('2018-11-28'));
$timesheet5->setEnd(new DateTime());
$timesheet5->setDuration(400);
$timesheet5->setRate(84);
$timesheet5->setUser(new User());
$timesheet5->setActivity(new Activity());
$timesheet5->setProject($project3);
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];

View File

@@ -57,54 +57,49 @@ class ProjectUserInvoiceCalculatorTest extends AbstractCalculatorTestCase
$project3->method('getId')->willReturn(3);
$timesheet = new Timesheet();
$timesheet
->setBegin(new DateTime('2018-11-29'))
->setEnd(new DateTime())
->setDuration(3600)
->setRate(293.27)
->setUser($user1)
->setActivity((new Activity())->setName('sdsd'))
->setProject($project1);
$timesheet->setBegin(new DateTime('2018-11-29'));
$timesheet->setEnd(new DateTime());
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser($user1);
$timesheet->setActivity((new Activity())->setName('sdsd'));
$timesheet->setProject($project1);
$timesheet2 = new Timesheet();
$timesheet2
->setBegin(new DateTime('2018-11-28'))
->setEnd(new DateTime())
->setDuration(400)
->setRate(84.75)
->setUser($user1)
->setActivity((new Activity())->setName('bar'))
->setProject($project2);
$timesheet2->setBegin(new DateTime('2018-11-28'));
$timesheet2->setEnd(new DateTime());
$timesheet2->setDuration(400);
$timesheet2->setRate(84.75);
$timesheet2->setUser($user1);
$timesheet2->setActivity((new Activity())->setName('bar'));
$timesheet2->setProject($project2);
$timesheet3 = new Timesheet();
$timesheet3
->setBegin(new DateTime('2018-11-29'))
->setEnd(new DateTime())
->setDuration(1800)
->setRate(111.11)
->setUser($user1)
->setActivity((new Activity())->setName('foo'))
->setProject($project1);
$timesheet3->setBegin(new DateTime('2018-11-29'));
$timesheet3->setEnd(new DateTime());
$timesheet3->setDuration(1800);
$timesheet3->setRate(111.11);
$timesheet3->setUser($user1);
$timesheet3->setActivity((new Activity())->setName('foo'));
$timesheet3->setProject($project1);
$timesheet4 = new Timesheet();
$timesheet4
->setBegin(new DateTime('2018-11-08'))
->setEnd(new DateTime())
->setDuration(400)
->setRate(1947.99)
->setUser($user1)
->setActivity((new Activity())->setName('blub'))
->setProject($project2);
$timesheet4->setBegin(new DateTime('2018-11-08'));
$timesheet4->setEnd(new DateTime());
$timesheet4->setDuration(400);
$timesheet4->setRate(1947.99);
$timesheet4->setUser($user1);
$timesheet4->setActivity((new Activity())->setName('blub'));
$timesheet4->setProject($project2);
$timesheet5 = new Timesheet();
$timesheet5
->setBegin(new DateTime('2018-11-28'))
->setEnd(new DateTime())
->setDuration(400)
->setRate(84)
->setUser($user2)
->setActivity(new Activity())
->setProject($project3);
$timesheet5->setBegin(new DateTime('2018-11-28'));
$timesheet5->setEnd(new DateTime());
$timesheet5->setDuration(400);
$timesheet5->setRate(84);
$timesheet5->setUser($user2);
$timesheet5->setActivity(new Activity());
$timesheet5->setProject($project3);
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];

View File

@@ -49,43 +49,37 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTestCase
$activity->setProject($project);
$timesheet = new Timesheet();
$timesheet
->setDuration(3600)
->setRate(293.27)
->setHourlyRate(293.27)
->setUser(new User())
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime('2018-11-29'))
->setEnd(new \DateTime())
->addTag((new Tag())->setName('foo'))
->addTag((new Tag())->setName('bar'))
;
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setHourlyRate(293.27);
$timesheet->setUser(new User());
$timesheet->setActivity($activity);
$timesheet->setProject($project);
$timesheet->setBegin(new \DateTime('2018-11-29'));
$timesheet->setEnd(new \DateTime());
$timesheet->addTag((new Tag())->setName('foo'));
$timesheet->addTag((new Tag())->setName('bar'));
$timesheet2 = new Timesheet();
$timesheet2
->setDuration(400)
->setRate(32.59)
->setHourlyRate(293.27)
->setUser(new User())
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime('2018-11-28'))
->setEnd(new \DateTime())
->addTag((new Tag())->setName('bar1'))
;
$timesheet2->setDuration(400);
$timesheet2->setRate(32.59);
$timesheet2->setHourlyRate(293.27);
$timesheet2->setUser(new User());
$timesheet2->setActivity($activity);
$timesheet2->setProject($project);
$timesheet2->setBegin(new \DateTime('2018-11-28'));
$timesheet2->setEnd(new \DateTime());
$timesheet2->addTag((new Tag())->setName('bar1'));
$timesheet3 = new Timesheet();
$timesheet3
->setDuration(1800)
->setRate(146.64)
->setHourlyRate(293.27)
->setUser(new User())
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime('2018-11-29'))
->setEnd(new \DateTime())
;
$timesheet3->setDuration(1800);
$timesheet3->setRate(146.64);
$timesheet3->setHourlyRate(293.27);
$timesheet3->setUser(new User());
$timesheet3->setActivity($activity);
$timesheet3->setProject($project);
$timesheet3->setBegin(new \DateTime('2018-11-29'));
$timesheet3->setEnd(new \DateTime());
$entries = [$timesheet, $timesheet2, $timesheet3];
@@ -134,40 +128,34 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTestCase
$activity->setProject($project);
$timesheet = new Timesheet();
$timesheet
->setDuration(3600)
->setRate(293.27)
->setHourlyRate(293.27)
->setUser(new User())
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
;
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setHourlyRate(293.27);
$timesheet->setUser(new User());
$timesheet->setActivity($activity);
$timesheet->setProject($project);
$timesheet->setBegin(new \DateTime());
$timesheet->setEnd(new \DateTime());
$timesheet2 = new Timesheet();
$timesheet2
->setDuration(400)
->setRate(84)
->setHourlyRate(756.00)
->setUser(new User())
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
;
$timesheet2->setDuration(400);
$timesheet2->setRate(84);
$timesheet2->setHourlyRate(756.00);
$timesheet2->setUser(new User());
$timesheet2->setActivity($activity);
$timesheet2->setProject($project);
$timesheet2->setBegin(new \DateTime());
$timesheet2->setEnd(new \DateTime());
$timesheet3 = new Timesheet();
$timesheet3
->setDuration(1800)
->setRate(111.11)
->setHourlyRate(222.22)
->setUser(new User())
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
;
$timesheet3->setDuration(1800);
$timesheet3->setRate(111.11);
$timesheet3->setHourlyRate(222.22);
$timesheet3->setUser(new User());
$timesheet3->setActivity($activity);
$timesheet3->setProject($project);
$timesheet3->setBegin(new \DateTime());
$timesheet3->setEnd(new \DateTime());
$entries = [$timesheet, $timesheet2, $timesheet3];
@@ -212,38 +200,32 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTestCase
$activity->setProject($project);
$timesheet = new Timesheet();
$timesheet
->setDuration(3600)
->setRate(293.27)
->setUser(new User())
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
;
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser(new User());
$timesheet->setActivity($activity);
$timesheet->setProject($project);
$timesheet->setBegin(new \DateTime());
$timesheet->setEnd(new \DateTime());
$timesheet2 = new Timesheet();
$timesheet2
->setDuration(400)
->setFixedRate(84)
->setRate(84)
->setUser(new User())
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
;
$timesheet2->setDuration(400);
$timesheet2->setFixedRate(84);
$timesheet2->setRate(84);
$timesheet2->setUser(new User());
$timesheet2->setActivity($activity);
$timesheet2->setProject($project);
$timesheet2->setBegin(new \DateTime());
$timesheet2->setEnd(new \DateTime());
$timesheet3 = new Timesheet();
$timesheet3
->setDuration(1800)
->setRate(111.11)
->setUser(new User())
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime())
->setEnd(new \DateTime())
;
$timesheet3->setDuration(1800);
$timesheet3->setRate(111.11);
$timesheet3->setUser(new User());
$timesheet3->setActivity($activity);
$timesheet3->setProject($project);
$timesheet3->setBegin(new \DateTime());
$timesheet3->setEnd(new \DateTime());
$entries = [$timesheet, $timesheet2, $timesheet3];

View File

@@ -52,54 +52,49 @@ class UserInvoiceCalculatorTest extends AbstractCalculatorTestCase
$user3->method('getId')->willReturn(3);
$timesheet = new Timesheet();
$timesheet
->setBegin(new \DateTime('2018-11-29'))
->setEnd(new \DateTime())
->setDuration(3600)
->setRate(293.27)
->setUser($user1)
->setActivity($activity)
->setProject((new Project())->setName('bar'));
$timesheet->setBegin(new \DateTime('2018-11-29'));
$timesheet->setEnd(new \DateTime());
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser($user1);
$timesheet->setActivity($activity);
$timesheet->setProject((new Project())->setName('bar'));
$timesheet2 = new Timesheet();
$timesheet2
->setBegin(new \DateTime('2018-11-28'))
->setEnd(new \DateTime())
->setDuration(400)
->setRate(84.75)
->setUser($user2)
->setActivity($activity)
->setProject((new Project())->setName('bar'));
$timesheet2->setBegin(new \DateTime('2018-11-28'));
$timesheet2->setEnd(new \DateTime());
$timesheet2->setDuration(400);
$timesheet2->setRate(84.75);
$timesheet2->setUser($user2);
$timesheet2->setActivity($activity);
$timesheet2->setProject((new Project())->setName('bar'));
$timesheet3 = new Timesheet();
$timesheet3
->setBegin(new \DateTime('2018-11-08'))
->setEnd(new \DateTime())
->setDuration(1800)
->setRate(111.11)
->setUser($user1)
->setActivity($activity)
->setProject((new Project())->setName('bar'));
$timesheet3->setBegin(new \DateTime('2018-11-08'));
$timesheet3->setEnd(new \DateTime());
$timesheet3->setDuration(1800);
$timesheet3->setRate(111.11);
$timesheet3->setUser($user1);
$timesheet3->setActivity($activity);
$timesheet3->setProject((new Project())->setName('bar'));
$timesheet4 = new Timesheet();
$timesheet4
->setBegin(new \DateTime('2018-11-28'))
->setEnd(new \DateTime())
->setDuration(400)
->setRate(1947.99)
->setUser($user2)
->setActivity($activity)
->setProject((new Project())->setName('bar'));
$timesheet4->setBegin(new \DateTime('2018-11-28'));
$timesheet4->setEnd(new \DateTime());
$timesheet4->setDuration(400);
$timesheet4->setRate(1947.99);
$timesheet4->setUser($user2);
$timesheet4->setActivity($activity);
$timesheet4->setProject((new Project())->setName('bar'));
$timesheet5 = new Timesheet();
$timesheet5
->setBegin(new \DateTime())
->setEnd(new \DateTime())
->setDuration(400)
->setRate(84)
->setUser($user3)
->setActivity($activity)
->setProject((new Project())->setName('bar'));
$timesheet5->setBegin(new \DateTime());
$timesheet5->setEnd(new \DateTime());
$timesheet5->setDuration(400);
$timesheet5->setRate(84);
$timesheet5->setUser($user3);
$timesheet5->setActivity($activity);
$timesheet5->setProject((new Project())->setName('bar'));
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];

View File

@@ -57,54 +57,49 @@ class WeeklyInvoiceCalculatorTest extends AbstractCalculatorTestCase
$end = new \DateTime('now', $timezone);
$timesheet = new Timesheet();
$timesheet
->setBegin(new DateTime('2018-11-26 12:00:00', $timezone))
->setEnd(clone $end)
->setDuration(3600)
->setRate(293.27)
->setUser($user)
->setActivity((new Activity())->setName('sdsd'))
->setProject($project1);
$timesheet->setBegin(new DateTime('2018-11-26 12:00:00', $timezone));
$timesheet->setEnd(clone $end);
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser($user);
$timesheet->setActivity((new Activity())->setName('sdsd'));
$timesheet->setProject($project1);
$timesheet2 = new Timesheet();
$timesheet2
->setBegin(new DateTime('2018-11-26 12:00:00', $timezone))
->setEnd(clone $end)
->setDuration(400)
->setRate(84.75)
->setUser($user)
->setActivity((new Activity())->setName('bar'))
->setProject($project2);
$timesheet2->setBegin(new DateTime('2018-11-26 12:00:00', $timezone));
$timesheet2->setEnd(clone $end);
$timesheet2->setDuration(400);
$timesheet2->setRate(84.75);
$timesheet2->setUser($user);
$timesheet2->setActivity((new Activity())->setName('bar'));
$timesheet2->setProject($project2);
$timesheet3 = new Timesheet();
$timesheet3
->setBegin(new DateTime('2018-11-25 12:00:00', $timezone))
->setEnd(clone $end)
->setDuration(1800)
->setRate(111.11)
->setUser($user)
->setActivity((new Activity())->setName('foo'))
->setProject($project1);
$timesheet3->setBegin(new DateTime('2018-11-25 12:00:00', $timezone));
$timesheet3->setEnd(clone $end);
$timesheet3->setDuration(1800);
$timesheet3->setRate(111.11);
$timesheet3->setUser($user);
$timesheet3->setActivity((new Activity())->setName('foo'));
$timesheet3->setProject($project1);
$timesheet4 = new Timesheet();
$timesheet4
->setBegin(new DateTime('2018-11-25 12:00:00', $timezone))
->setEnd(clone $end)
->setDuration(400)
->setRate(1947.99)
->setUser($user)
->setActivity((new Activity())->setName('blub'))
->setProject($project2);
$timesheet4->setBegin(new DateTime('2018-11-25 12:00:00', $timezone));
$timesheet4->setEnd(clone $end);
$timesheet4->setDuration(400);
$timesheet4->setRate(1947.99);
$timesheet4->setUser($user);
$timesheet4->setActivity((new Activity())->setName('blub'));
$timesheet4->setProject($project2);
$timesheet5 = new Timesheet();
$timesheet5
->setBegin(new DateTime('2018-11-25 12:00:00', $timezone))
->setEnd(clone $end)
->setDuration(400)
->setRate(84)
->setUser(new User())
->setActivity(new Activity())
->setProject($project3);
$timesheet5->setBegin(new DateTime('2018-11-25 12:00:00', $timezone));
$timesheet5->setEnd(clone $end);
$timesheet5->setDuration(400);
$timesheet5->setRate(84);
$timesheet5->setUser(new User());
$timesheet5->setActivity(new Activity());
$timesheet5->setProject($project3);
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];

View File

@@ -43,7 +43,7 @@ class InvoiceModelCustomerHydratorTest extends TestCase
'customer.vat' => '',
'customer.vat_id' => '',
'customer.number' => '',
'customer.country' => null,
'customer.country' => 'AT',
'customer.homepage' => '',
'customer.comment' => '',
'customer.email' => '',

View File

@@ -12,6 +12,7 @@ namespace App\Tests\Invoice\Hydrator;
use App\Invoice\Hydrator\InvoiceModelDefaultHydrator;
use App\Tests\Invoice\Renderer\RendererTestTrait;
use PHPUnit\Framework\TestCase;
use ReflectionObject;
/**
* @covers \App\Invoice\Hydrator\InvoiceModelDefaultHydrator
@@ -30,6 +31,23 @@ class InvoiceModelDefaultHydratorTest extends TestCase
$this->assertModelStructure($result);
}
public function testHydrateThrowsOnMissing(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('InvoiceModel needs a template');
$model = $this->getInvoiceModel();
$obj = new ReflectionObject($model);
$prop = $obj->getProperty('template');
$prop->setAccessible(true);
$prop->setValue($model, null);
$sut = new InvoiceModelDefaultHydrator();
$sut->hydrate($model);
}
protected function assertModelStructure(array $model, bool $hasProject = true): void
{
$keys = [
@@ -60,6 +78,8 @@ class InvoiceModelDefaultHydratorTest extends TestCase
'invoice.subtotal_plain',
'template.name',
'template.company',
'template.country',
'template.country_name',
'template.address',
'template.title',
'template.payment_terms',

View File

@@ -111,6 +111,7 @@ class DebugRendererTest extends TestCase
'invoice.subtotal_plain',
'template.name',
'template.company',
'template.country',
'template.address',
'template.title',
'template.payment_terms',
@@ -118,6 +119,7 @@ class DebugRendererTest extends TestCase
'template.vat_id',
'template.contact',
'template.payment_details',
'template.country_name',
'query.day',
'query.month',
'query.month_number',

View File

@@ -88,6 +88,7 @@ trait RendererTestTrait
$customer = new Customer('customer,with/special#name');
$customer->setAddress('Foo' . PHP_EOL . 'Street' . PHP_EOL . '1111 City');
$customer->setCurrency('EUR');
$customer->setCountry('AT');
$customer->setMetaField((new CustomerMeta())->setName('foo-customer')->setValue('bar-customer')->setIsVisible(true));
$template = new InvoiceTemplate();
@@ -152,61 +153,54 @@ trait RendererTestTrait
$user2->method('getVisiblePreferences')->willReturn([$pref1, $pref2]);
$timesheet = new Timesheet();
$timesheet
->setDuration(3600)
->setRate(293.27)
->setUser($user1)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime('2020-12-13 14:00:00'))
->setEnd(new \DateTime('2020-12-13 15:00:00'))
->setMetaField((new TimesheetMeta())->setName('foo-timesheet')->setValue('bar-timesheet')->setIsVisible(true));
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser($user1);
$timesheet->setActivity($activity);
$timesheet->setProject($project);
$timesheet->setBegin(new \DateTime('2020-12-13 14:00:00'));
$timesheet->setEnd(new \DateTime('2020-12-13 15:00:00'));
$timesheet->setMetaField((new TimesheetMeta())->setName('foo-timesheet')->setValue('bar-timesheet')->setIsVisible(true));
$timesheet2 = new Timesheet();
$timesheet2
->setDuration(400)
->setRate(84.75)
->setUser($user2)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime('2020-08-13 14:00:00'))
->setEnd(new \DateTime('2020-08-13 14:06:40'))
->setMetaField((new TimesheetMeta())->setName('foo-timesheet')->setValue('bar-timesheet'))
->setMetaField((new TimesheetMeta())->setName('foo-timesheet2')->setValue('bar-timesheet2')->setIsVisible(true))
;
$timesheet2->setDuration(400);
$timesheet2->setRate(84.75);
$timesheet2->setUser($user2);
$timesheet2->setActivity($activity);
$timesheet2->setProject($project);
$timesheet2->setBegin(new \DateTime('2020-08-13 14:00:00'));
$timesheet2->setEnd(new \DateTime('2020-08-13 14:06:40'));
$timesheet2->setMetaField((new TimesheetMeta())->setName('foo-timesheet')->setValue('bar-timesheet'));
$timesheet2->setMetaField((new TimesheetMeta())->setName('foo-timesheet2')->setValue('bar-timesheet2')->setIsVisible(true));
$timesheet3 = new Timesheet();
$timesheet3
->setDuration(1800)
->setRate(111.11)
->setUser($user1)
->setActivity($activity2)
->setDescription('== jhg ljhg ') // make sure that spreadsheets don't render it as formula
->setProject($project2)
->setBegin(new \DateTime('2020-08-12 18:00:00'))
->setEnd(new \DateTime('2020-08-12 18:30:00'))
->setMetaField((new TimesheetMeta())->setName('foo-timesheet')->setValue('bar-timesheet1')->setIsVisible(true))
;
$timesheet3->setDuration(1800);
$timesheet3->setRate(111.11);
$timesheet3->setUser($user1);
$timesheet3->setActivity($activity2);
$timesheet3->setDescription('== jhg ljhg '); // make sure that spreadsheets don't render it as formula
$timesheet3->setProject($project2);
$timesheet3->setBegin(new \DateTime('2020-08-12 18:00:00'));
$timesheet3->setEnd(new \DateTime('2020-08-12 18:30:00'));
$timesheet3->setMetaField((new TimesheetMeta())->setName('foo-timesheet')->setValue('bar-timesheet1')->setIsVisible(true));
$timesheet4 = new Timesheet();
$timesheet4
->setDuration(400)
->setRate(1947.99)
->setUser($user2)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime('2020-12-13 14:00:00'))
->setEnd(new \DateTime('2020-12-13 14:06:40'))
->setDescription(
"foo\n" .
"foo\r\n" .
'foo' . PHP_EOL .
"bar\n" .
"bar\r\n" .
'Hello'
)
->setMetaField((new TimesheetMeta())->setName('foo-timesheet3')->setValue('bluuuub')->setIsVisible(true))
;
$timesheet4->setDuration(400);
$timesheet4->setRate(1947.99);
$timesheet4->setUser($user2);
$timesheet4->setActivity($activity);
$timesheet4->setProject($project);
$timesheet4->setBegin(new \DateTime('2020-12-13 14:00:00'));
$timesheet4->setEnd(new \DateTime('2020-12-13 14:06:40'));
$timesheet4->setDescription(
"foo\n" .
"foo\r\n" .
'foo' . PHP_EOL .
"bar\n" .
"bar\r\n" .
'Hello'
);
$timesheet4->setMetaField((new TimesheetMeta())->setName('foo-timesheet3')->setValue('bluuuub')->setIsVisible(true));
$userKevin = new User();
$userKevin->setUserIdentifier('kevin');
@@ -214,23 +208,21 @@ trait RendererTestTrait
$userKevin->addPreference($pref2);
$timesheet5 = new Timesheet();
$timesheet5
->setDuration(400)
->setFixedRate(84)
->setUser($userKevin)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime('2021-03-12 12:13:00'))
->setEnd(new \DateTime('2021-03-12 12:17:40'))
->setDescription(
"foo\n" .
"foo\r\n" .
'foo' . PHP_EOL .
"bar\n" .
"bar\r\n" .
'Hello'
)
;
$timesheet5->setDuration(400);
$timesheet5->setFixedRate(84);
$timesheet5->setUser($userKevin);
$timesheet5->setActivity($activity);
$timesheet5->setProject($project);
$timesheet5->setBegin(new \DateTime('2021-03-12 12:13:00'));
$timesheet5->setEnd(new \DateTime('2021-03-12 12:17:40'));
$timesheet5->setDescription(
"foo\n" .
"foo\r\n" .
'foo' . PHP_EOL .
"bar\n" .
"bar\r\n" .
'Hello'
);
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];
@@ -279,6 +271,7 @@ trait RendererTestTrait
$user->addPreference(new UserPreference('hello', 'world'));
$customer = new Customer('customer,with/special#name');
$customer->setCountry('DE');
$customer->setCurrency('USD');
$customer->setMetaField((new CustomerMeta())->setName('foo-customer')->setValue('bar-customer')->setIsVisible(true));
@@ -307,15 +300,13 @@ trait RendererTestTrait
$user1->method('getVisiblePreferences')->willReturn([$pref1, $pref2]);
$timesheet = new Timesheet();
$timesheet
->setDuration(3600)
->setRate(293.27)
->setUser($user1)
->setActivity($activity)
->setProject($project)
->setBegin(new \DateTime('2020-08-12 18:00:00'))
->setEnd(new \DateTime('2021-03-12 18:30:00'))
;
$timesheet->setDuration(3600);
$timesheet->setRate(293.27);
$timesheet->setUser($user1);
$timesheet->setActivity($activity);
$timesheet->setProject($project);
$timesheet->setBegin(new \DateTime('2020-08-12 18:00:00'));
$timesheet->setEnd(new \DateTime('2021-03-12 18:30:00'));
$entries = [$timesheet];

View File

@@ -9,6 +9,7 @@
namespace App\Tests\Project;
use App\Configuration\SystemConfiguration;
use App\Entity\Customer;
use App\Entity\Project;
use App\Entity\Team;
@@ -38,7 +39,7 @@ class ProjectServiceTest extends TestCase
private function getSut(
?EventDispatcherInterface $dispatcher = null,
?ValidatorInterface $validator = null,
bool $copyTeamsOnCreate = false
?SystemConfiguration $configuration = null
): ProjectService {
$repository = $this->createMock(ProjectRepository::class);
@@ -54,7 +55,11 @@ class ProjectServiceTest extends TestCase
$validator->method('validate')->willReturn(new ConstraintViolationList());
}
$configuration = SystemConfigurationFactory::createStub(['project' => ['copy_teams_on_create' => $copyTeamsOnCreate]]);
if ($configuration === null) {
$configuration = SystemConfigurationFactory::createStub(
['project' => ['copy_teams_on_create' => false]]
);
}
return new ProjectService($repository, $configuration, $dispatcher, $validator);
}
@@ -151,8 +156,11 @@ class ProjectServiceTest extends TestCase
public function testCreateNewProjectCopiesTeam(): void
{
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$configuration = SystemConfigurationFactory::createStub(
['project' => ['copy_teams_on_create' => true]]
);
$sut = $this->getSut($dispatcher, null, true);
$sut = $this->getSut($dispatcher, null, $configuration);
$team1 = new Team('foo');
$team2 = new Team('bar');
@@ -176,4 +184,78 @@ class ProjectServiceTest extends TestCase
$project = $sut->createNewProject();
self::assertNull($project->getCustomer());
}
/**
* @dataProvider getTestData
*/
public function testProjectNumber(string $format, int|string $expected): void
{
$configuration = SystemConfigurationFactory::createStub([
'project' => [
'copy_teams_on_create' => true,
'number_format' => $format,
]
]);
$sut = $this->getSut(null, null, $configuration);
$project = $sut->createNewProject();
self::assertEquals((string) $expected, $project->getNumber());
}
/**
* @return array<int, array<int, string|\DateTime|int>>
*/
public static function getTestData(): array
{
$dateTime = new \DateTime();
$yearLong = (int) $dateTime->format('Y');
$yearShort = (int) $dateTime->format('y');
$monthLong = $dateTime->format('m');
$monthShort = (int) $dateTime->format('n');
$dayLong = $dateTime->format('d');
$dayShort = (int) $dateTime->format('j');
return [
// simple tests for single calls
['{pc,1}', '2'],
['{pc,2}', '02'],
['{pc,3}', '002'],
['{pc,4}', '0002'],
['{Y}', $yearLong],
['{y}', $yearShort],
['{M}', $monthLong],
['{m}', $monthShort],
['{D}', $dayLong],
['{d}', $dayShort],
// number formatting (not testing the lower case versions, as the tests might break depending on the date)
['{Y,6}', '00' . $yearLong],
['{M,3}', '0' . $monthLong],
['{D,3}', '0' . $dayLong],
// increment dates
['{YY}', $yearLong + 1],
['{YY+1}', $yearLong + 1],
['{YY+2}', $yearLong + 2],
['{YY+3}', $yearLong + 3],
['{YY-1}', $yearLong - 1],
['{YY-2}', $yearLong - 2],
['{YY-3}', $yearLong - 3],
['{yy}', $yearShort + 1],
['{yy+1}', $yearShort + 1],
['{yy+2}', $yearShort + 2],
['{yy+3}', $yearShort + 3],
['{yy-1}', $yearShort - 1],
['{yy-2}', $yearShort - 2],
['{yy-3}', $yearShort - 3],
['{MM}', $monthShort + 1], // cast to int removes leading zero
['{MM+1}', $monthShort + 1], // cast to int removes leading zero
['{MM+2}', $monthShort + 2], // cast to int removes leading zero
['{MM+3}', $monthShort + 3], // cast to int removes leading zero
['{DD}', $dayShort + 1], // cast to int removes leading zero
['{DD+1}', $dayShort + 1], // cast to int removes leading zero
['{DD+2}', $dayShort + 2], // cast to int removes leading zero
['{DD+3}', $dayShort + 3], // cast to int removes leading zero
];
}
}

View File

@@ -132,15 +132,13 @@ class RateCalculatorTest extends TestCase
$activity->setProject($project);
$timesheet = new Timesheet();
$timesheet
->setEnd(new \DateTime())
->setHourlyRate($timesheetHourly)
->setFixedRate($timesheetFixed)
->setActivity($activity)
->setProject($project)
->setDuration($duration)
->setUser($this->getTestUser($userRate, $userInternalRate))
;
$timesheet->setEnd(new \DateTime());
$timesheet->setHourlyRate($timesheetHourly);
$timesheet->setFixedRate($timesheetFixed);
$timesheet->setActivity($activity);
$timesheet->setProject($project);
$timesheet->setDuration($duration);
$timesheet->setUser($this->getTestUser($userRate, $userInternalRate));
$rates = [];

View File

@@ -45,7 +45,6 @@ class DateTimeFactoryTest extends TestCase
public function testGetStartOfMonth(): void
{
$expected = new DateTime('now', new DateTimeZone(self::TEST_TIMEZONE));
$sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
$dateTime = $sut->getStartOfMonth();
self::assertEquals(0, $dateTime->format('H'));
@@ -55,12 +54,30 @@ class DateTimeFactoryTest extends TestCase
self::assertEquals($expected->format('m'), $dateTime->format('m'));
self::assertEquals($expected->format('Y'), $dateTime->format('Y'));
self::assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
$dateTime = $sut->getStartOfMonth('now');
self::assertEquals(0, $dateTime->format('H'));
self::assertEquals(0, $dateTime->format('i'));
self::assertEquals(0, $dateTime->format('s'));
self::assertEquals(1, $dateTime->format('d'));
self::assertEquals($expected->format('m'), $dateTime->format('m'));
self::assertEquals($expected->format('Y'), $dateTime->format('Y'));
self::assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
$expected = new DateTime('now', new DateTimeZone('Atlantic/Canary'));
$dateTime = $sut->getStartOfMonth($expected);
self::assertEquals(0, $dateTime->format('H'));
self::assertEquals(0, $dateTime->format('i'));
self::assertEquals(0, $dateTime->format('s'));
self::assertEquals(1, $dateTime->format('d'));
self::assertEquals($expected->format('m'), $dateTime->format('m'));
self::assertEquals($expected->format('Y'), $dateTime->format('Y'));
self::assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
}
public function testGetEndOfMonth(): void
{
$expected = new DateTime('last day of this month', new DateTimeZone(self::TEST_TIMEZONE));
$sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
$dateTime = $sut->getEndOfMonth();
self::assertEquals(23, $dateTime->format('H'));
@@ -70,6 +87,26 @@ class DateTimeFactoryTest extends TestCase
self::assertEquals($expected->format('m'), $dateTime->format('m'));
self::assertEquals($expected->format('Y'), $dateTime->format('Y'));
self::assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
$sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
$dateTime = $sut->getEndOfMonth('last day of this month');
self::assertEquals(23, $dateTime->format('H'));
self::assertEquals(59, $dateTime->format('i'));
self::assertEquals(59, $dateTime->format('s'));
self::assertEquals($expected->format('d'), $dateTime->format('d'));
self::assertEquals($expected->format('m'), $dateTime->format('m'));
self::assertEquals($expected->format('Y'), $dateTime->format('Y'));
self::assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
$expected = new DateTime('last day of this month', new DateTimeZone('Atlantic/Canary'));
$dateTime = $sut->getEndOfMonth($expected);
self::assertEquals(23, $dateTime->format('H'));
self::assertEquals(59, $dateTime->format('i'));
self::assertEquals(59, $dateTime->format('s'));
self::assertEquals($expected->format('d'), $dateTime->format('d'));
self::assertEquals($expected->format('m'), $dateTime->format('m'));
self::assertEquals($expected->format('Y'), $dateTime->format('Y'));
self::assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
}
public static function getStartOfWeekData()
@@ -175,6 +212,8 @@ class DateTimeFactoryTest extends TestCase
$sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
$dateTime = $sut->createStartOfFinancialYear();
$expected = $sut->createDateTime('01 january this year 00:00:00');
self::assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
self::assertInstanceOf(DateTime::class, $dateTime);
self::assertEquals($expected, $dateTime);
}
@@ -224,6 +263,7 @@ class DateTimeFactoryTest extends TestCase
$now = $sut->createDateTime();
$year = $sut->createStartOfYear();
self::assertEquals(self::TEST_TIMEZONE, $year->getTimezone()->getName());
self::assertEquals($now->format('Y'), $year->format('Y'));
self::assertEquals('01', $year->format('m'));
self::assertEquals('01', $year->format('d'));
@@ -233,6 +273,15 @@ class DateTimeFactoryTest extends TestCase
$begin = $sut->createDateTime('2017-12-31 23:59:59');
$year = $sut->createStartOfYear($begin);
self::assertEquals(self::TEST_TIMEZONE, $year->getTimezone()->getName());
self::assertEquals('2017', $year->format('Y'));
self::assertEquals('01', $year->format('m'));
self::assertEquals('01', $year->format('d'));
self::assertEquals('00:00:00', $year->format('H:i:s'));
$begin = new \DateTime('2017-12-01 23:59:59', new DateTimeZone('Atlantic/Canary'));
$year = $sut->createStartOfYear($begin);
self::assertEquals(self::TEST_TIMEZONE, $year->getTimezone()->getName());
self::assertEquals('2017', $year->format('Y'));
self::assertEquals('01', $year->format('m'));
self::assertEquals('01', $year->format('d'));
@@ -245,6 +294,7 @@ class DateTimeFactoryTest extends TestCase
$now = $sut->createDateTime();
$year = $sut->createEndOfYear();
self::assertEquals(self::TEST_TIMEZONE, $year->getTimezone()->getName());
self::assertEquals($now->format('Y'), $year->format('Y'));
self::assertEquals('12', $year->format('m'));
self::assertEquals('31', $year->format('d'));
@@ -254,9 +304,45 @@ class DateTimeFactoryTest extends TestCase
$begin = $sut->createDateTime('2017-12-31 23:59:59');
$year = $sut->createEndOfYear($begin);
self::assertEquals(self::TEST_TIMEZONE, $year->getTimezone()->getName());
self::assertEquals('2017', $year->format('Y'));
self::assertEquals('12', $year->format('m'));
self::assertEquals('31', $year->format('d'));
self::assertEquals('23:59:59', $year->format('H:i:s'));
$begin = new \DateTime('2017-12-01 23:59:59', new DateTimeZone('Atlantic/Canary'));
$year = $sut->createEndOfYear($begin);
self::assertEquals(self::TEST_TIMEZONE, $year->getTimezone()->getName());
self::assertEquals('2017', $year->format('Y'));
self::assertEquals('12', $year->format('m'));
self::assertEquals('31', $year->format('d'));
self::assertEquals('23:59:59', $year->format('H:i:s'));
}
public function testCreate(): void
{
$sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
$dateTime = $sut->create('2025-04-22 17:29:30');
self::assertEquals(17, $dateTime->format('H'));
self::assertEquals(29, $dateTime->format('i'));
self::assertEquals(30, $dateTime->format('s'));
self::assertEquals('22', $dateTime->format('d'));
self::assertEquals('04', $dateTime->format('m'));
self::assertEquals('2025', $dateTime->format('Y'));
self::assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
}
public function testCreateFromFormat(): void
{
$sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
$dateTime = $sut->createDateTimeFromFormat('H:i:s m.d-Y', '17:29:30 04.22-2025');
self::assertInstanceOf(DateTime::class, $dateTime);
self::assertEquals(17, $dateTime->format('H'));
self::assertEquals(29, $dateTime->format('i'));
self::assertEquals(30, $dateTime->format('s'));
self::assertEquals('22', $dateTime->format('d'));
self::assertEquals('04', $dateTime->format('m'));
self::assertEquals('2025', $dateTime->format('Y'));
self::assertEquals(self::TEST_TIMEZONE, $dateTime->getTimezone()->getName());
}
}

View File

@@ -136,15 +136,13 @@ class RateServiceTest extends TestCase
$activity->setProject($project);
$timesheet = new Timesheet();
$timesheet
->setEnd(self::createDateTime())
->setHourlyRate($timesheetHourly)
->setFixedRate($timesheetFixed)
->setActivity($activity)
->setProject($project)
->setDuration($duration)
->setUser($this->getTestUser($userRate, $userInternalRate))
;
$timesheet->setEnd(self::createDateTime());
$timesheet->setHourlyRate($timesheetHourly);
$timesheet->setFixedRate($timesheetFixed);
$timesheet->setActivity($activity);
$timesheet->setProject($project);
$timesheet->setDuration($duration);
$timesheet->setUser($this->getTestUser($userRate, $userInternalRate));
$rates = [];