diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..2c1bae6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +Tests export-ignore +.github export-ignore + +.gitattributes export-ignore +.gitignore export-ignore + +.php-cs-fixer.dist.php export-ignore +phpstan.neon export-ignore +phpunit.xml.dist export-ignore + +shell.nix export-ignore diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e6e7aff..04665e5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,11 +20,9 @@ jobs: strategy: matrix: php-version: - - 7.3 - - 7.4 - - 8.0 - 8.1 - 8.2 + - 8.3 steps: - name: Checkout uses: actions/checkout@v3 @@ -78,13 +76,42 @@ jobs: with: coverage: none tools: composer:v2 - php-version: "8.2" + php-version: "8.3" - name: Install dependencies run: composer install --prefer-dist --no-progress --no-suggest - name: Coding Guideline - run: ./vendor/bin/ecs + run: ./vendor/bin/php-cs-fixer fix --dry-run + + phpstan: + runs-on: ubuntu-latest + needs: + - xml-linting + strategy: + matrix: + include: + - php-version: '8.1' + typo3-version: '^12.4' + - php-version: '8.2' + typo3-version: '^12.4' + - php-version: '8.3' + typo3-version: '^12.4' + steps: + - uses: actions/checkout@v3 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + coverage: none + tools: composer:v2 + php-version: "${{ matrix.php-version }}" + + - name: Install dependencies + run: composer req "typo3/cms-core:${{ matrix.typo3-version }}" --prefer-dist --no-progress --no-interaction + + - name: PHPStan + run: ./vendor/bin/phpstan tests: runs-on: ubuntu-latest @@ -93,16 +120,12 @@ jobs: strategy: matrix: include: - - php-version: '7.3' - typo3-version: '^10.4' - - php-version: '7.4' - typo3-version: '^10.4' - - php-version: '7.4' - typo3-version: '^11.5' - php-version: '8.1' - typo3-version: '^11.5' + typo3-version: '^12.4' - php-version: '8.2' - typo3-version: '^11.5' + typo3-version: '^12.4' + - php-version: '8.3' + typo3-version: '^12.4' steps: - uses: actions/checkout@v3 @@ -114,7 +137,7 @@ jobs: php-version: "${{ matrix.php-version }}" - name: Install dependencies - run: composer install --prefer-dist --no-progress --no-suggest + run: composer req "typo3/cms-core:${{ matrix.typo3-version }}" --prefer-dist --no-progress --no-interaction - name: PHPUnit Tests run: ./vendor/bin/phpunit --testdox diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..86849bd --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,63 @@ +ignoreVCSIgnored(true) + ->in(realpath(__DIR__)); + +return (new \PhpCsFixer\Config()) + ->setRiskyAllowed(true) + ->setRules([ + '@DoctrineAnnotation' => true, + '@PSR2' => true, + 'array_syntax' => ['syntax' => 'short'], + 'blank_line_after_opening_tag' => true, + 'braces' => ['allow_single_line_closure' => true], + 'cast_spaces' => ['space' => 'none'], + 'compact_nullable_typehint' => true, + 'concat_space' => ['spacing' => 'one'], + 'declare_equal_normalize' => ['space' => 'none'], + 'dir_constant' => true, + 'function_to_constant' => ['functions' => ['get_called_class', 'get_class', 'get_class_this', 'php_sapi_name', 'phpversion', 'pi']], + 'function_typehint_space' => true, + 'lowercase_cast' => true, + 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], + 'modernize_strpos' => true, + 'modernize_types_casting' => true, + 'native_function_casing' => true, + 'new_with_braces' => true, + 'no_alias_functions' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_blank_lines' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_null_property_initialization' => true, + 'no_short_bool_cast' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_superfluous_elseif' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_unneeded_control_parentheses' => true, + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_whitespace_in_blank_line' => true, + 'ordered_imports' => true, + 'php_unit_construct' => ['assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']], + 'php_unit_mock_short_will_return' => true, + 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'], + 'phpdoc_no_access' => true, + 'phpdoc_no_empty_return' => true, + 'phpdoc_no_package' => true, + 'phpdoc_scalar' => true, + 'phpdoc_trim' => true, + 'phpdoc_types' => true, + 'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], + 'return_type_declaration' => ['space_before' => 'none'], + 'single_quote' => true, + 'single_line_comment_style' => ['comment_types' => ['hash']], + 'single_trait_insert_per_statement' => true, + 'trailing_comma_in_multiline' => ['elements' => ['arrays']], + 'whitespace_after_comma_in_array' => true, + 'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false], + ]) + ->setFinder($finder); diff --git a/Classes/Controller/Frontend/CalendarController.php b/Classes/Controller/Frontend/CalendarController.php index 1be5855..21f349c 100644 --- a/Classes/Controller/Frontend/CalendarController.php +++ b/Classes/Controller/Frontend/CalendarController.php @@ -21,11 +21,14 @@ * 02110-1301, USA. */ +use Psr\Http\Message\ResponseInterface; +use RuntimeException; use TYPO3\CMS\Core\TypoScript\TypoScriptService; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Annotation as Extbase; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter; +use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use WerkraumMedia\Calendar\Domain\Model\Context; use WerkraumMedia\Calendar\Domain\Model\ContextSpecificFactory; use WerkraumMedia\Calendar\Domain\Model\Day; @@ -35,7 +38,7 @@ use WerkraumMedia\Calendar\Domain\Model\Year; use WerkraumMedia\Calendar\Events\AssignTemplateVariables; -class CalendarController extends ActionController +final class CalendarController extends ActionController { /** * @var ForeignDataFactory @@ -55,19 +58,19 @@ public function __construct( $this->typoScriptService = $typoScriptService; } - public function initializeAction() + public function initializeAction(): void { if ($this->foreignDataFactory instanceof ContextSpecificFactory) { $this->foreignDataFactory->setContext( - Context::createFromContentObjectRenderer($this->configurationManager->getContentObject()) + Context::createFromContentObjectRenderer($this->getContentObjectRenderer()) ); } } - public function initializeYearAction() + public function initializeYearAction(): void { if ($this->request->hasArgument('year') === false) { - $this->request->setArguments([ + $this->request = $this->request->withArguments([ 'year' => [ 'year' => $this->getDefaultArgumentValue('year'), ], @@ -82,17 +85,19 @@ public function initializeYearAction() /** * @Extbase\IgnoreValidation("year") */ - public function yearAction(Year $year) + public function yearAction(Year $year): ResponseInterface { $this->assignVariables([ 'year' => $year, ]); + + return $this->htmlResponse(); } - public function initializeMonthAction() + public function initializeMonthAction(): void { if ($this->request->hasArgument('month') === false) { - $this->request->setArguments([ + $this->request = $this->request->withArguments([ 'month' => [ 'month' => $this->getDefaultArgumentValue('month'), 'year' => $this->getDefaultArgumentValue('year'), @@ -108,17 +113,19 @@ public function initializeMonthAction() /** * @Extbase\IgnoreValidation("month") */ - public function monthAction(Month $month) + public function monthAction(Month $month): ResponseInterface { $this->assignVariables([ 'month' => $month, ]); + + return $this->htmlResponse(); } - public function initializeWeekAction() + public function initializeWeekAction(): void { if ($this->request->hasArgument('week') === false) { - $this->request->setArguments([ + $this->request = $this->request->withArguments([ 'week' => [ 'week' => $this->getDefaultArgumentValue('week'), 'year' => $this->getDefaultArgumentValue('year'), @@ -134,17 +141,19 @@ public function initializeWeekAction() /** * @Extbase\IgnoreValidation("week") */ - public function weekAction(Week $week) + public function weekAction(Week $week): ResponseInterface { $this->assignVariables([ 'week' => $week, ]); + + return $this->htmlResponse(); } - public function initializeDayAction() + public function initializeDayAction(): void { if ($this->request->hasArgument('day') === false) { - $this->request->setArguments([ + $this->request = $this->request->withArguments([ 'day' => [ 'day' => $this->getDefaultArgumentValue('day'), ], @@ -167,11 +176,13 @@ public function initializeDayAction() /** * @Extbase\IgnoreValidation("day") */ - public function dayAction(Day $day) + public function dayAction(Day $day): ResponseInterface { $this->assignVariables([ 'day' => $day, ]); + + return $this->htmlResponse(); } private function assignVariables(array $variables): void @@ -202,12 +213,23 @@ private function getDefaultArgumentValue(string $argumentName): string 'day' => date('Y-m-d'), ]; - $value = $this->configurationManager->getContentObject()->stdWrapValue( + $value = $this->getContentObjectRenderer()->stdWrapValue( $argumentName, $arguments, $fallbackValues[$argumentName] ); - return $value; + return (string)$value; + } + + private function getContentObjectRenderer(): ContentObjectRenderer + { + $contentObjectRenderer = $this->request->getAttribute('currentContentObject'); + + if (! $contentObjectRenderer instanceof ContentObjectRenderer) { + throw new RuntimeException('Could not fetch currentContentObject from request.', 1726490796); + } + + return $contentObjectRenderer; } } diff --git a/Classes/Domain/Model/Day.php b/Classes/Domain/Model/Day.php index 43991cd..6a84679 100644 --- a/Classes/Domain/Model/Day.php +++ b/Classes/Domain/Model/Day.php @@ -22,7 +22,6 @@ */ use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Persistence\ObjectStorage; class Day { @@ -44,7 +43,6 @@ class Day public function __construct( \DateTime $day ) { - $this->periods = new ObjectStorage(); $this->day = \DateTimeImmutable::createFromMutable($day)->modify('midnight'); } @@ -58,7 +56,7 @@ public function isActive(): bool return false; } - public function getForeignData() + public function getForeignData(): mixed { $this->initializeForeignData(); diff --git a/Classes/Domain/Model/ForeignDataFactory.php b/Classes/Domain/Model/ForeignDataFactory.php index f47b4c4..cc8a5d3 100644 --- a/Classes/Domain/Model/ForeignDataFactory.php +++ b/Classes/Domain/Model/ForeignDataFactory.php @@ -27,5 +27,5 @@ interface ForeignDataFactory * Receives a specific day and may return arbirtrary data. * This data is attached to the day and available through getter. */ - public function getData(Day $day); + public function getData(Day $day): mixed; } diff --git a/Classes/Domain/Model/Month.php b/Classes/Domain/Model/Month.php index 04a6143..bbf9bfb 100644 --- a/Classes/Domain/Model/Month.php +++ b/Classes/Domain/Model/Month.php @@ -21,9 +21,6 @@ * 02110-1301, USA. */ -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Persistence\ObjectStorage; - class Month { /** @@ -77,8 +74,8 @@ public function getWeeks(): array while ($currentDay <= $lastDay) { $this->weeks[] = new Week( - (int) $currentDay->format('W'), - (int) $currentDay->format('o') + (int)$currentDay->format('W'), + (int)$currentDay->format('o') ); $currentDay = $currentDay->modify('+7 days'); diff --git a/Classes/Domain/Model/NullDataFactory.php b/Classes/Domain/Model/NullDataFactory.php index 0b55153..713bb98 100644 --- a/Classes/Domain/Model/NullDataFactory.php +++ b/Classes/Domain/Model/NullDataFactory.php @@ -23,7 +23,7 @@ class NullDataFactory implements ForeignDataFactory { - public function getData(Day $day) + public function getData(Day $day): mixed { return null; } diff --git a/Classes/Domain/Model/Week.php b/Classes/Domain/Model/Week.php index 81e1c65..14fb692 100644 --- a/Classes/Domain/Model/Week.php +++ b/Classes/Domain/Model/Week.php @@ -79,8 +79,8 @@ public function getPreviousWeek(): Week $newDay = $this->getWeek()->modify('-1 week'); return new self( - (int) $newDay->format('W'), - (int) $newDay->format('o') + (int)$newDay->format('W'), + (int)$newDay->format('o') ); } @@ -89,8 +89,8 @@ public function getNextWeek(): Week $newDay = $this->getWeek()->modify('+1 week'); return new self( - (int) $newDay->format('W'), - (int) $newDay->format('o') + (int)$newDay->format('W'), + (int)$newDay->format('o') ); } diff --git a/Classes/Domain/Model/Year.php b/Classes/Domain/Model/Year.php index 88f005f..dda2281 100644 --- a/Classes/Domain/Model/Year.php +++ b/Classes/Domain/Model/Year.php @@ -21,9 +21,6 @@ * 02110-1301, USA. */ -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Persistence\ObjectStorage; - class Year { /** @@ -64,7 +61,7 @@ public function getMonths(): array while ($currentMonth <= $lastMonth) { $this->months[] = new Month( - (int) $currentMonth->format('n'), + (int)$currentMonth->format('n'), $this->year ); diff --git a/Documentation/Changelog/2.0.0.rst b/Documentation/Changelog/2.0.0.rst new file mode 100644 index 0000000..d4ee2c9 --- /dev/null +++ b/Documentation/Changelog/2.0.0.rst @@ -0,0 +1,36 @@ +2.0.0 +===== + +Breaking +-------- + +* Drop support for TYPO3 v10.4 LTS and PHP 7.3, 7.4, 8.0. + +Features +-------- + +* Add compatibility for TYPO3 v12.4.0 and PHP 8.3. + +Fixes +----- + +Nothing + +Tasks +----- + +* Switch CGL from ecs to php-cs-fixer. + + As that's the tool we use everywhere else. + Use the same config as well. + +* Add PHPStan + + As we always add that tool. + It helps us to find bugs and keep code clean. + +Deprecation +----------- + +Nothing + diff --git a/Tests/Fixtures/BasicDatabase.php b/Tests/Fixtures/BasicDatabase.php new file mode 100644 index 0000000..fee9931 --- /dev/null +++ b/Tests/Fixtures/BasicDatabase.php @@ -0,0 +1,29 @@ + [ + 0 => [ + 'uid' => 1, + 'pid' => 0, + 'doktype' => 1, + 'is_siteroot' => 1, + 'slug' => '/', + 'title' => 'Page Title', + ], + ], + 'sys_template' => [ + 0 => [ + 'uid' => 1, + 'pid' => 1, + 'root' => 1, + 'clear' => 3, + 'constants' => 'databasePlatform = mysql', + 'config' => ' + + + ', + ], + ], +]; diff --git a/Tests/Fixtures/BasicDatabase.xml b/Tests/Fixtures/BasicDatabase.xml deleted file mode 100644 index e62ccec..0000000 --- a/Tests/Fixtures/BasicDatabase.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - 1 - 0 - 1 - 1 - / - Page Title - - - 1 - 1 - 1 - 3 - databasePlatform = mysql - - - ]]> - - diff --git a/Tests/Fixtures/calendar_example/Classes/Domain/ExampleDataFactory.php b/Tests/Fixtures/calendar_example/Classes/Domain/ExampleDataFactory.php index 0ec0fc9..e7e4c1a 100644 --- a/Tests/Fixtures/calendar_example/Classes/Domain/ExampleDataFactory.php +++ b/Tests/Fixtures/calendar_example/Classes/Domain/ExampleDataFactory.php @@ -40,7 +40,7 @@ public function setContext(Context $context): void $this->context = $context; } - public function getData(Day $day) + public function getData(Day $day): mixed { return [ 'exampleKey' => 'exampleValue', diff --git a/Tests/Fixtures/calendar_example/Configuration/TypoScript/Setup.typoscript b/Tests/Fixtures/calendar_example/Configuration/TypoScript/Setup.typoscript index 9031a3e..c0613c8 100644 --- a/Tests/Fixtures/calendar_example/Configuration/TypoScript/Setup.typoscript +++ b/Tests/Fixtures/calendar_example/Configuration/TypoScript/Setup.typoscript @@ -11,7 +11,7 @@ page { 10 =< tt_content.calendar_example.20 } -[request.getQueryParams()['typoScriptDefaults'] == 1] +[traverse(request.getQueryParams(), 'typoScriptDefaults') == 1] plugin.tx_calendar_example { settings { arguments { diff --git a/Tests/ForcePropertyTrait.php b/Tests/ForcePropertyTrait.php index 1af013f..543b5c9 100644 --- a/Tests/ForcePropertyTrait.php +++ b/Tests/ForcePropertyTrait.php @@ -23,7 +23,7 @@ trait ForcePropertyTrait { - protected function forceProperty($subject, string $name, $value) + protected function forceProperty(object $subject, string $name, mixed $value): void { $objectReflection = new \ReflectionObject($subject); $property = $objectReflection->getProperty($name); diff --git a/Tests/Functional/CalendarControllerTest.php b/Tests/Functional/CalendarControllerTest.php index c412cc6..fdfb58f 100644 --- a/Tests/Functional/CalendarControllerTest.php +++ b/Tests/Functional/CalendarControllerTest.php @@ -23,30 +23,32 @@ namespace WerkraumMedia\Calendar\Tests\Functional; +use Codappix\Typo3PhpDatasets\TestingFramework; +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\TestDox; +use TYPO3\CMS\Core\Localization\DateFormatter; use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -use WerkraumMedia\Calendar\Controller\Frontend\CalendarController; -/** - * @coversNothing - * @testdox Calendar controller renders with - */ +#[TestDox('Calendar controller renders with')] class CalendarControllerTest extends FunctionalTestCase { - protected $coreExtensionsToLoad = [ + use TestingFramework; + + protected array $coreExtensionsToLoad = [ 'fluid_styled_content', ]; - protected $testExtensionsToLoad = [ + protected array $testExtensionsToLoad = [ 'typo3conf/ext/calendar', 'typo3conf/ext/calendar/Tests/Fixtures/calendar_example', ]; - protected $pathsToLinkInTestInstance = [ + protected array $pathsToLinkInTestInstance = [ 'typo3conf/ext/calendar/Tests/Fixtures/Sites' => 'typo3conf/sites', ]; - protected $configurationToUseInTestInstance = [ + protected array $configurationToUseInTestInstance = [ 'FE' => [ 'cacheHash' => [ 'excludedParameters' => [ @@ -61,45 +63,39 @@ protected function setUp(): void { parent::setUp(); - $this->importDataSet(__DIR__ . '/../Fixtures/BasicDatabase.xml'); + $this->importPHPDataSet(__DIR__ . '/../Fixtures/BasicDatabase.php'); } - /** - * @test - */ + #[Test] public function modifiedVariablesForCurrentDay(): void { $request = new InternalRequest(); $request = $request->withPageId(1); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); self::assertStringContainsString('modifiedVariable', $html); } - /** - * @test - */ + #[Test] public function pluginNameForCurrentDay(): void { $request = new InternalRequest(); $request = $request->withPageId(1); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); self::assertStringContainsString('PluginName: Example', $html); } - /** - * @test - */ + #[Test] public function contextForCurrentDay(): void { $request = new InternalRequest(); $request = $request->withPageId(1); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); @@ -107,14 +103,12 @@ public function contextForCurrentDay(): void self::assertStringContainsString('Title: Page Title', $html); } - /** - * @test - */ + #[Test] public function customDataForCurrentDay(): void { $request = new InternalRequest(); $request = $request->withPageId(1); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); @@ -122,75 +116,65 @@ public function customDataForCurrentDay(): void self::assertStringContainsString('exampleValue', $html); } - /** - * @test - */ + #[Test] public function configuredDay(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('typoScriptDefaults', '1'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); self::assertStringContainsString('03.11.1988', $html); } - /** - * @test - */ + #[Test] public function providedDay(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[day][day]', '2020-11-03'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); self::assertStringContainsString('03.11.2020', $html); } - /** - * @test - */ + #[Test] public function modifiedVariablesForCurrentWeek(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'week'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); self::assertStringContainsString('modifiedVariable', $html); } - /** - * @test - */ + #[Test] public function pluginNameForCurrentWeek(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'week'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); self::assertStringContainsString('PluginName: Example', $html); } - /** - * @test - */ + #[Test] public function contextForCurrentWeek(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'week'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); @@ -198,15 +182,13 @@ public function contextForCurrentWeek(): void self::assertStringContainsString('Title: Page Title', $html); } - /** - * @test - */ + #[Test] public function customDataForCurrentWeek(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'week'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); @@ -214,25 +196,21 @@ public function customDataForCurrentWeek(): void self::assertStringContainsString('exampleValue', $html); } - /** - * @test - */ + #[Test] public function configuredWeek(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'week'); $request = $request->withQueryParameter('typoScriptDefaults', '1'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); self::assertStringContainsString('12 1988', $html); } - /** - * @test - */ + #[Test] public function providedWeek(): void { $request = new InternalRequest(); @@ -240,52 +218,46 @@ public function providedWeek(): void $request = $request->withQueryParameter('tx_calendar_example[action]', 'week'); $request = $request->withQueryParameter('tx_calendar_example[week][week]', '02'); $request = $request->withQueryParameter('tx_calendar_example[week][year]', '2020'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); self::assertStringContainsString('02 2020', $html); } - /** - * @test - */ + #[Test] public function modifiedVariablesForCurrentMonth(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'month'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); self::assertStringContainsString('modifiedVariable', $html); } - /** - * @test - */ + #[Test] public function pluginNameForCurrentMonth(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'month'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); self::assertStringContainsString('PluginName: Example', $html); } - /** - * @test - */ + #[Test] public function contextForCurrentMonth(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'month'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); @@ -293,41 +265,35 @@ public function contextForCurrentMonth(): void self::assertStringContainsString('Title: Page Title', $html); } - /** - * @test - */ + #[Test] public function customDataForCurrentMonth(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'month'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); - self::assertStringContainsString(strftime('%B %Y'), $html); + self::assertStringContainsString((new DateFormatter())->strftime('%B %Y', 'now', 'de-DE'), $html); self::assertStringContainsString('exampleValue', $html); } - /** - * @test - */ + #[Test] public function configuredMonth(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'month'); $request = $request->withQueryParameter('typoScriptDefaults', '1'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); self::assertStringContainsString('November 1988', $html); } - /** - * @test - */ + #[Test] public function providedMonth(): void { $request = new InternalRequest(); @@ -335,7 +301,7 @@ public function providedMonth(): void $request = $request->withQueryParameter('tx_calendar_example[action]', 'month'); $request = $request->withQueryParameter('tx_calendar_example[month][month]', '11'); $request = $request->withQueryParameter('tx_calendar_example[month][year]', '2020'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); @@ -343,45 +309,39 @@ public function providedMonth(): void self::assertStringContainsString('exampleValue', $html); } - /** - * @test - */ + #[Test] public function modifiedVariablesForCurrentYear(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'year'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); self::assertStringContainsString('modifiedVariable', $html); } - /** - * @test - */ + #[Test] public function pluginNameForCurrentYear(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'year'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); self::assertStringContainsString('PluginName: Example', $html); } - /** - * @test - */ + #[Test] public function contextForCurrentYear(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'year'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); @@ -389,15 +349,13 @@ public function contextForCurrentYear(): void self::assertStringContainsString('Title: Page Title', $html); } - /** - * @test - */ + #[Test] public function customDataForCurrentYear(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'year'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); @@ -405,32 +363,28 @@ public function customDataForCurrentYear(): void self::assertStringContainsString('exampleValue', $html); } - /** - * @test - */ + #[Test] public function configuredYear(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'year'); $request = $request->withQueryParameter('typoScriptDefaults', '1'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); self::assertStringContainsString('1988', $html); } - /** - * @test - */ + #[Test] public function providedYear(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('tx_calendar_example[action]', 'year'); $request = $request->withQueryParameter('tx_calendar_example[year][year]', '2020'); - $result = $this->executeFrontendRequest($request); + $result = $this->executeFrontendSubRequest($request); self::assertSame(200, $result->getStatusCode()); $html = $result->getBody()->__toString(); diff --git a/Tests/Unit/Domain/Model/ContextTest.php b/Tests/Unit/Domain/Model/ContextTest.php index 380822d..c7cbfd4 100644 --- a/Tests/Unit/Domain/Model/ContextTest.php +++ b/Tests/Unit/Domain/Model/ContextTest.php @@ -23,32 +23,14 @@ namespace WerkraumMedia\Calendar\Tests\Unit\Domain\Model; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use WerkraumMedia\Calendar\Domain\Model\Context; -/** - * @covers \WerkraumMedia\Calendar\Domain\Model\Context - */ class ContextTest extends TestCase { - /** - * @test - */ - public function canNotBeCreatedViaNew(): void - { - $this->expectError(); - if (version_compare(PHP_VERSION, '8.0', '>=')) { - $this->expectErrorMessage('Call to private WerkraumMedia\Calendar\Domain\Model\Context::__construct() from scope WerkraumMedia\Calendar\Tests\Unit\Domain\Model\ContextTest'); - } else { - $this->expectErrorMessage('Call to private WerkraumMedia\Calendar\Domain\Model\Context::__construct() from context \'WerkraumMedia\Calendar\Tests\Unit\Domain\Model\ContextTest\''); - } - $subject = new Context(); - } - - /** - * @test - */ + #[Test] public function canBeCreatedFromContentObjectRenderer(): void { $contentObjectRenderer = $this->createStub(ContentObjectRenderer::class); @@ -57,9 +39,7 @@ public function canBeCreatedFromContentObjectRenderer(): void self::assertInstanceOf(Context::class, $subject); } - /** - * @test - */ + #[Test] public function providesTableNameInheritedFromContentObjectRenderer(): void { $contentObjectRenderer = $this->createStub(ContentObjectRenderer::class); @@ -69,9 +49,7 @@ public function providesTableNameInheritedFromContentObjectRenderer(): void self::assertSame('tx_calendar_example_table', $subject->getTableName()); } - /** - * @test - */ + #[Test] public function providesDatabaseRowInheritedFromContentObjectRenderer(): void { $contentObjectRenderer = $this->createStub(ContentObjectRenderer::class); diff --git a/Tests/Unit/Domain/Model/DayTest.php b/Tests/Unit/Domain/Model/DayTest.php index 7bfc028..5177f05 100644 --- a/Tests/Unit/Domain/Model/DayTest.php +++ b/Tests/Unit/Domain/Model/DayTest.php @@ -21,19 +21,16 @@ * 02110-1301, USA. */ +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Persistence\ObjectStorage; use WerkraumMedia\Calendar\Domain\Model\Day; use WerkraumMedia\Calendar\Domain\Model\ForeignDataFactory; use WerkraumMedia\Calendar\Domain\Model\IsDayActive; -use WerkraumMedia\Calendar\Domain\Model\NullDataFactory; use WerkraumMedia\Calendar\Tests\ForcePropertyTrait; -/** - * @covers WerkraumMedia\Calendar\Domain\Model\Day - * @testdox A day - */ +#[TestDox('A day')] class DayTest extends TestCase { use ForcePropertyTrait; @@ -44,9 +41,7 @@ public function tearDown(): void parent::tearDown(); } - /** - * @test - */ + #[Test] public function canBeCreated(): void { $subject = new Day( @@ -56,9 +51,7 @@ public function canBeCreated(): void self::assertInstanceOf(Day::class, $subject); } - /** - * @test - */ + #[Test] public function providesDateTimeInstance(): void { $dateTimeInstance = new \DateTime(); @@ -69,9 +62,7 @@ public function providesDateTimeInstance(): void self::assertInstanceOf(\DateTimeImmutable::class, $subject->getDateTimeInstance()); } - /** - * @test - */ + #[Test] public function providedDateTimeInstanceHasExpectedDay(): void { $dateTimeInstance = new \DateTime(); @@ -82,9 +73,7 @@ public function providedDateTimeInstanceHasExpectedDay(): void self::assertSame($dateTimeInstance->format('d.m.Y'), $subject->getDateTimeInstance()->format('d.m.Y')); } - /** - * @test - */ + #[Test] public function providedDateTimeInstanceHasMidnight(): void { $dateTimeInstance = new \DateTime(); @@ -95,9 +84,7 @@ public function providedDateTimeInstanceHasMidnight(): void self::assertSame('00:00:00', $subject->getDateTimeInstance()->format('H:i:s')); } - /** - * @test - */ + #[Test] public function providesItselfAsUrlArgument(): void { $subject = new Day(new \DateTime('2020-10-19')); @@ -105,9 +92,7 @@ public function providesItselfAsUrlArgument(): void self::assertSame(['day' => '2020-10-19'], $subject->getAsUrlArgument()); } - /** - * @test - */ + #[Test] public function isNotActiveIfNoForeignDataWithInterfaceExists(): void { $subject = new Day(new \DateTime('2020-10-19')); @@ -117,9 +102,7 @@ public function isNotActiveIfNoForeignDataWithInterfaceExists(): void self::assertFalse($subject->isActive()); } - /** - * @test - */ + #[Test] public function isNotActiveIfForeignDataIsNotActive(): void { $subject = new Day(new \DateTime('2020-10-19')); @@ -133,9 +116,7 @@ public function isNotActiveIfForeignDataIsNotActive(): void self::assertFalse($subject->isActive()); } - /** - * @test - */ + #[Test] public function initializesForeignDataViaFactory(): void { $subject = new Day(new \DateTime('2020-10-19')); diff --git a/Tests/Unit/Domain/Model/MonthTest.php b/Tests/Unit/Domain/Model/MonthTest.php index f214f63..5e8c81b 100644 --- a/Tests/Unit/Domain/Model/MonthTest.php +++ b/Tests/Unit/Domain/Model/MonthTest.php @@ -21,22 +21,19 @@ * 02110-1301, USA. */ +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; use WerkraumMedia\Calendar\Domain\Model\Month; use WerkraumMedia\Calendar\Domain\Model\Week; use WerkraumMedia\Calendar\Tests\ForcePropertyTrait; -/** - * @covers WerkraumMedia\Calendar\Domain\Model\Month - * @testdox A month - */ +#[TestDox('A month')] class MonthTest extends TestCase { use ForcePropertyTrait; - /** - * @test - */ + #[Test] public function canBeCreated(): void { $subject = new Month(1, 2020); @@ -44,9 +41,7 @@ public function canBeCreated(): void self::assertInstanceOf(Month::class, $subject); } - /** - * @test - */ + #[Test] public function returnsPreviousMonthForSameYear(): void { $subject = new Month(2, 2020); @@ -55,9 +50,7 @@ public function returnsPreviousMonthForSameYear(): void self::assertSame('2020', $subject->getPreviousMonth()->getDateTimeInstance()->format('Y')); } - /** - * @test - */ + #[Test] public function returnsPreviousMonthForPreviousYear(): void { $subject = new Month(1, 2020); @@ -66,9 +59,7 @@ public function returnsPreviousMonthForPreviousYear(): void self::assertSame('2019', $subject->getPreviousMonth()->getDateTimeInstance()->format('Y')); } - /** - * @test - */ + #[Test] public function returnsNextMonthForSameYear(): void { $subject = new Month(1, 2020); @@ -77,9 +68,7 @@ public function returnsNextMonthForSameYear(): void self::assertSame('2020', $subject->getNextMonth()->getDateTimeInstance()->format('Y')); } - /** - * @test - */ + #[Test] public function returnsNextMonthForNextYear(): void { $subject = new Month(12, 2020); @@ -88,9 +77,7 @@ public function returnsNextMonthForNextYear(): void self::assertSame('2021', $subject->getNextMonth()->getDateTimeInstance()->format('Y')); } - /** - * @test - */ + #[Test] public function returnsFiveWeeksForDecember2020(): void { $subject = new Month(12, 2020); @@ -101,9 +88,7 @@ public function returnsFiveWeeksForDecember2020(): void self::assertSame('2021-01-03', $weeks[4]->getDays()[6]->getDateTimeInstance()->format('Y-m-d')); } - /** - * @test - */ + #[Test] public function returnsSixWeeksForNovember2020(): void { $subject = new Month(11, 2020); @@ -114,9 +99,7 @@ public function returnsSixWeeksForNovember2020(): void self::assertSame('2020-12-06', $weeks[5]->getDays()[6]->getDateTimeInstance()->format('Y-m-d')); } - /** - * @test - */ + #[Test] public function returnsSameWeeksOnSecondCall(): void { $subject = new Month(11, 2020); @@ -124,9 +107,7 @@ public function returnsSameWeeksOnSecondCall(): void self::assertSame($subject->getWeeks(), $subject->getWeeks()); } - /** - * @test - */ + #[Test] public function returnsAllDaysOfTheFebruaryMonth2021(): void { $subject = new Month(02, 2021); @@ -138,9 +119,7 @@ public function returnsAllDaysOfTheFebruaryMonth2021(): void self::assertSame('2021-02-28', $result[27]->getDateTimeInstance()->format('Y-m-d')); } - /** - * @test - */ + #[Test] public function returnsWeeksIfLastDecemberWeekIsInNextYear(): void { $subject = new Month(12, 2024); @@ -160,9 +139,7 @@ public function returnsWeeksIfLastDecemberWeekIsInNextYear(): void self::assertSame('2024-12-29', $days[6]->getDateTimeInstance()->format('Y-m-d')); } - /** - * @test - */ + #[Test] public function returnsAllDaysOfTheJuneMonth2021(): void { $subject = new Month(06, 2021); @@ -174,9 +151,7 @@ public function returnsAllDaysOfTheJuneMonth2021(): void self::assertSame('2021-06-30', $result[29]->getDateTimeInstance()->format('Y-m-d')); } - /** - * @test - */ + #[Test] public function returnsSameDaysOnSecondCall(): void { $subject = new Month(06, 2021); @@ -184,9 +159,7 @@ public function returnsSameDaysOnSecondCall(): void self::assertSame($subject->getDays(), $subject->getDays()); } - /** - * @test - */ + #[Test] public function providesDateTimeInstance(): void { $subject = new Month(02, 2018); @@ -194,9 +167,7 @@ public function providesDateTimeInstance(): void self::assertSame('2018-02-01', $subject->getDateTimeInstance()->format('Y-m-d')); } - /** - * @test - */ + #[Test] public function returnsAsUrlArguments(): void { $subject = new Month(02, 2018); @@ -207,9 +178,7 @@ public function returnsAsUrlArguments(): void ], $subject->getAsUrlArgument()); } - /** - * @test - */ + #[Test] public function returnsNotActiveIfAllWeeksAreInactive(): void { $subject = new Month(02, 2018); @@ -222,9 +191,7 @@ public function returnsNotActiveIfAllWeeksAreInactive(): void self::assertFalse($subject->isActive()); } - /** - * @test - */ + #[Test] public function returnsActiveIfASingleWeekIsActive(): void { $subject = new Month(02, 2018); diff --git a/Tests/Unit/Domain/Model/NullDataFactoryTest.php b/Tests/Unit/Domain/Model/NullDataFactoryTest.php index 90106bc..3e54ebe 100644 --- a/Tests/Unit/Domain/Model/NullDataFactoryTest.php +++ b/Tests/Unit/Domain/Model/NullDataFactoryTest.php @@ -21,18 +21,14 @@ * 02110-1301, USA. */ +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use WerkraumMedia\Calendar\Domain\Model\Day; use WerkraumMedia\Calendar\Domain\Model\NullDataFactory; -/** - * @covers WerkraumMedia\Calendar\Domain\Model\NullDataFactory - */ class NullDataFactoryTest extends TestCase { - /** - * @test - */ + #[Test] public function returnsNull(): void { $subject = new NullDataFactory(); diff --git a/Tests/Unit/Domain/Model/WeekTest.php b/Tests/Unit/Domain/Model/WeekTest.php index afee954..4368e9e 100644 --- a/Tests/Unit/Domain/Model/WeekTest.php +++ b/Tests/Unit/Domain/Model/WeekTest.php @@ -21,22 +21,19 @@ * 02110-1301, USA. */ +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; use WerkraumMedia\Calendar\Domain\Model\Day; use WerkraumMedia\Calendar\Domain\Model\Week; use WerkraumMedia\Calendar\Tests\ForcePropertyTrait; -/** - * @covers WerkraumMedia\Calendar\Domain\Model\Week - * @testdox A week - */ +#[TestDox('A week')] class WeekTest extends TestCase { use ForcePropertyTrait; - /** - * @test - */ + #[Test] public function canBeCreated(): void { $subject = new Week(1, 2020); @@ -44,9 +41,7 @@ public function canBeCreated(): void self::assertInstanceOf(Week::class, $subject); } - /** - * @test - */ + #[Test] public function returnsSevenDays(): void { $subject = new Week(1, 2020); @@ -54,9 +49,7 @@ public function returnsSevenDays(): void self::assertCount(7, $subject->getDays()); } - /** - * @test - */ + #[Test] public function returnsSameDaysOnSecondCall(): void { $subject = new Week(1, 2020); @@ -64,9 +57,7 @@ public function returnsSameDaysOnSecondCall(): void self::assertSame($subject->getDays(), $subject->getDays()); } - /** - * @test - */ + #[Test] public function returnsDaysForWeek1(): void { $subject = new Week(1, 2020); @@ -81,9 +72,7 @@ public function returnsDaysForWeek1(): void self::assertSame('2020-01-05', $days[6]->getDateTimeInstance()->format('Y-m-d')); } - /** - * @test - */ + #[Test] public function returnsDaysForWeek53(): void { $subject = new Week(53, 2020); @@ -98,9 +87,7 @@ public function returnsDaysForWeek53(): void self::assertSame('2021-01-03', $days[6]->getDateTimeInstance()->format('Y-m-d')); } - /** - * @test - */ + #[Test] public function returnsPreviousWeekForSameYear(): void { $subject = new Week(2, 2020); @@ -109,9 +96,7 @@ public function returnsPreviousWeekForSameYear(): void self::assertSame('2020', $subject->getPreviousWeek()->getDateTimeInstance()->format('Y')); } - /** - * @test - */ + #[Test] public function returnsPreviousWeekForYearSwitchFrom2019To2018(): void { $subject = new Week(1, 2019); @@ -120,9 +105,7 @@ public function returnsPreviousWeekForYearSwitchFrom2019To2018(): void self::assertSame('2018', $subject->getPreviousWeek()->getDateTimeInstance()->format('Y')); } - /** - * @test - */ + #[Test] public function returnsPreviousWeekForYearSwitchFrom2018To2017(): void { $subject = new Week(1, 2018); @@ -131,9 +114,7 @@ public function returnsPreviousWeekForYearSwitchFrom2018To2017(): void self::assertSame('2017', $subject->getPreviousWeek()->getDateTimeInstance()->format('Y')); } - /** - * @test - */ + #[Test] public function returnsPreviousWeekForPreviousYear(): void { $subject = new Week(1, 2021); @@ -142,9 +123,7 @@ public function returnsPreviousWeekForPreviousYear(): void self::assertSame('2020', $subject->getPreviousWeek()->getDateTimeInstance()->format('Y')); } - /** - * @test - */ + #[Test] public function returnsNextWeekForSameYear(): void { $subject = new Week(1, 2020); @@ -153,9 +132,7 @@ public function returnsNextWeekForSameYear(): void self::assertSame('2020', $subject->getNextWeek()->getDateTimeInstance()->format('Y')); } - /** - * @test - */ + #[Test] public function returnsNextWeekForNextYear(): void { $subject = new Week(53, 2020); @@ -164,9 +141,7 @@ public function returnsNextWeekForNextYear(): void self::assertSame('2021', $subject->getNextWeek()->getDateTimeInstance()->format('Y')); } - /** - * @test - */ + #[Test] public function returnsNextWeekForNextYearFrom2018To2019(): void { $subject = new Week(52, 2018); @@ -175,9 +150,7 @@ public function returnsNextWeekForNextYearFrom2018To2019(): void self::assertSame('2019', $subject->getNextWeek()->getDateTimeInstance()->format('Y')); } - /** - * @test - */ + #[Test] public function providesDateTimeInstance(): void { $subject = new Week(52, 2018); @@ -186,9 +159,7 @@ public function providesDateTimeInstance(): void self::assertSame('2018-12-27 Thursday', $subject->getDateTimeInstance()->format('Y-m-d l')); } - /** - * @test - */ + #[Test] public function providesItselfAsUrlArgument(): void { $subject = new Week(52, 2018); @@ -199,9 +170,7 @@ public function providesItselfAsUrlArgument(): void ], $subject->getAsUrlArgument()); } - /** - * @test - */ + #[Test] public function returnsNotActiveIfAllDaysAreInactive(): void { $subject = new Week(02, 2018); @@ -214,9 +183,7 @@ public function returnsNotActiveIfAllDaysAreInactive(): void self::assertFalse($subject->isActive()); } - /** - * @test - */ + #[Test] public function returnsActiveIfASingleDayActive(): void { $subject = new Week(02, 2018); diff --git a/Tests/Unit/Domain/Model/YearTest.php b/Tests/Unit/Domain/Model/YearTest.php index c55c65a..4af88e6 100644 --- a/Tests/Unit/Domain/Model/YearTest.php +++ b/Tests/Unit/Domain/Model/YearTest.php @@ -21,22 +21,19 @@ * 02110-1301, USA. */ +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; use WerkraumMedia\Calendar\Domain\Model\Month; use WerkraumMedia\Calendar\Domain\Model\Year; use WerkraumMedia\Calendar\Tests\ForcePropertyTrait; -/** - * @covers WerkraumMedia\Calendar\Domain\Model\Year - * @testdox A year - */ +#[TestDox('A year')] class YearTest extends TestCase { use ForcePropertyTrait; - /** - * @test - */ + #[Test] public function canBeCreated(): void { $subject = new Year(2020); @@ -44,9 +41,7 @@ public function canBeCreated(): void self::assertInstanceOf(Year::class, $subject); } - /** - * @test - */ + #[Test] public function returnsPreviousYear(): void { $subject = new Year(2020); @@ -57,9 +52,7 @@ public function returnsPreviousYear(): void self::assertSame('2019', $result->getDateTimeInstance()->format('Y')); } - /** - * @test - */ + #[Test] public function returnsNextYear(): void { $subject = new Year(2020); @@ -70,9 +63,7 @@ public function returnsNextYear(): void self::assertSame('2021', $result->getDateTimeInstance()->format('Y')); } - /** - * @test - */ + #[Test] public function returnsAsUrlArguments(): void { $subject = new Year(2020); @@ -82,9 +73,7 @@ public function returnsAsUrlArguments(): void ], $subject->getAsUrlArgument()); } - /** - * @test - */ + #[Test] public function returnsMonthsForYear2020(): void { $subject = new Year(2020); @@ -96,13 +85,11 @@ public function returnsMonthsForYear2020(): void foreach ($result as $index => $month) { self::assertInstanceOf(Month::class, $month); $monthNumber = $index + 1; - self::assertSame((string) $monthNumber, $month->getDateTimeInstance()->format('n')); + self::assertSame((string)$monthNumber, $month->getDateTimeInstance()->format('n')); } } - /** - * @test - */ + #[Test] public function returnsSameMonthsOnSecondCall(): void { $subject = new Year(2020); @@ -110,9 +97,7 @@ public function returnsSameMonthsOnSecondCall(): void self::assertSame($subject->getMonths(), $subject->getMonths()); } - /** - * @test - */ + #[Test] public function returnsAllDaysFor2020(): void { $subject = new Year(2020); @@ -124,9 +109,7 @@ public function returnsAllDaysFor2020(): void self::assertSame('2020-12-31', $result[365]->getDateTimeInstance()->format('Y-m-d')); } - /** - * @test - */ + #[Test] public function returnsNotActiveIfAllMonthsAreInactive(): void { $subject = new Year(2020); @@ -139,9 +122,7 @@ public function returnsNotActiveIfAllMonthsAreInactive(): void self::assertFalse($subject->isActive()); } - /** - * @test - */ + #[Test] public function returnsActiveIfASingleMonthIsActive(): void { $subject = new Year(2020); diff --git a/Tests/Unit/Events/AssignTemplateVariablesTest.php b/Tests/Unit/Events/AssignTemplateVariablesTest.php index f5d738b..35b4d34 100644 --- a/Tests/Unit/Events/AssignTemplateVariablesTest.php +++ b/Tests/Unit/Events/AssignTemplateVariablesTest.php @@ -21,17 +21,13 @@ * 02110-1301, USA. */ +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use WerkraumMedia\Calendar\Events\AssignTemplateVariables; -/** - * @covers WerkraumMedia\Calendar\Events\AssignTemplateVariables - */ class AssignTemplateVariablesTest extends TestCase { - /** - * @test - */ + #[Test] public function canBeCreated(): void { $subject = new AssignTemplateVariables( @@ -42,9 +38,7 @@ public function canBeCreated(): void self::assertInstanceOf(AssignTemplateVariables::class, $subject); } - /** - * @test - */ + #[Test] public function returnsPluginName(): void { $subject = new AssignTemplateVariables( @@ -57,9 +51,7 @@ public function returnsPluginName(): void self::assertSame('Example', $result); } - /** - * @test - */ + #[Test] public function returnsVariables(): void { $subject = new AssignTemplateVariables( @@ -76,9 +68,7 @@ public function returnsVariables(): void ], $result); } - /** - * @test - */ + #[Test] public function newVariablesOverwriteExistingVariables(): void { $subject = new AssignTemplateVariables( diff --git a/composer.json b/composer.json index 7dc5dda..294cc84 100644 --- a/composer.json +++ b/composer.json @@ -11,16 +11,21 @@ ], "config": { "sort-packages": true, + "lock": false, "allow-plugins": { "typo3/class-alias-loader": true, "typo3/cms-composer-installers": true } }, + "minimum-stability": "dev", + "prefer-stable": true, "require": { - "php": "^7.3.0 || ^7.4.0 || ^8.0.0 || ^8.1.0 || ^8.2.0", - "typo3/cms-core": "^10.4 || ^11.5", - "typo3/cms-extbase": "^10.4 || ^11.5", - "typo3/cms-frontend": "^10.4 || ^11.5" + "php": "~8.1.0 || ~8.2.0 || ~8.3.0", + "typo3/cms-backend": "^12.4", + "typo3/cms-core": "^12.4", + "typo3/cms-extbase": "^12.4", + "typo3/cms-fluid-styled-content": "^12.4", + "typo3/cms-frontend": "^12.4" }, "autoload": { "psr-4": { @@ -34,14 +39,16 @@ } }, "require-dev": { - "phpunit/phpunit": "^9.5", - "symplify/easy-coding-standard": "^9.2", - "typo3/cms-fluid-styled-content": "^10.4 || ^11.5", - "typo3/testing-framework": "^6.6" + "codappix/typo3-php-datasets": "^1.5", + "friendsofphp/php-cs-fixer": "^3.11", + "phpstan/phpstan": "^1.12", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^10.5 || ^11.3", + "saschaegerer/phpstan-typo3": "^1.10", + "typo3/testing-framework": "^8.2" }, "extra": { "typo3/cms": { - "cms-package-dir": "{$vendor-dir}/typo3/cms", "extension-key": "calendar", "web-dir": ".Build/web" } diff --git a/ecs.php b/ecs.php deleted file mode 100644 index 379a801..0000000 --- a/ecs.php +++ /dev/null @@ -1,35 +0,0 @@ -parameters(); - $parameters->set(Option::PATHS, [ - __DIR__ . '/Classes', - __DIR__ . '/Tests', - __DIR__ . '/ext_emconf.php', - __DIR__ . '/ecs.php', - ]); - - $parameters->set(Option::SETS, [ - // run and fix, one by one - // SetList::SPACES, - // SetList::ARRAY, - // SetList::DOCBLOCK, - // SetList::NAMESPACES, - // SetList::CONTROL_STRUCTURES, - // SetList::CLEAN_CODE, - SetList::PSR_12, - ]); - - $services = $containerConfigurator->services(); - $services->set(ArraySyntaxFixer::class) - ->call('configure', [[ - 'syntax' => 'short', - ]]); -}; diff --git a/ext_emconf.php b/ext_emconf.php index 80d6d14..19cc470 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -10,7 +10,7 @@ 'state' => 'alpha', 'uploadfolder' => 0, 'clearCacheOnLoad' => 0, - 'version' => '1.1.1', + 'version' => '2.0.0', 'constraints' => [ 'depends' => [ 'typo3' => '*', diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..28e3f34 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,10 @@ +parameters: + level: 'max' + paths: + - 'Classes' + - 'Configuration' + - 'Tests' + reportUnmatchedIgnoredErrors: true + ignoreErrors: + - + identifier: 'missingType.iterableValue' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 858b92f..50b1459 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,21 +1,25 @@ + cacheDirectory=".phpunit.cache" + backupStaticProperties="false" + requireCoverageMetadata="false" +> + + + + Classes + + @@ -26,12 +30,6 @@ - - - Classes - - - diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..2e5e12d --- /dev/null +++ b/shell.nix @@ -0,0 +1,52 @@ +{ pkgs ? import { } }: + +let + php = pkgs.php82.buildEnv { + extensions = { enabled, all }: enabled ++ (with all; [ + xdebug + ]); + extraConfig = '' + xdebug.mode = debug + memory_limit = 4G + ''; + }; + inherit (php.packages) composer; + + projectInstall = pkgs.writeShellApplication { + name = "project-install"; + runtimeInputs = [ + php + composer + ]; + text = '' + rm -rf vendor/ .Build/ + composer install --prefer-dist --no-progress --working-dir="$PROJECT_ROOT" + ''; + }; + + projectValidateComposer = pkgs.writeShellApplication { + name = "project-validate-composer"; + runtimeInputs = [ + php + composer + ]; + text = '' + composer validate + ''; + }; + +in pkgs.mkShell { + name = "TYPO3 Extension Watchlist"; + buildInputs = [ + projectInstall + projectValidateComposer + php + composer + ]; + + shellHook = '' + export PROJECT_ROOT="$(pwd)" + + export typo3DatabaseDriver=pdo_sqlite + ''; +}