Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)

This commit is contained in:
Kevin Papst
2022-12-31 21:19:55 +01:00
committed by GitHub
parent 95e06746bd
commit 90a0fd8a22
2164 changed files with 83700 additions and 86426 deletions

View File

@@ -42,17 +42,17 @@ class BillableCalculatorTest extends TestCase
}
$timesheet->setBillable($billable);
$timesheet->setBillableMode($mode);
$sut->calculate($timesheet);
$sut->calculate($timesheet, []);
self::assertEquals($mode, $timesheet->getBillableMode());
self::assertEquals($expected, $timesheet->isBillable());
}
public function getTestData()
{
$customerYes = new Customer();
$customerYes = new Customer('foo');
$customerYes->setBillable(true);
$customerNo = new Customer();
$customerNo = new Customer('foo');
$customerNo->setBillable(false);
$projectYes = new Project();

View File

@@ -27,7 +27,7 @@ class DurationCalculatorTest extends TestCase
$this->assertEquals(0, $record->getDuration());
$sut = new DurationCalculator((new RoundingServiceFactory($this))->create());
$sut->calculate($record);
$sut->calculate($record, []);
$this->assertEquals(0, $record->getDuration());
}
@@ -42,7 +42,7 @@ class DurationCalculatorTest extends TestCase
$this->assertEquals(0, $record->getDuration());
$sut = new DurationCalculator((new RoundingServiceFactory($this))->create($rules));
$sut->calculate($record);
$sut->calculate($record, []);
$this->assertEquals($expectedDuration, $record->getDuration());
}
@@ -195,8 +195,8 @@ class DurationCalculatorTest extends TestCase
'mode' => 'default',
],
],
(clone $start)->setTime(12, 27, 00), // no diff, to test ...
(clone $start)->setTime(12, 27, 00), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 0), // no diff, to test ...
(clone $start)->setTime(12, 27, 0), // ... that no rounding is applied
0
],
[

View File

@@ -48,7 +48,7 @@ class RateCalculatorTest extends TestCase
$record->setUser($this->getTestUser());
$sut = new RateCalculator(new RateService([], $this->getRateRepositoryMock()));
$sut->calculate($record);
$sut->calculate($record, []);
$this->assertEquals(50, $record->getRate());
}
@@ -64,7 +64,7 @@ class RateCalculatorTest extends TestCase
$record->setUser($this->getTestUser());
$sut = new RateCalculator(new RateService([], $this->getRateRepositoryMock()));
$sut->calculate($record);
$sut->calculate($record, []);
$this->assertEquals(10, $record->getRate());
}
@@ -123,7 +123,7 @@ class RateCalculatorTest extends TestCase
$customerInternal,
$customerIsFixed
) {
$customer = new Customer();
$customer = new Customer('foo');
$project = new Project();
$project->setCustomer($customer);
@@ -175,7 +175,7 @@ class RateCalculatorTest extends TestCase
}
$sut = new RateCalculator(new RateService([], $this->getRateRepositoryMock($rates)));
$sut->calculate($timesheet);
$sut->calculate($timesheet, []);
$this->assertEquals($expectedRate, $timesheet->getRate());
$this->assertEquals($expectedInternalRate, $timesheet->getInternalRate());
}
@@ -184,13 +184,8 @@ class RateCalculatorTest extends TestCase
{
$user = new User();
$pref = new UserPreference();
$pref->setName(UserPreference::HOURLY_RATE);
$pref->setValue($rate);
$prefInt = new UserPreference();
$prefInt->setName(UserPreference::INTERNAL_RATE);
$prefInt->setValue($internalRate);
$pref = new UserPreference(UserPreference::HOURLY_RATE, $rate);
$prefInt = new UserPreference(UserPreference::INTERNAL_RATE, $internalRate);
$user->setPreferences([$pref, $prefInt]);
@@ -209,7 +204,7 @@ class RateCalculatorTest extends TestCase
$this->assertEquals(0, $record->getRate());
$sut = new RateCalculator(new RateService([], $this->getRateRepositoryMock()));
$sut->calculate($record);
$sut->calculate($record, []);
$this->assertEquals(0, $record->getRate());
}
@@ -235,7 +230,7 @@ class RateCalculatorTest extends TestCase
$record->setEnd($end);
$sut = new RateCalculator(new RateService($rules, $this->getRateRepositoryMock()));
$sut->calculate($record);
$sut->calculate($record, []);
$this->assertEquals($expectedRate, $record->getRate());
}

View File

@@ -0,0 +1,56 @@
<?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\Timesheet\Calculator;
use App\Entity\Project;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Entity\UserPreference;
use App\Timesheet\Calculator\RateResetCalculator;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\Calculator\RateResetCalculator
*/
class RateResetCalculatorTest extends TestCase
{
public function testWithReset(): void
{
$record = new Timesheet();
$record->setRate(999.99);
$record->setHourlyRate(100);
$record->setFixedRate(123.45);
$record->setInternalRate(98.76);
$record->setBillableMode(Timesheet::BILLABLE_NO);
$user = new User();
$user->setPreferences([
new UserPreference(UserPreference::HOURLY_RATE, 75),
new UserPreference(UserPreference::INTERNAL_RATE, 25)
]);
$record->setUser($user);
self::assertEquals(999.99, $record->getRate());
self::assertEquals(100, $record->getHourlyRate());
self::assertEquals(123.45, $record->getFixedRate());
self::assertEquals(98.76, $record->getInternalRate());
self::assertEquals(Timesheet::BILLABLE_NO, $record->getBillableMode());
$sut = new RateResetCalculator();
// 0 = before, 1 = after
$sut->calculate($record, ['project' => [0 => new Project(), 1 => new Project()]]);
self::assertEquals(0.00, $record->getRate());
self::assertNull($record->getHourlyRate());
self::assertNull($record->getFixedRate());
self::assertNull($record->getInternalRate());
self::assertEquals(Timesheet::BILLABLE_AUTOMATIC, $record->getBillableMode());
}
}

View File

@@ -10,8 +10,8 @@
namespace App\Tests\Timesheet;
use App\Configuration\ConfigLoaderInterface;
use App\Configuration\SystemConfiguration;
use App\Entity\Timesheet;
use App\Tests\Mocks\SystemConfigurationFactory;
use App\Timesheet\LockdownService;
use PHPUnit\Framework\TestCase;
@@ -20,10 +20,10 @@ use PHPUnit\Framework\TestCase;
*/
class LockdownServiceTest extends TestCase
{
protected function createService(?string $start, ?string $end, ?string $grace, ?string $timezone = null)
protected function createService(?string $start, ?string $end, ?string $grace = null, ?string $timezone = null): LockdownService
{
$loader = $this->createMock(ConfigLoaderInterface::class);
$config = new SystemConfiguration($loader, [
$config = SystemConfigurationFactory::create($loader, [
'timesheet' => [
'rules' => [
'lockdown_period_start' => $start,
@@ -37,7 +37,7 @@ class LockdownServiceTest extends TestCase
return new LockdownService($config);
}
public function testValidatorWithoutNowConstraint()
public function testValidatorWithoutNowConstraint(): void
{
$sut = $this->createService('first day of last month', 'last day of last month', '+10 days');
@@ -49,14 +49,14 @@ class LockdownServiceTest extends TestCase
self::assertFalse($sut->isEditable($timesheet, new \DateTime(), false));
}
public function testValidatorWithEmptyTimesheet()
public function testValidatorWithEmptyTimesheet(): void
{
$sut = $this->createService('first day of last month', 'last day of last month', '+10 days');
self::assertTrue($sut->isEditable(new Timesheet(), new \DateTime(), false));
}
public function testValidatorWithoutNowStringConstraint()
public function testValidatorWithoutNowStringConstraint(): void
{
$sut = $this->createService('first day of last month', 'last day of last month', '+10 days');
@@ -68,7 +68,7 @@ class LockdownServiceTest extends TestCase
self::assertTrue($sut->isEditable($timesheet, new \DateTime('first day of this month'), false));
}
public function testValidatorWithEndBeforeStartPeriod()
public function testValidatorWithEndBeforeStartPeriod(): void
{
$sut = $this->createService('first day of this month', 'last day of last month', '+10 days');
@@ -83,7 +83,7 @@ class LockdownServiceTest extends TestCase
/**
* @dataProvider getTestData
*/
public function testLockdown(bool $allowOverwriteGrace, string $beginModifier, string $nowModifier, bool $isViolation)
public function testLockdown(bool $allowOverwriteGrace, string $beginModifier, string $nowModifier, bool $isViolation): void
{
$sut = $this->createService('first day of last month', 'last day of last month', '+10 days');
@@ -120,7 +120,7 @@ class LockdownServiceTest extends TestCase
/**
* @dataProvider getConfigTestData
*/
public function testLockdownConfig(bool $allowOverwriteGrace, ?string $lockdownBegin, ?string $lockdownEnd, ?string $grace, bool $isViolation)
public function testLockdownConfig(bool $allowOverwriteGrace, ?string $lockdownBegin, ?string $lockdownEnd, ?string $grace, bool $isViolation): void
{
$sut = $this->createService($lockdownBegin, $lockdownEnd, $grace);
@@ -149,4 +149,19 @@ class LockdownServiceTest extends TestCase
yield [true, 'öööö', '+11 days', null, false];
yield [true, '+5 days', '+5 of !!!!', null, false];
}
public function testIsLockdownActive(): void
{
$sut = $this->createService(null, null);
self::assertFalse($sut->isLockdownActive());
$sut = $this->createService('+5 days', null);
self::assertFalse($sut->isLockdownActive());
$sut = $this->createService(null, '+5 days');
self::assertFalse($sut->isLockdownActive());
$sut = $this->createService('+5 days', '+5 days');
self::assertTrue($sut->isLockdownActive());
}
}

View File

@@ -37,10 +37,15 @@ class RateServiceTest extends TestCase
return $mock;
}
private function createDateTime(string $datetime = null): \DateTime
{
return new \DateTime($datetime ?? 'now', new \DateTimeZone('UTC'));
}
public function testCalculateWithTimesheetHourlyRate()
{
$record = new Timesheet();
$record->setEnd(new \DateTime());
$record->setEnd($this->createDateTime());
$record->setDuration(1800);
$record->setHourlyRate(100);
$record->setActivity(new Activity());
@@ -54,7 +59,7 @@ class RateServiceTest extends TestCase
public function testCalculateWithTimesheetFixedRate()
{
$record = new Timesheet();
$record->setEnd(new \DateTime());
$record->setEnd($this->createDateTime());
$record->setDuration(1800);
$record->setFixedRate(10);
// make sure that fixed rate is always applied, even if hourly rate is set
@@ -122,7 +127,7 @@ class RateServiceTest extends TestCase
$customerInternal,
$customerIsFixed
) {
$customer = new Customer();
$customer = new Customer('foo');
$project = new Project();
$project->setCustomer($customer);
@@ -132,7 +137,7 @@ class RateServiceTest extends TestCase
$timesheet = new Timesheet();
$timesheet
->setEnd(new \DateTime())
->setEnd($this->createDateTime())
->setHourlyRate($timesheetHourly)
->setFixedRate($timesheetFixed)
->setActivity($activity)
@@ -183,13 +188,8 @@ class RateServiceTest extends TestCase
{
$user = new User();
$pref = new UserPreference();
$pref->setName(UserPreference::HOURLY_RATE);
$pref->setValue($rate);
$prefInt = new UserPreference();
$prefInt->setName(UserPreference::INTERNAL_RATE);
$prefInt->setValue($internalRate);
$pref = new UserPreference(UserPreference::HOURLY_RATE, $rate);
$prefInt = new UserPreference(UserPreference::INTERNAL_RATE, $internalRate);
$user->setPreferences([$pref, $prefInt]);
@@ -199,7 +199,7 @@ class RateServiceTest extends TestCase
public function testCalculateWithEmptyEnd()
{
$record = new Timesheet();
$record->setBegin(new \DateTime());
$record->setBegin($this->createDateTime());
$record->setDuration(1800);
$record->setFixedRate(100);
$record->setHourlyRate(100);
@@ -219,7 +219,7 @@ class RateServiceTest extends TestCase
*/
public function testCalculateWithRulesByUsersHourlyRate($duration, $rules, $expectedRate)
{
$end = new \DateTime('12:00:00', new \DateTimeZone('UTC'));
$end = $this->createDateTime('12:00:00');
$start = clone $end;
$start->setTimestamp($end->getTimestamp() - $duration);
@@ -241,7 +241,7 @@ class RateServiceTest extends TestCase
public function getRuleDefinitions()
{
$start = new \DateTime('12:00:00', new \DateTimeZone('UTC'));
$start = $this->createDateTime('12:00:00');
$day = $start->format('l');
return [

View File

@@ -64,8 +64,8 @@ class CeilRoundingTest extends TestCase
0,
(clone $start)->setTime(12, 17, 35),
(clone $start)->setTime(13, 32, 52),
(clone $start)->setTime(12, 30, 00),
(clone $start)->setTime(13, 45, 00),
(clone $start)->setTime(12, 30, 0),
(clone $start)->setTime(13, 45, 0),
4500
],
[
@@ -84,8 +84,8 @@ class CeilRoundingTest extends TestCase
0,
(clone $start)->setTime(12, 17, 35),
(clone $start)->setTime(13, 32, 52),
(clone $start)->setTime(12, 18, 00),
(clone $start)->setTime(13, 33, 00),
(clone $start)->setTime(12, 18, 0),
(clone $start)->setTime(13, 33, 0),
4500
],
[
@@ -105,7 +105,7 @@ class CeilRoundingTest extends TestCase
(clone $start)->setTime(12, 27, 35), // 12:15
(clone $start)->setTime(14, 32, 52), // 14:33 => 2:18 => 2:30
(clone $start)->setTime(12, 27, 35),
(clone $start)->setTime(14, 33, 00),
(clone $start)->setTime(14, 33, 0),
9000
],
[
@@ -114,7 +114,7 @@ class CeilRoundingTest extends TestCase
30,
(clone $start)->setTime(12, 27, 35), // 12:15
(clone $start)->setTime(14, 32, 52), // 14:33 => 2:18 (second duration will not be rounded)
(clone $start)->setTime(12, 30, 00), // 12:15
(clone $start)->setTime(12, 30, 0), // 12:15
(clone $start)->setTime(14, 32, 52), // 14:33 => 2:18 (second duration will not be rounded)
9000
],
@@ -132,10 +132,10 @@ class CeilRoundingTest extends TestCase
1,
1,
1,
(clone $start)->setTime(12, 27, 00), // no diff, to test ...
(clone $start)->setTime(12, 27, 00), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 00), // no diff, to test ...
(clone $start)->setTime(12, 27, 00), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 0), // no diff, to test ...
(clone $start)->setTime(12, 27, 0), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 0), // no diff, to test ...
(clone $start)->setTime(12, 27, 0), // ... that no rounding is applied
0
],
[

View File

@@ -64,8 +64,8 @@ class ClosestRoundingTest extends TestCase
0,
(clone $start)->setTime(12, 17, 35),
(clone $start)->setTime(13, 32, 52),
(clone $start)->setTime(12, 15, 00),
(clone $start)->setTime(13, 30, 00),
(clone $start)->setTime(12, 15, 0),
(clone $start)->setTime(13, 30, 0),
4500
],
[
@@ -84,8 +84,8 @@ class ClosestRoundingTest extends TestCase
0,
(clone $start)->setTime(12, 17, 35),
(clone $start)->setTime(13, 32, 52),
(clone $start)->setTime(12, 18, 00),
(clone $start)->setTime(13, 33, 00),
(clone $start)->setTime(12, 18, 0),
(clone $start)->setTime(13, 33, 0),
4500
],
[
@@ -105,7 +105,7 @@ class ClosestRoundingTest extends TestCase
(clone $start)->setTime(12, 27, 35), // 12:15
(clone $start)->setTime(14, 32, 52), // 14:33 => 2:18 => 2:30
(clone $start)->setTime(12, 27, 35),
(clone $start)->setTime(14, 33, 00),
(clone $start)->setTime(14, 33, 0),
7200
],
[
@@ -114,7 +114,7 @@ class ClosestRoundingTest extends TestCase
30,
(clone $start)->setTime(12, 27, 35), // 12:15
(clone $start)->setTime(14, 32, 52), // 14:33 => 2:18 (second duration will not be rounded)
(clone $start)->setTime(12, 30, 00), // 12:15
(clone $start)->setTime(12, 30, 0), // 12:15
(clone $start)->setTime(14, 32, 52), // 14:33 => 2:18 (second duration will not be rounded)
7200
],
@@ -132,10 +132,10 @@ class ClosestRoundingTest extends TestCase
1,
1,
1,
(clone $start)->setTime(12, 27, 00), // no diff, to test ...
(clone $start)->setTime(12, 27, 00), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 00), // no diff, to test ...
(clone $start)->setTime(12, 27, 00), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 0), // no diff, to test ...
(clone $start)->setTime(12, 27, 0), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 0), // no diff, to test ...
(clone $start)->setTime(12, 27, 0), // ... that no rounding is applied
0
],
[

View File

@@ -64,8 +64,8 @@ class DefaultRoundingTest extends TestCase
0,
(clone $start)->setTime(12, 17, 35),
(clone $start)->setTime(13, 32, 52),
(clone $start)->setTime(12, 15, 00),
(clone $start)->setTime(13, 45, 00),
(clone $start)->setTime(12, 15, 0),
(clone $start)->setTime(13, 45, 0),
5400
],
[
@@ -84,8 +84,8 @@ class DefaultRoundingTest extends TestCase
0,
(clone $start)->setTime(12, 17, 35),
(clone $start)->setTime(13, 32, 52),
(clone $start)->setTime(12, 17, 00),
(clone $start)->setTime(13, 33, 00),
(clone $start)->setTime(12, 17, 0),
(clone $start)->setTime(13, 33, 0),
4560
],
[
@@ -105,7 +105,7 @@ class DefaultRoundingTest extends TestCase
(clone $start)->setTime(12, 27, 35), // 12:15
(clone $start)->setTime(14, 32, 52), // 14:33 => 2:18 => 2:30
(clone $start)->setTime(12, 27, 35),
(clone $start)->setTime(14, 33, 00),
(clone $start)->setTime(14, 33, 0),
9000
],
[
@@ -114,7 +114,7 @@ class DefaultRoundingTest extends TestCase
30,
(clone $start)->setTime(12, 27, 35), // 12:15
(clone $start)->setTime(14, 32, 52), // 14:33 => 2:18 (second duration will not be rounded)
(clone $start)->setTime(12, 15, 00), // 12:15
(clone $start)->setTime(12, 15, 0), // 12:15
(clone $start)->setTime(14, 32, 52), // 14:33 => 2:18 (second duration will not be rounded)
9000
],
@@ -132,10 +132,10 @@ class DefaultRoundingTest extends TestCase
1,
1,
1,
(clone $start)->setTime(12, 27, 00), // no diff, to test ...
(clone $start)->setTime(12, 27, 00), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 00), // no diff, to test ...
(clone $start)->setTime(12, 27, 00), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 0), // no diff, to test ...
(clone $start)->setTime(12, 27, 0), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 0), // no diff, to test ...
(clone $start)->setTime(12, 27, 0), // ... that no rounding is applied
0
],
[

View File

@@ -64,8 +64,8 @@ class FloorRoundingTest extends TestCase
0,
(clone $start)->setTime(12, 17, 35),
(clone $start)->setTime(13, 32, 52),
(clone $start)->setTime(12, 15, 00),
(clone $start)->setTime(13, 30, 00),
(clone $start)->setTime(12, 15, 0),
(clone $start)->setTime(13, 30, 0),
4500
],
[
@@ -84,8 +84,8 @@ class FloorRoundingTest extends TestCase
0,
(clone $start)->setTime(12, 17, 35),
(clone $start)->setTime(13, 32, 52),
(clone $start)->setTime(12, 17, 00),
(clone $start)->setTime(13, 32, 00),
(clone $start)->setTime(12, 17, 0),
(clone $start)->setTime(13, 32, 0),
4500
],
[
@@ -105,7 +105,7 @@ class FloorRoundingTest extends TestCase
(clone $start)->setTime(12, 27, 35), // 12:15
(clone $start)->setTime(14, 32, 52), // 14:33 => 2:18 => 2:30
(clone $start)->setTime(12, 27, 35),
(clone $start)->setTime(14, 32, 00),
(clone $start)->setTime(14, 32, 0),
7200
],
[
@@ -114,7 +114,7 @@ class FloorRoundingTest extends TestCase
30,
(clone $start)->setTime(12, 27, 35), // 12:15
(clone $start)->setTime(14, 32, 52), // 14:33 => 2:18 (second duration will not be rounded)
(clone $start)->setTime(12, 15, 00), // 12:15
(clone $start)->setTime(12, 15, 0), // 12:15
(clone $start)->setTime(14, 32, 52), // 14:33 => 2:18 (second duration will not be rounded)
7200
],
@@ -132,10 +132,10 @@ class FloorRoundingTest extends TestCase
1,
1,
1,
(clone $start)->setTime(12, 27, 00), // no diff, to test ...
(clone $start)->setTime(12, 27, 00), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 00), // no diff, to test ...
(clone $start)->setTime(12, 27, 00), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 0), // no diff, to test ...
(clone $start)->setTime(12, 27, 0), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 0), // no diff, to test ...
(clone $start)->setTime(12, 27, 0), // ... that no rounding is applied
0
],
[

View File

@@ -79,8 +79,8 @@ class RoundingServiceTest extends TestCase
],
(clone $start)->setTime(12, 17, 35),
(clone $start)->setTime(13, 32, 52),
(clone $start)->setTime(12, 15, 00),
(clone $start)->setTime(13, 45, 00),
(clone $start)->setTime(12, 15, 0),
(clone $start)->setTime(13, 45, 0),
5400
],
[
@@ -111,8 +111,8 @@ class RoundingServiceTest extends TestCase
],
(clone $start)->setTime(12, 17, 35),
(clone $start)->setTime(13, 32, 52),
(clone $start)->setTime(12, 17, 00),
(clone $start)->setTime(13, 33, 00),
(clone $start)->setTime(12, 17, 0),
(clone $start)->setTime(13, 33, 0),
4560
],
[
@@ -150,8 +150,8 @@ class RoundingServiceTest extends TestCase
],
(clone $start)->setTime(12, 27, 35), // 12:15
(clone $start)->setTime(14, 32, 52), // 14:33 => 2:18 => 2:30
(clone $start)->setTime(12, 15, 00), // 12:15
(clone $start)->setTime(14, 33, 00), // 14:33 => 2:18 => 2:30
(clone $start)->setTime(12, 15, 0), // 12:15
(clone $start)->setTime(14, 33, 0), // 14:33 => 2:18 => 2:30
9000
],
[
@@ -173,8 +173,8 @@ class RoundingServiceTest extends TestCase
],
(clone $start)->setTime(12, 27, 35), // 12:15
(clone $start)->setTime(14, 32, 52), // 14:33 => 2:18 (second duration will not be rounded)
(clone $start)->setTime(12, 15, 00), // 12:15
(clone $start)->setTime(14, 33, 00), // 14:33 => 2:18 (second duration will not be rounded)
(clone $start)->setTime(12, 15, 0), // 12:15
(clone $start)->setTime(14, 33, 0), // 14:33 => 2:18 (second duration will not be rounded)
9000
],
[
@@ -217,10 +217,10 @@ class RoundingServiceTest extends TestCase
'mode' => 'default',
],
],
(clone $start)->setTime(12, 27, 00), // no diff, to test ...
(clone $start)->setTime(12, 27, 00), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 00), // no diff, to test ...
(clone $start)->setTime(12, 27, 00), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 0), // no diff, to test ...
(clone $start)->setTime(12, 27, 0), // ... that no rounding is applied
(clone $start)->setTime(12, 27, 0), // no diff, to test ...
(clone $start)->setTime(12, 27, 0), // ... that no rounding is applied
0
],
[

View File

@@ -9,7 +9,6 @@
namespace App\Tests\Timesheet;
use App\Configuration\SystemConfiguration;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Event\TimesheetCreatePostEvent;
@@ -19,6 +18,7 @@ use App\Event\TimesheetDeletePreEvent;
use App\Event\TimesheetRestartPostEvent;
use App\Event\TimesheetRestartPreEvent;
use App\Repository\TimesheetRepository;
use App\Tests\Mocks\SystemConfigurationFactory;
use App\Timesheet\TimesheetService;
use App\Timesheet\TrackingModeService;
use App\Validator\ValidationFailedException;
@@ -41,8 +41,7 @@ class TimesheetServiceTest extends TestCase
?ValidatorInterface $validator = null,
?TimesheetRepository $repository = null
): TimesheetService {
$configuration = $this->createMock(SystemConfiguration::class);
$configuration->method('getTimesheetActiveEntriesHardLimit')->willReturn(1);
$configuration = SystemConfigurationFactory::createStub(['timesheet' => ['active_entries' => ['hard_limit' => 1]]]);
if ($repository === null) {
$repository = $this->createMock(TimesheetRepository::class);
@@ -190,6 +189,8 @@ class TimesheetServiceTest extends TestCase
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$dispatcher->method('dispatch')->willReturnCallback(function ($event) {
self::assertInstanceOf(TimesheetRestartPreEvent::class, $event);
return $event;
});
$sut = $this->getSut(null, $dispatcher);
@@ -223,6 +224,8 @@ class TimesheetServiceTest extends TestCase
self::assertInstanceOf(TimesheetRestartPostEvent::class, $event);
break;
}
return $event;
});
$sut = $this->getSut($authorizationChecker, $dispatcher);
@@ -256,6 +259,20 @@ class TimesheetServiceTest extends TestCase
self::assertSame($dateTime->getTimestamp(), $timesheet->getEnd()->getTimestamp());
}
public function testStopSetsEnd()
{
$dateTime = new \DateTime('-2 hours');
$timesheet = new Timesheet();
$timesheet->setBegin($dateTime);
$sut = $this->getSut();
self::assertNull($timesheet->getEnd());
$sut->stopTimesheet($timesheet);
self::assertNotNull($timesheet->getEnd());
}
public function testDeleteDispatchesEvent()
{
$timesheet = new Timesheet();
@@ -265,6 +282,8 @@ class TimesheetServiceTest extends TestCase
self::assertInstanceOf(TimesheetDeletePreEvent::class, $event);
/* @var TimesheetDeletePreEvent $event */
self::assertSame($timesheet, $event->getTimesheet());
return $event;
});
$sut = $this->getSut(null, $dispatcher);
@@ -281,6 +300,8 @@ class TimesheetServiceTest extends TestCase
self::assertInstanceOf(TimesheetDeleteMultiplePreEvent::class, $event);
/* @var TimesheetDeleteMultiplePreEvent $event */
self::assertSame($timesheets, $event->getTimesheets());
return $event;
});
$sut = $this->getSut(null, $dispatcher);

View File

@@ -9,10 +9,10 @@
namespace App\Tests\Timesheet\TrackingMode;
use App\Configuration\SystemConfiguration;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Tests\Configuration\TestConfigLoader;
use App\Tests\Mocks\SystemConfigurationFactory;
use App\Timesheet\TrackingMode\DurationFixedBeginMode;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
@@ -25,7 +25,7 @@ class DurationFixedBeginModeTest extends TestCase
protected function createSut($default = '13:47')
{
$loader = new TestConfigLoader([]);
$configuration = new SystemConfiguration($loader, ['timesheet' => ['default_begin' => $default]]);
$configuration = SystemConfigurationFactory::create($loader, ['timesheet' => ['default_begin' => $default]]);
return new DurationFixedBeginMode($configuration);
}

View File

@@ -1,59 +0,0 @@
<?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\Timesheet\TrackingMode;
use App\Configuration\SystemConfiguration;
use App\Entity\Timesheet;
use App\Tests\Configuration\TestConfigLoader;
use App\Timesheet\TrackingMode\DurationOnlyMode;
/**
* @covers \App\Timesheet\TrackingMode\DurationOnlyMode
*/
class DurationOnlyModeTest extends AbstractTrackingModeTest
{
protected function assertDefaultBegin(Timesheet $timesheet)
{
self::assertNotNull($timesheet->getBegin());
self::assertEquals('13:45:37', $timesheet->getBegin()->format('H:i:s'));
}
protected function createSut($default = '13:45:37')
{
$loader = new TestConfigLoader([]);
$configuration = new SystemConfiguration($loader, ['timesheet' => ['default_begin' => $default]]);
return new DurationOnlyMode($configuration);
}
public function testNow()
{
$seconds = (new \DateTime())->getTimestamp();
$timesheet = new Timesheet();
$timesheet->setBegin(new \DateTime('18:50:32'));
$mode = $this->createSut('now');
$mode->create($timesheet);
$diff = $timesheet->getBegin()->getTimestamp() - $seconds;
// amount of seconds doesn't really matter, it must only be near "now"
self::assertLessThanOrEqual(2, $diff);
}
public function testDefaultValues()
{
$sut = $this->createSut();
self::assertTrue($sut->canEditBegin());
self::assertFalse($sut->canEditEnd());
self::assertTrue($sut->canEditDuration());
self::assertTrue($sut->canUpdateTimesWithAPI());
self::assertFalse($sut->canSeeBeginAndEndTimes());
self::assertEquals('duration_only', $sut->getId());
}
}

View File

@@ -33,7 +33,6 @@ class TrackingModeServiceTest extends TestCase
self::assertContains('default', $ids);
self::assertContains('punch', $ids);
self::assertContains('duration_only', $ids);
self::assertContains('duration_fixed_begin', $ids);
}

View File

@@ -1,45 +0,0 @@
<?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\Timesheet;
use App\Entity\User;
use App\Tests\Mocks\Security\CurrentUserFactory;
use App\Timesheet\UserDateTimeFactory;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\DateTimeFactory
* @covers \App\Timesheet\UserDateTimeFactory
* @group legacy
*/
class UserDateTimeFactoryTest extends TestCase
{
public const TEST_TIMEZONE = 'Africa/Asmara';
protected function createUserDateTimeFactory(?string $timezone = null): UserDateTimeFactory
{
$userFactory = new CurrentUserFactory($this);
$currentUser = $userFactory->create(new User(), $timezone);
return new UserDateTimeFactory($currentUser);
}
public function testGetTimezone()
{
$sut = $this->createUserDateTimeFactory(self::TEST_TIMEZONE);
$this->assertEquals(self::TEST_TIMEZONE, $sut->getTimezone()->getName());
}
public function testGetTimezoneWithFallbackTimezone()
{
$sut = $this->createUserDateTimeFactory();
$this->assertEquals(date_default_timezone_get(), $sut->getTimezone()->getName());
}
}

View File

@@ -20,7 +20,7 @@ class UtilTest extends TestCase
/**
* @dataProvider getRateCalculationData
*/
public function testCalculateRate($hourlyRate, $duration, $expectedRate)
public function testCalculateRate(int|float $hourlyRate, int $duration, int|float $expectedRate)
{
$this->assertEquals($expectedRate, Util::calculateRate($hourlyRate, $duration));
}