replace PHPUnit annotations with attributes (#5608)

This commit is contained in:
Kevin Papst
2025-08-11 18:57:42 +02:00
committed by GitHub
parent 04331420ae
commit 24778d3ffb
599 changed files with 1778 additions and 2313 deletions

View File

@@ -14,16 +14,14 @@ use App\Entity\Customer;
use App\Entity\Project;
use App\Entity\Timesheet;
use App\Timesheet\Calculator\BillableCalculator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\Calculator\BillableCalculator
*/
#[CoversClass(BillableCalculator::class)]
class BillableCalculatorTest extends TestCase
{
/**
* @dataProvider getTestData
*/
#[DataProvider('getTestData')]
public function testCalculate(bool $billable, string $mode, bool $expected, ?Customer $customer, ?Project $project, ?Activity $activity): void
{
$sut = new BillableCalculator();

View File

@@ -12,12 +12,13 @@ namespace App\Tests\Timesheet\Calculator;
use App\Entity\Timesheet;
use App\Tests\Mocks\RoundingServiceFactory;
use App\Timesheet\Calculator\DurationCalculator;
use App\Timesheet\RoundingService;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\Calculator\DurationCalculator
* @covers \App\Timesheet\RoundingService
*/
#[CoversClass(DurationCalculator::class)]
#[CoversClass(RoundingService::class)]
class DurationCalculatorTest extends TestCase
{
public function testCalculateWithEmptyEnd(): void
@@ -31,9 +32,7 @@ class DurationCalculatorTest extends TestCase
self::assertEquals(0, $record->getDuration());
}
/**
* @dataProvider getTestData
*/
#[DataProvider('getTestData')]
public function testCalculate($rules, $start, $end, $expectedDuration): void
{
$record = new Timesheet();

View File

@@ -21,11 +21,11 @@ use App\Entity\UserPreference;
use App\Repository\TimesheetRepository;
use App\Timesheet\Calculator\RateCalculator;
use App\Timesheet\RateService;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\Calculator\RateCalculator
*/
#[CoversClass(RateCalculator::class)]
class RateCalculatorTest extends TestCase
{
protected function getRateRepositoryMock(array $rates = [])
@@ -102,9 +102,7 @@ class RateCalculatorTest extends TestCase
yield 'k1' => [8.82, 8.82, 1800, 17.64, null, null, null, null, null, false, null, null, false, null, null, true];
}
/**
* @dataProvider getRateTestData
*/
#[DataProvider('getRateTestData')]
public function testRates(
$expectedRate,
$expectedInternalRate,
@@ -208,9 +206,8 @@ class RateCalculatorTest extends TestCase
/**
* Uses the hourly rate from user_preferences to calculate the rate.
*
* @dataProvider getRuleDefinitions
*/
#[DataProvider('getRuleDefinitions')]
public function testCalculateWithRulesByUsersHourlyRate($duration, $rules, $expectedRate): void
{
$end = new \DateTime('12:00:00', new \DateTimeZone('UTC'));

View File

@@ -14,11 +14,10 @@ use App\Entity\Timesheet;
use App\Entity\User;
use App\Entity\UserPreference;
use App\Timesheet\Calculator\RateResetCalculator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\Calculator\RateResetCalculator
*/
#[CoversClass(RateResetCalculator::class)]
class RateResetCalculatorTest extends TestCase
{
public function testWithReset(): void

View File

@@ -12,11 +12,11 @@ namespace App\Tests\Timesheet;
use App\Timesheet\DateTimeFactory;
use DateTime;
use DateTimeZone;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\DateTimeFactory
*/
#[CoversClass(DateTimeFactory::class)]
class DateTimeFactoryTest extends TestCase
{
public const TEST_TIMEZONE = 'Europe/London';
@@ -116,9 +116,7 @@ class DateTimeFactoryTest extends TestCase
yield [self::createDateTimeFactory(self::TEST_TIMEZONE, true), 'Sunday', 22, 7];
}
/**
* @dataProvider getStartOfWeekData
*/
#[DataProvider('getStartOfWeekData')]
public function testGetStartOfWeek(DateTimeFactory $sut, string $dayName, int $dayNum, int $day): void
{
$expected = new DateTime('2018-07-26 16:47:31', new DateTimeZone(self::TEST_TIMEZONE));
@@ -153,9 +151,7 @@ class DateTimeFactoryTest extends TestCase
yield [self::createDateTimeFactory(self::TEST_TIMEZONE, true), 'Saturday', 28, 6];
}
/**
* @dataProvider getEndOfWeekData
*/
#[DataProvider('getEndOfWeekData')]
public function testGetEndOfWeek(DateTimeFactory $sut, string $dayName, int $dayNum, int $day): void
{
$expected = new DateTime('2018-07-26 16:47:31', new DateTimeZone(self::TEST_TIMEZONE));

View File

@@ -13,11 +13,11 @@ use App\Configuration\ConfigLoaderInterface;
use App\Entity\Timesheet;
use App\Tests\Mocks\SystemConfigurationFactory;
use App\Timesheet\LockdownService;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\LockdownService
*/
#[CoversClass(LockdownService::class)]
class LockdownServiceTest extends TestCase
{
protected function createService(?string $start, ?string $end, ?string $grace = null, ?string $timezone = null): LockdownService
@@ -80,9 +80,7 @@ class LockdownServiceTest extends TestCase
self::assertTrue($sut->isEditable($timesheet, new \DateTime('first day of this month'), false));
}
/**
* @dataProvider getTestData
*/
#[DataProvider('getTestData')]
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');
@@ -117,9 +115,7 @@ class LockdownServiceTest extends TestCase
yield [true, '+5 days', '+11 days', false];
}
/**
* @dataProvider getConfigTestData
*/
#[DataProvider('getConfigTestData')]
public function testLockdownConfig(bool $allowOverwriteGrace, ?string $lockdownBegin, ?string $lockdownEnd, ?string $grace, bool $isViolation): void
{
$sut = $this->createService($lockdownBegin, $lockdownEnd, $grace);

View File

@@ -20,11 +20,11 @@ use App\Entity\User;
use App\Entity\UserPreference;
use App\Repository\TimesheetRepository;
use App\Timesheet\RateService;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\RateService
*/
#[CoversClass(RateService::class)]
class RateServiceTest extends TestCase
{
protected function getRateRepositoryMock(array $rates = [])
@@ -106,9 +106,7 @@ class RateServiceTest extends TestCase
yield 'k1' => [8.82, 8.82, 1800, 17.64, null, null, null, null, null, false, null, null, false, null, null, true];
}
/**
* @dataProvider getRateTestData
*/
#[DataProvider('getRateTestData')]
public function testRates(
$expectedRate,
$expectedInternalRate,
@@ -212,9 +210,8 @@ class RateServiceTest extends TestCase
/**
* Uses the hourly rate from user_preferences to calculate the rate.
*
* @dataProvider getRuleDefinitions
*/
#[DataProvider('getRuleDefinitions')]
public function testCalculateWithRulesByUsersHourlyRate($duration, $rules, $expectedRate): void
{
$end = self::createDateTime('12:00:00');

View File

@@ -11,16 +11,14 @@ namespace App\Tests\Timesheet\Rounding;
use App\Entity\Timesheet;
use App\Timesheet\Rounding\CeilRounding;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\Rounding\CeilRounding
*/
#[CoversClass(CeilRounding::class)]
class CeilRoundingTest extends TestCase
{
/**
* @dataProvider getTestData
*/
#[DataProvider('getTestData')]
public function testCalculate($roundBegin, $roundEnd, $roundDuration, \DateTime $start, \DateTime $end, \DateTime $expectedStart, \DateTime $expectedEnd, $expectedDuration): void
{
$record = new Timesheet();

View File

@@ -11,16 +11,14 @@ namespace App\Tests\Timesheet\Rounding;
use App\Entity\Timesheet;
use App\Timesheet\Rounding\ClosestRounding;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\Rounding\ClosestRounding
*/
#[CoversClass(ClosestRounding::class)]
class ClosestRoundingTest extends TestCase
{
/**
* @dataProvider getTestData
*/
#[DataProvider('getTestData')]
public function testCalculate($roundBegin, $roundEnd, $roundDuration, \DateTime $start, \DateTime $end, \DateTime $expectedStart, \DateTime $expectedEnd, $expectedDuration): void
{
$record = new Timesheet();

View File

@@ -11,16 +11,14 @@ namespace App\Tests\Timesheet\Rounding;
use App\Entity\Timesheet;
use App\Timesheet\Rounding\DefaultRounding;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\Rounding\DefaultRounding
*/
#[CoversClass(DefaultRounding::class)]
class DefaultRoundingTest extends TestCase
{
/**
* @dataProvider getTestData
*/
#[DataProvider('getTestData')]
public function testCalculate($roundBegin, $roundEnd, $roundDuration, \DateTime $start, \DateTime $end, \DateTime $expectedStart, \DateTime $expectedEnd, $expectedDuration): void
{
$record = new Timesheet();

View File

@@ -11,16 +11,14 @@ namespace App\Tests\Timesheet\Rounding;
use App\Entity\Timesheet;
use App\Timesheet\Rounding\FloorRounding;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\Rounding\FloorRounding
*/
#[CoversClass(FloorRounding::class)]
class FloorRoundingTest extends TestCase
{
/**
* @dataProvider getTestData
*/
#[DataProvider('getTestData')]
public function testCalculate($roundBegin, $roundEnd, $roundDuration, \DateTime $start, \DateTime $end, \DateTime $expectedStart, \DateTime $expectedEnd, $expectedDuration): void
{
$record = new Timesheet();

View File

@@ -11,11 +11,12 @@ namespace App\Tests\Timesheet;
use App\Entity\Timesheet;
use App\Tests\Mocks\RoundingServiceFactory;
use App\Timesheet\RoundingService;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\RoundingService
*/
#[CoversClass(RoundingService::class)]
class RoundingServiceTest extends TestCase
{
public function testCalculateWithEmptyEnd(): void
@@ -29,9 +30,7 @@ class RoundingServiceTest extends TestCase
self::assertEquals(0, $record->getDuration());
}
/**
* @dataProvider getTestData
*/
#[DataProvider('getTestData')]
public function testCalculate($rules, $start, $end, $expectedStart, $expectedEnd, $expectedDuration): void
{
$record = new Timesheet();

View File

@@ -22,6 +22,8 @@ use App\Tests\Mocks\SystemConfigurationFactory;
use App\Timesheet\TimesheetService;
use App\Timesheet\TrackingModeService;
use App\Validator\ValidationFailedException;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
@@ -30,9 +32,7 @@ use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
* @covers \App\Timesheet\TimesheetService
*/
#[CoversClass(TimesheetService::class)]
class TimesheetServiceTest extends TestCase
{
private function getSut(
@@ -65,9 +65,7 @@ class TimesheetServiceTest extends TestCase
return $service;
}
/**
* @group legacy
*/
#[Group('legacy')]
public function testCannotSavePersistedTimesheetAsNew(): void
{
$timesheet = $this->createMock(Timesheet::class);
@@ -163,9 +161,7 @@ class TimesheetServiceTest extends TestCase
self::assertEquals('Europe/Paris', $timesheet->getTimezone());
}
/**
* @group legacy
*/
#[Group('legacy')]
public function testUpdateTimesheetFixesTimezone(): void
{
$user = new User();

View File

@@ -12,12 +12,11 @@ namespace App\Tests\Timesheet\TrackingMode;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Timesheet\TrackingMode\AbstractTrackingMode;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
/**
* @covers \App\Timesheet\TrackingMode\AbstractTrackingMode
*/
#[CoversClass(AbstractTrackingMode::class)]
abstract class AbstractTrackingModeTestCase extends TestCase
{
/**

View File

@@ -12,10 +12,9 @@ namespace App\Tests\Timesheet\TrackingMode;
use App\Entity\Timesheet;
use App\Tests\Mocks\RoundingServiceFactory;
use App\Timesheet\TrackingMode\DefaultMode;
use PHPUnit\Framework\Attributes\CoversClass;
/**
* @covers \App\Timesheet\TrackingMode\DefaultMode
*/
#[CoversClass(DefaultMode::class)]
class DefaultModeTest extends AbstractTrackingModeTestCase
{
public function assertDefaultBegin(Timesheet $timesheet): void

View File

@@ -14,13 +14,12 @@ use App\Entity\User;
use App\Tests\Configuration\TestConfigLoader;
use App\Tests\Mocks\SystemConfigurationFactory;
use App\Timesheet\TrackingMode\DurationFixedBeginMode;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
/**
* @covers \App\Timesheet\TrackingMode\DurationFixedBeginMode
*/
#[CoversClass(DurationFixedBeginMode::class)]
class DurationFixedBeginModeTest extends TestCase
{
private function createSut(string $default = '13:47', bool $allowApiTimes = false): DurationFixedBeginMode

View File

@@ -12,13 +12,12 @@ namespace App\Tests\Timesheet\TrackingMode;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Timesheet\TrackingMode\PunchInOutMode;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
/**
* @covers \App\Timesheet\TrackingMode\PunchInOutMode
*/
#[CoversClass(PunchInOutMode::class)]
class PunchInOutModeTest extends TestCase
{
private function createSut(bool $allowApiTimes = false): PunchInOutMode

View File

@@ -11,12 +11,12 @@ namespace App\Tests\Timesheet;
use App\Tests\Mocks\TrackingModeServiceFactory;
use App\Timesheet\TrackingMode\PunchInOutMode;
use App\Timesheet\TrackingModeService;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
/**
* @covers \App\Timesheet\TrackingModeService
*/
#[CoversClass(TrackingModeService::class)]
class TrackingModeServiceTest extends TestCase
{
public function testDefaultTrackingModesAreRegistered(): void

View File

@@ -10,16 +10,14 @@
namespace App\Tests\Timesheet;
use App\Timesheet\Util;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Timesheet\Util
*/
#[CoversClass(Util::class)]
class UtilTest extends TestCase
{
/**
* @dataProvider getRateCalculationData
*/
#[DataProvider('getRateCalculationData')]
public function testCalculateRate(int|float $hourlyRate, int $duration, int|float $expectedRate): void
{
self::assertEquals($expectedRate, Util::calculateRate($hourlyRate, $duration));