diff --git a/.github/workflows/linting.yaml b/.github/workflows/linting.yaml index 24ace41e..3150ebe0 100644 --- a/.github/workflows/linting.yaml +++ b/.github/workflows/linting.yaml @@ -24,5 +24,5 @@ jobs: - run: composer validate --no-check-all --strict - run: vendor/bin/php-cs-fixer fix --dry-run --verbose --config=.php_cs.dist --using-cache=no --show-progress=none --format=checkstyle | cs2pr - run: vendor/bin/phpstan analyse src -c phpstan.neon --level=5 --no-progress --error-format=checkstyle | cs2pr - - run: vendor/bin/phpstan analyse tests -c tests/phpstan.neon --level=4 --no-progress --error-format=checkstyle | cs2pr + - run: vendor/bin/phpstan analyse tests -c tests/phpstan.neon --level=5 --no-progress --error-format=checkstyle | cs2pr - run: composer kimai:code-lint diff --git a/composer.json b/composer.json index 3255254f..e8abddd2 100644 --- a/composer.json +++ b/composer.json @@ -170,7 +170,7 @@ "kimai:phpstan": "@phpstan", "phpstan": [ "vendor/bin/phpstan analyse src -c phpstan.neon --level=5", - "vendor/bin/phpstan analyse tests -c tests/phpstan.neon --level=4" + "vendor/bin/phpstan analyse tests -c tests/phpstan.neon --level=5" ], "kimai:codestyle": "@codestyle", "codestyle": "vendor/bin/php-cs-fixer fix --dry-run --verbose --show-progress=none", diff --git a/src/Export/Spreadsheet/Extractor/AnnotationExtractor.php b/src/Export/Spreadsheet/Extractor/AnnotationExtractor.php index da475338..40f593a4 100644 --- a/src/Export/Spreadsheet/Extractor/AnnotationExtractor.php +++ b/src/Export/Spreadsheet/Extractor/AnnotationExtractor.php @@ -42,8 +42,8 @@ final class AnnotationExtractor implements ExtractorInterface */ public function extract($value): array { - if (!\is_string($value)) { - throw new ExtractorException('AnnotationExtractor needs a class name (string) for work'); + if (!\is_string($value) || empty($value)) { + throw new ExtractorException('AnnotationExtractor needs a non-empty class name for work'); } try { diff --git a/src/Form/DataTransformer/SearchTermTransformer.php b/src/Form/DataTransformer/SearchTermTransformer.php index d0206151..ea9c7586 100644 --- a/src/Form/DataTransformer/SearchTermTransformer.php +++ b/src/Form/DataTransformer/SearchTermTransformer.php @@ -23,7 +23,7 @@ class SearchTermTransformer implements DataTransformerInterface */ public function transform($searchTerm) { - if (empty($searchTerm) || !$searchTerm instanceof SearchTerm) { + if (empty($searchTerm) || !($searchTerm instanceof SearchTerm)) { return ''; } @@ -33,7 +33,7 @@ class SearchTermTransformer implements DataTransformerInterface /** * Transforms a string to a SearchTerm object. * - * @param string $searchTerm + * @param string|null $searchTerm * @return SearchTerm|null * @throws TransformationFailedException if object (issue) is not found */ diff --git a/src/Form/DataTransformer/TagArrayToStringTransformer.php b/src/Form/DataTransformer/TagArrayToStringTransformer.php index 5d2a2322..d072905f 100644 --- a/src/Form/DataTransformer/TagArrayToStringTransformer.php +++ b/src/Form/DataTransformer/TagArrayToStringTransformer.php @@ -48,7 +48,7 @@ class TagArrayToStringTransformer implements DataTransformerInterface /** * Transforms a string to an array of tags. * - * @param string $stringOfTags + * @param string|null $stringOfTags * * @return Tag[] * @throws TransformationFailedException if object (issue) is not found diff --git a/src/Model/TimesheetStatistic.php b/src/Model/TimesheetStatistic.php index e9b1c75b..771687b1 100644 --- a/src/Model/TimesheetStatistic.php +++ b/src/Model/TimesheetStatistic.php @@ -25,11 +25,11 @@ class TimesheetStatistic */ protected $durationTotal = 0; /** - * @var int + * @var float */ protected $amountThisMonth = 0; /** - * @var int + * @var float */ protected $amountTotal = 0; /** @@ -54,17 +54,24 @@ class TimesheetStatistic $this->durationThisMonth = (int) $durationThisMonth; } - public function getAmountTotal(): int + /** + * This is actually the rate, wrong wording... + * + * @return float + */ + public function getAmountTotal(): float { return $this->amountTotal; } /** - * @param int $amountTotal + * This is actually the rate, wrong wording... + * + * @param float|int $amountTotal */ public function setAmountTotal($amountTotal) { - $this->amountTotal = (int) $amountTotal; + $this->amountTotal = (float) $amountTotal; } public function getDurationTotal(): int @@ -80,17 +87,24 @@ class TimesheetStatistic $this->durationTotal = (int) $durationTotal; } - public function getAmountThisMonth(): int + /** + * This is actually the rate, wrong wording... + * + * @return float + */ + public function getAmountThisMonth(): float { return $this->amountThisMonth; } /** - * @param int $amountThisMonth + * This is actually the rate, wrong wording... + * + * @param float|int $amountThisMonth */ public function setAmountThisMonth($amountThisMonth) { - $this->amountThisMonth = (int) $amountThisMonth; + $this->amountThisMonth = (float) $amountThisMonth; } public function getFirstEntry(): ?\DateTime diff --git a/src/Twig/MarkdownExtension.php b/src/Twig/MarkdownExtension.php index e2076cc7..258d7cf1 100644 --- a/src/Twig/MarkdownExtension.php +++ b/src/Twig/MarkdownExtension.php @@ -78,10 +78,10 @@ final class MarkdownExtension extends AbstractExtension /** * Transforms the timesheet description content into HTML. * - * @param string $content + * @param string|null $content * @return string */ - public function timesheetContent($content): string + public function timesheetContent(?string $content): string { if (empty($content)) { return ''; diff --git a/src/Validator/Constraints/TimesheetValidator.php b/src/Validator/Constraints/TimesheetValidator.php index 4e5e4382..b25811a9 100644 --- a/src/Validator/Constraints/TimesheetValidator.php +++ b/src/Validator/Constraints/TimesheetValidator.php @@ -19,12 +19,12 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException; final class TimesheetValidator extends ConstraintValidator { /** - * @var TimesheetConstraint[] + * @var Constraint[] */ private $constraints; /** - * @param TimesheetConstraint[] $constraints + * @param Constraint[] $constraints */ public function __construct(iterable $constraints) { diff --git a/tests/Event/SystemConfigurationEventTest.php b/tests/Event/SystemConfigurationEventTest.php index cd124288..4f5c759a 100644 --- a/tests/Event/SystemConfigurationEventTest.php +++ b/tests/Event/SystemConfigurationEventTest.php @@ -9,8 +9,8 @@ namespace App\Tests\Event; -use App\Entity\Configuration; use App\Event\SystemConfigurationEvent; +use App\Form\Model\Configuration; use App\Form\Model\SystemConfiguration; use PHPUnit\Framework\TestCase; diff --git a/tests/Export/Spreadsheet/Extractor/AnnotationExtractorTest.php b/tests/Export/Spreadsheet/Extractor/AnnotationExtractorTest.php index 0eb238d3..ea31227a 100644 --- a/tests/Export/Spreadsheet/Extractor/AnnotationExtractorTest.php +++ b/tests/Export/Spreadsheet/Extractor/AnnotationExtractorTest.php @@ -75,11 +75,22 @@ class AnnotationExtractorTest extends TestCase $sut = new AnnotationExtractor(new AnnotationReader()); $this->expectException(ExtractorException::class); - $this->expectExceptionMessage('AnnotationExtractor needs a class name (string) for work'); + $this->expectExceptionMessage('AnnotationExtractor needs a non-empty class name for work'); + /* @phpstan-ignore-next-line */ $sut->extract(new \stdClass()); } + public function testExceptionOnEmptyString() + { + $sut = new AnnotationExtractor(new AnnotationReader()); + + $this->expectException(ExtractorException::class); + $this->expectExceptionMessage('AnnotationExtractor needs a non-empty class name for work'); + + $sut->extract(''); + } + public function testExceptionOnMissingExpression() { $sut = new AnnotationExtractor(new AnnotationReader()); diff --git a/tests/Export/Spreadsheet/Extractor/MetaFieldExtractorTest.php b/tests/Export/Spreadsheet/Extractor/MetaFieldExtractorTest.php index bd40fdc3..58dd67ec 100644 --- a/tests/Export/Spreadsheet/Extractor/MetaFieldExtractorTest.php +++ b/tests/Export/Spreadsheet/Extractor/MetaFieldExtractorTest.php @@ -61,6 +61,7 @@ class MetaFieldExtractorTest extends TestCase $this->expectException(ExtractorException::class); $this->expectExceptionMessage('MetaFieldExtractor needs a MetaDisplayEventInterface instance for work'); + /* @phpstan-ignore-next-line */ $sut->extract(new \stdClass()); } } diff --git a/tests/Export/Spreadsheet/Extractor/UserPreferenceExtractorTest.php b/tests/Export/Spreadsheet/Extractor/UserPreferenceExtractorTest.php index 2dccbe20..551830b3 100644 --- a/tests/Export/Spreadsheet/Extractor/UserPreferenceExtractorTest.php +++ b/tests/Export/Spreadsheet/Extractor/UserPreferenceExtractorTest.php @@ -60,6 +60,7 @@ class UserPreferenceExtractorTest extends TestCase $this->expectException(ExtractorException::class); $this->expectExceptionMessage('UserPreferenceExtractor needs a UserPreferenceDisplayEvent instance for work'); + /* @phpstan-ignore-next-line */ $sut->extract(new \stdClass()); } } diff --git a/tests/Form/DataTransformer/SearchTermTransformerTest.php b/tests/Form/DataTransformer/SearchTermTransformerTest.php index 3cece58f..e4475273 100644 --- a/tests/Form/DataTransformer/SearchTermTransformerTest.php +++ b/tests/Form/DataTransformer/SearchTermTransformerTest.php @@ -22,8 +22,10 @@ class SearchTermTransformerTest extends TestCase { $sut = new SearchTermTransformer(); + /* @phpstan-ignore-next-line */ self::assertEquals('', $sut->transform('')); self::assertEquals('', $sut->transform(null)); + /* @phpstan-ignore-next-line */ self::assertEquals('', $sut->transform(new \stdClass())); self::assertEquals( diff --git a/tests/Form/MultiUpdate/MultiUpdateTableDTOTest.php b/tests/Form/MultiUpdate/MultiUpdateTableDTOTest.php index 05c06cc8..0ede2310 100644 --- a/tests/Form/MultiUpdate/MultiUpdateTableDTOTest.php +++ b/tests/Form/MultiUpdate/MultiUpdateTableDTOTest.php @@ -9,6 +9,11 @@ namespace App\Tests\Form\MultiUpdate; +use App\Entity\Activity; +use App\Entity\Customer; +use App\Entity\Project; +use App\Entity\Tag; +use App\Entity\Timesheet; use App\Form\MultiUpdate\MultiUpdateTableDTO; use PHPUnit\Framework\TestCase; @@ -45,7 +50,13 @@ class MultiUpdateTableDTOTest extends TestCase self::assertInstanceOf(MultiUpdateTableDTO::class, $sut->setAction('sdfsdfsdf')); self::assertEquals('sdfsdfsdf', $sut->getAction()); - self::assertInstanceOf(MultiUpdateTableDTO::class, $sut->setEntities([1, 2, 3, 4, 5, 6, 7, 8, 9, '0815'])); - self::assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, '0815'], $sut->getEntities()); + $activity = new Activity(); + $project = new Project(); + $customer = new Customer(); + $timesheet = new Timesheet(); + $tag = new Tag(); + + self::assertInstanceOf(MultiUpdateTableDTO::class, $sut->setEntities([$tag, $timesheet, $activity, $customer, $project])); + self::assertEquals([$tag, $timesheet, $activity, $customer, $project], $sut->getEntities()); } } diff --git a/tests/Form/MultiUpdate/TimesheetMultiUpdateDTOTest.php b/tests/Form/MultiUpdate/TimesheetMultiUpdateDTOTest.php index 3735e08a..422e912a 100644 --- a/tests/Form/MultiUpdate/TimesheetMultiUpdateDTOTest.php +++ b/tests/Form/MultiUpdate/TimesheetMultiUpdateDTOTest.php @@ -12,6 +12,7 @@ namespace App\Tests\Form\MultiUpdate; use App\Entity\Activity; use App\Entity\Customer; use App\Entity\Project; +use App\Entity\Timesheet; use App\Entity\User; use App\Form\MultiUpdate\TimesheetMultiUpdateDTO; use PHPUnit\Framework\TestCase; @@ -59,8 +60,10 @@ class TimesheetMultiUpdateDTOTest extends TestCase self::assertInstanceOf(TimesheetMultiUpdateDTO::class, $sut->setAction('sdfsdfsdf')); self::assertEquals('sdfsdfsdf', $sut->getAction()); - self::assertInstanceOf(TimesheetMultiUpdateDTO::class, $sut->setEntities([1, 2, 3, 4, 5, 6, 7, 8, 9, '0815'])); - self::assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9, '0815'], $sut->getEntities()); + $entities = [new Timesheet(), new Timesheet(), new Timesheet(), new Timesheet()]; + + self::assertInstanceOf(TimesheetMultiUpdateDTO::class, $sut->setEntities($entities)); + self::assertEquals($entities, $sut->getEntities()); self::assertInstanceOf(TimesheetMultiUpdateDTO::class, $sut->setExported(true)); self::assertTrue($sut->isExported()); diff --git a/tests/Mocks/Saml/SamlAuthFactory.php b/tests/Mocks/Saml/SamlAuthFactory.php index a1a7bbd5..becad3db 100644 --- a/tests/Mocks/Saml/SamlAuthFactory.php +++ b/tests/Mocks/Saml/SamlAuthFactory.php @@ -76,8 +76,10 @@ class SamlAuthFactory extends AbstractMockFactory ]; } - $request = $this->getMockBuilder(Request::class)->getMock(); - $request->method('isFromTrustedProxy')->willReturn($fromTrustedProxy); + $mock = $this->getMockBuilder(Request::class)->getMock(); + $mock->method('isFromTrustedProxy')->willReturn($fromTrustedProxy); + /** @var Request $request */ + $request = $mock; $requestStack = new RequestStack(); $requestStack->push($request); diff --git a/tests/Mocks/Security/CurrentUserFactory.php b/tests/Mocks/Security/CurrentUserFactory.php index dec8daf2..f4917974 100644 --- a/tests/Mocks/Security/CurrentUserFactory.php +++ b/tests/Mocks/Security/CurrentUserFactory.php @@ -34,10 +34,16 @@ class CurrentUserFactory extends AbstractMockFactory $user->addPreference($pref); } - $repository = $this->getMockBuilder(UserRepository::class)->onlyMethods(['getUserById'])->disableOriginalConstructor()->getMock(); - $repository->expects(TestCase::atMost(1))->method('getUserById')->willReturn($user); - $token = $this->getMockBuilder(UsernamePasswordToken::class)->onlyMethods(['getUser'])->disableOriginalConstructor()->getMock(); - $token->method('getUser')->willReturn($user); + $mock = $this->getMockBuilder(UserRepository::class)->onlyMethods(['getUserById'])->disableOriginalConstructor()->getMock(); + $mock->expects(TestCase::atMost(1))->method('getUserById')->willReturn($user); + /** @var UserRepository $repository */ + $repository = $mock; + + $mock = $this->getMockBuilder(UsernamePasswordToken::class)->onlyMethods(['getUser'])->disableOriginalConstructor()->getMock(); + $mock->method('getUser')->willReturn($user); + /** @var UsernamePasswordToken $token */ + $token = $mock; + $tokenStorage = new TokenStorage(); $tokenStorage->setToken($token); diff --git a/tests/Mocks/Security/RoleServiceFactory.php b/tests/Mocks/Security/RoleServiceFactory.php index 25e3a84e..3d3b63a8 100644 --- a/tests/Mocks/Security/RoleServiceFactory.php +++ b/tests/Mocks/Security/RoleServiceFactory.php @@ -18,7 +18,7 @@ use App\Tests\Mocks\AbstractMockFactory; class RoleServiceFactory extends AbstractMockFactory { /** - * @param string[]|null $roles + * @param array>|null $roles * @param Role[]|null $repositoryRoles * @return RoleService */ @@ -33,10 +33,12 @@ class RoleServiceFactory extends AbstractMockFactory ]; } - $repository = $this->getMockBuilder(RoleRepository::class)->onlyMethods(['findAll'])->disableOriginalConstructor()->getMock(); - $repository->method('findAll')->willReturn($repositoryRoles); + $mock = $this->getMockBuilder(RoleRepository::class)->onlyMethods(['findAll'])->disableOriginalConstructor()->getMock(); + $mock->method('findAll')->willReturn($repositoryRoles); + + /** @var RoleRepository $repository */ + $repository = $mock; - /* @var RoleRepository $repository */ return new RoleService($repository, $roles); } } diff --git a/tests/Model/ActivityStatisticTest.php b/tests/Model/ActivityStatisticTest.php index 44c92c6e..ecc015f2 100644 --- a/tests/Model/ActivityStatisticTest.php +++ b/tests/Model/ActivityStatisticTest.php @@ -27,8 +27,8 @@ class ActivityStatisticTest extends TestCase public function testSetter() { $sut = new ActivityStatistic(); - $sut->setRecordAmount(7654.298); - $sut->setRecordDuration(826.10); + $sut->setRecordAmount(7654); + $sut->setRecordDuration(826); $this->assertEquals(7654, $sut->getRecordAmount()); $this->assertEquals(826, $sut->getRecordDuration()); diff --git a/tests/Model/CustomerStatisticTest.php b/tests/Model/CustomerStatisticTest.php index d55ee95b..543e3a60 100644 --- a/tests/Model/CustomerStatisticTest.php +++ b/tests/Model/CustomerStatisticTest.php @@ -29,8 +29,8 @@ class CustomerStatisticTest extends TestCase public function testSetter() { $sut = new CustomerStatistic(); - $sut->setRecordAmount(7654.298); - $sut->setRecordDuration(826.10); + $sut->setRecordAmount(7654); + $sut->setRecordDuration(826); $sut->setActivityAmount(13); $sut->setProjectAmount(2); diff --git a/tests/Model/ProjectStatisticTest.php b/tests/Model/ProjectStatisticTest.php index 204ff56e..25a76825 100644 --- a/tests/Model/ProjectStatisticTest.php +++ b/tests/Model/ProjectStatisticTest.php @@ -30,8 +30,8 @@ class ProjectStatisticTest extends TestCase { $project = new Project(); $sut = new ProjectStatistic($project); - $sut->setRecordAmount(7654.298); - $sut->setRecordDuration(826.10); + $sut->setRecordAmount(7654); + $sut->setRecordDuration(826); $sut->setActivityAmount(13); self::assertEquals(13, $sut->getActivityAmount()); diff --git a/tests/Model/Statistic/DayTest.php b/tests/Model/Statistic/DayTest.php index 4f13fe90..788d8667 100644 --- a/tests/Model/Statistic/DayTest.php +++ b/tests/Model/Statistic/DayTest.php @@ -34,7 +34,7 @@ class DayTest extends TestCase $date = new DateTime('-8 hours'); $sut = new Day($date, 12340, 197.25956); - $sut->setTotalDuration(999.27); + $sut->setTotalDuration(999); $sut->setTotalRate(0.123456789); $this->assertEquals(999, $sut->getTotalDuration()); diff --git a/tests/Model/Statistic/MonthTest.php b/tests/Model/Statistic/MonthTest.php index faeab837..013c6721 100644 --- a/tests/Model/Statistic/MonthTest.php +++ b/tests/Model/Statistic/MonthTest.php @@ -58,7 +58,7 @@ class MonthTest extends TestCase public function testSetter() { $sut = new Month('01'); - $sut->setTotalDuration(999.27); + $sut->setTotalDuration(999); $sut->setTotalRate(0.123456789); $this->assertEquals(999, $sut->getTotalDuration()); diff --git a/tests/Model/Statistic/YearTest.php b/tests/Model/Statistic/YearTest.php index e25405df..80bd77d5 100644 --- a/tests/Model/Statistic/YearTest.php +++ b/tests/Model/Statistic/YearTest.php @@ -21,7 +21,7 @@ class YearTest extends TestCase public function testDefaultValues() { $sut = new Year('1999'); - $this->assertNull($sut->getMonth('01')); + $this->assertNull($sut->getMonth(1)); $this->assertEmpty($sut->getMonths()); $this->assertIsArray($sut->getMonths()); $this->assertEquals('1999', $sut->getYear()); diff --git a/tests/Model/TimesheetStatisticTest.php b/tests/Model/TimesheetStatisticTest.php index 5e77308e..34b0b86b 100644 --- a/tests/Model/TimesheetStatisticTest.php +++ b/tests/Model/TimesheetStatisticTest.php @@ -41,8 +41,8 @@ class TimesheetStatisticTest extends TestCase $sut->setFirstEntry($date); $this->assertEquals(2, $sut->getRecordsTotal()); - $this->assertEquals(7654, $sut->getAmountTotal()); - $this->assertEquals(826, $sut->getAmountThisMonth()); + $this->assertEquals(7654.298, $sut->getAmountTotal()); + $this->assertEquals(826.10, $sut->getAmountThisMonth()); $this->assertEquals(13, $sut->getDurationTotal()); $this->assertEquals(200, $sut->getDurationThisMonth()); $this->assertSame($date, $sut->getFirstEntry()); diff --git a/tests/Repository/Query/TimesheetQueryTest.php b/tests/Repository/Query/TimesheetQueryTest.php index 9b4656e9..963b850c 100644 --- a/tests/Repository/Query/TimesheetQueryTest.php +++ b/tests/Repository/Query/TimesheetQueryTest.php @@ -128,7 +128,7 @@ class TimesheetQueryTest extends BaseQueryTest $sut->setExported(TimesheetQuery::STATE_ALL); self::assertEquals(TimesheetQuery::STATE_ALL, $sut->getExported()); - $sut->setExported('02'); + $sut->setExported(2); self::assertEquals(TimesheetQuery::STATE_ALL, $sut->getExported()); } diff --git a/tests/Repository/Query/VisibilityQueryTest.php b/tests/Repository/Query/VisibilityQueryTest.php index 9b6133a8..3679aff0 100644 --- a/tests/Repository/Query/VisibilityQueryTest.php +++ b/tests/Repository/Query/VisibilityQueryTest.php @@ -29,15 +29,18 @@ class VisibilityQueryTest extends TestCase self::assertFalse($sut->isShowHidden()); self::assertFalse($sut->isShowBoth()); + /* @phpstan-ignore-next-line */ $sut->setVisibility('foo-bar'); $this->assertEquals(VisibilityQuery::SHOW_VISIBLE, $sut->getVisibility()); - $sut->setVisibility('2'); + /* @phpstan-ignore-next-line */ + $sut->setVisibility('2'); // cast to integer $this->assertEquals(VisibilityQuery::SHOW_HIDDEN, $sut->getVisibility()); self::assertFalse($sut->isShowVisible()); self::assertTrue($sut->isShowHidden()); self::assertFalse($sut->isShowBoth()); + /* @phpstan-ignore-next-line */ $sut->setVisibility('0'); // keep the value that was previously set $this->assertEquals(VisibilityQuery::SHOW_HIDDEN, $sut->getVisibility()); @@ -63,15 +66,18 @@ class VisibilityQueryTest extends TestCase self::assertFalse($sut->isShowHidden()); self::assertFalse($sut->isShowBoth()); + /* @phpstan-ignore-next-line */ $sut->setVisibility('foo-bar'); $this->assertEquals(VisibilityInterface::SHOW_VISIBLE, $sut->getVisibility()); + /* @phpstan-ignore-next-line */ $sut->setVisibility('2'); $this->assertEquals(VisibilityInterface::SHOW_HIDDEN, $sut->getVisibility()); self::assertFalse($sut->isShowVisible()); self::assertTrue($sut->isShowHidden()); self::assertFalse($sut->isShowBoth()); + /* @phpstan-ignore-next-line */ $sut->setVisibility('0'); // keep the value that was previously set $this->assertEquals(VisibilityInterface::SHOW_HIDDEN, $sut->getVisibility()); diff --git a/tests/Security/RoleServiceTest.php b/tests/Security/RoleServiceTest.php index fa2f4d5c..e9b20ac3 100644 --- a/tests/Security/RoleServiceTest.php +++ b/tests/Security/RoleServiceTest.php @@ -21,9 +21,9 @@ class RoleServiceTest extends TestCase public function testWithEmptyRepository() { $real = [ - 'ROLE_TEAMLEAD' => [0 => 'ROLE_USER'], - 'ROLE_ADMIN' => [0 => 'ROLE_TEAMLEAD'], - 'ROLE_SUPER_ADMIN' => [0 => 'ROLE_ADMIN'] + 'ROLE_TEAMLEAD' => ['ROLE_USER'], + 'ROLE_ADMIN' => ['ROLE_TEAMLEAD'], + 'ROLE_SUPER_ADMIN' => ['ROLE_ADMIN'] ]; $sut = (new RoleServiceFactory($this))->create($real); diff --git a/tests/Twig/DateExtensionsTest.php b/tests/Twig/DateExtensionsTest.php index a2fb2a32..36ea9635 100644 --- a/tests/Twig/DateExtensionsTest.php +++ b/tests/Twig/DateExtensionsTest.php @@ -171,6 +171,9 @@ class DateExtensionsTest extends TestCase $sut = $this->getSut('en', []); $this->assertEquals('2010-01-07T17:43:21+01:00', $sut->dateFormat($date, 'c')); $this->assertStringStartsWith('2010-01-07T17:43:21', $sut->dateFormat('7 January 2010 17:43:21', 'c')); + + // next test checks the fallback for errors while converting the date + /* @phpstan-ignore-next-line */ $this->assertEquals(2010.0107, $sut->dateFormat(2010.0107, 'c')); } @@ -209,6 +212,9 @@ class DateExtensionsTest extends TestCase $this->assertEquals('2019-08-17 12:29:47', $sut->dateTimeFull($dateTime)); $this->assertEquals('2019-08-17 12:29:47', $sut->dateTimeFull('2019-08-17 12:29:47')); + + // next test checks the fallback for errors while converting the date + /* @phpstan-ignore-next-line */ $this->assertEquals(189.45, $sut->dateTimeFull(189.45)); } } diff --git a/tests/Twig/ExtensionsTest.php b/tests/Twig/ExtensionsTest.php index bbe8fe51..59c40f79 100644 --- a/tests/Twig/ExtensionsTest.php +++ b/tests/Twig/ExtensionsTest.php @@ -77,7 +77,9 @@ class ExtensionsTest extends TestCase $sut = $this->getSut(); $this->assertEquals('DateTime', $sut->getClassName(new \DateTime())); $this->assertEquals('stdClass', $sut->getClassName(new \stdClass())); + /* @phpstan-ignore-next-line */ $this->assertNull($sut->getClassName('')); + /* @phpstan-ignore-next-line */ $this->assertNull($sut->getClassName(null)); $this->assertEquals('App\Entity\User', $sut->getClassName(new User())); } diff --git a/tests/Twig/LocaleExtensionsTest.php b/tests/Twig/LocaleExtensionsTest.php index 37d67fcf..6b0d94b5 100644 --- a/tests/Twig/LocaleExtensionsTest.php +++ b/tests/Twig/LocaleExtensionsTest.php @@ -268,11 +268,11 @@ class LocaleExtensionsTest extends TestCase // test negative duration $sut = $this->getSut($this->localeEn, 'en'); - $this->assertEquals('?', $sut->duration('-1')); + $this->assertEquals('?', $sut->duration(-1)); // test zero duration $sut = $this->getSut($this->localeEn, 'en'); - $this->assertEquals('00:00 h', $sut->duration('0')); + $this->assertEquals('00:00 h', $sut->duration(0)); $sut = $this->getSut($this->localeEn, 'en'); @@ -296,11 +296,11 @@ class LocaleExtensionsTest extends TestCase // test negative duration $sut = $this->getSut($this->localeEn, 'en'); - $this->assertEquals('0', $sut->durationDecimal('-1')); + $this->assertEquals('0', $sut->durationDecimal(-1)); // test zero duration $sut = $this->getSut($this->localeEn, 'en'); - $this->assertEquals('0', $sut->durationDecimal('0')); + $this->assertEquals('0', $sut->durationDecimal(0)); $sut = $this->getSut($this->localeEn, 'en'); diff --git a/tests/Twig/WidgetExtensionTest.php b/tests/Twig/WidgetExtensionTest.php index 3e20872f..6051c7f7 100644 --- a/tests/Twig/WidgetExtensionTest.php +++ b/tests/Twig/WidgetExtensionTest.php @@ -58,6 +58,7 @@ class WidgetExtensionTest extends TestCase $this->expectExceptionMessage('Widget must either implement WidgetInterface or be a string'); $sut = $this->getSut(); + /* @phpstan-ignore-next-line */ $sut->renderWidget(true); } diff --git a/tests/Utils/LocaleHelperTest.php b/tests/Utils/LocaleHelperTest.php index b7232541..bf0b1f0c 100644 --- a/tests/Utils/LocaleHelperTest.php +++ b/tests/Utils/LocaleHelperTest.php @@ -201,11 +201,11 @@ class LocaleHelperTest extends TestCase // test negative duration $sut = $this->getSut('en'); - $this->assertEquals('0', $sut->durationDecimal('-1')); + $this->assertEquals('0', $sut->durationDecimal(-1)); // test zero duration $sut = $this->getSut('en'); - $this->assertEquals('0', $sut->durationDecimal('0')); + $this->assertEquals('0', $sut->durationDecimal(0)); } protected function getTimesheet($seconds) diff --git a/tests/Validator/Constraints/TimesheetValidatorTest.php b/tests/Validator/Constraints/TimesheetValidatorTest.php index 98dc4d87..52f5adeb 100644 --- a/tests/Validator/Constraints/TimesheetValidatorTest.php +++ b/tests/Validator/Constraints/TimesheetValidatorTest.php @@ -9,21 +9,13 @@ namespace App\Tests\Validator\Constraints; -use App\Configuration\ConfigLoaderInterface; -use App\Configuration\TimesheetConfiguration; use App\Entity\Activity; use App\Entity\Customer; use App\Entity\Project; use App\Entity\Timesheet; -use App\Repository\TimesheetRepository; -use App\Tests\Mocks\TrackingModeServiceFactory; use App\Validator\Constraints\Timesheet as TimesheetConstraint; -use App\Validator\Constraints\TimesheetFutureTimesValidator; -use App\Validator\Constraints\TimesheetLockdownValidator; -use App\Validator\Constraints\TimesheetOverlappingValidator; -use App\Validator\Constraints\TimesheetRestartValidator; +use App\Validator\Constraints\TimesheetFutureTimes; use App\Validator\Constraints\TimesheetValidator; -use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; @@ -41,32 +33,7 @@ class TimesheetValidatorTest extends ConstraintValidatorTestCase protected function createMyValidator(bool $isGranted = true) { - $auth = $this->createMock(AuthorizationCheckerInterface::class); - $auth->method('isGranted')->willReturn($isGranted); - - $loader = $this->createMock(ConfigLoaderInterface::class); - $config = new TimesheetConfiguration($loader, [ - 'rules' => [ - 'allow_future_times' => false, - 'allow_overlapping_records' => true, - ], - 'rounding' => [ - 'default' => [ - 'begin' => 1 - ] - ] - ]); - $service = (new TrackingModeServiceFactory($this))->create('default'); - $repository = $this->createMock(TimesheetRepository::class); - - $constraints = [ - new TimesheetFutureTimesValidator($config), - new TimesheetLockdownValidator($auth, $config), - new TimesheetOverlappingValidator($config, $repository), - new TimesheetRestartValidator($service, $auth), - ]; - - return new TimesheetValidator($constraints); + return new TimesheetValidator([]); } public function testConstraintIsInvalid() diff --git a/tests/Voter/TimesheetVoterTest.php b/tests/Voter/TimesheetVoterTest.php index ad047d78..2cff09e5 100644 --- a/tests/Voter/TimesheetVoterTest.php +++ b/tests/Voter/TimesheetVoterTest.php @@ -41,7 +41,7 @@ class TimesheetVoterTest extends AbstractVoterTest public function getTestData() { - $user0 = $this->getUser(0, null); + $user0 = $this->getUser(0, 'unknown'); $user1 = $this->getUser(1, User::ROLE_USER); $user2 = $this->getUser(2, User::ROLE_TEAMLEAD); $user3 = $this->getUser(3, User::ROLE_ADMIN);