From 413afa1851d15ee744ff51c391cb0780f7e34321 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Mon, 5 Feb 2024 11:25:00 +0100 Subject: [PATCH] Update * Rector result with cgl applied * Fix constructor multi line by hand * Migrate away from prophecy. --- .php-cs-fixer.dist.php | 418 +++++++++++++++--- Classes/Command/UpdateDataCommand.php | 12 +- .../Dashboard/Provider/NewestPageviews.php | 41 +- .../Dashboard/Provider/PageviewsPerDay.php | 62 +-- .../Provider/PageviewsPerOperatingSystem.php | 40 +- .../Dashboard/Provider/PageviewsPerPage.php | 66 +-- Classes/Dashboard/Provider/Recordviews.php | 99 ++--- .../SymfonyExpressionLanguage.php | 2 +- Classes/Domain/Model/Expression.php | 5 +- Classes/Domain/Model/Pageview.php | 56 +-- Classes/Domain/Model/RecordRule.php | 24 +- Classes/Domain/Model/Recordview.php | 56 +-- Classes/Domain/Model/SymfonyExpression.php | 26 +- Classes/Domain/Pageview/Factory.php | 23 +- Classes/Domain/Recordview/Factory.php | 12 +- Classes/Domain/Repository/Pageview.php | 31 +- Classes/Domain/Repository/Recordview.php | 8 +- Classes/Hooks/DataHandler.php | 7 +- Classes/LanguageAspectFactory.php | 38 ++ Classes/Middleware/Pageview.php | 42 +- Classes/Middleware/Recordview.php | 37 +- .../Backend/DashboardWidgetGroups.php | 2 + Configuration/Backend/DashboardWidgets.yaml | 4 - Configuration/RequestMiddlewares.php | 2 + Configuration/TCA/tx_tracking_pageview.php | 17 +- Configuration/TCA/tx_tracking_recordview.php | 14 +- ...est.php => AbstractFunctionalTestCase.php} | 13 +- .../Command/UpdateDataCommandTest.php | 31 +- .../Provider/NewestPageviewsTest.php | 32 +- .../Provider/PageviewsPerDayTest.php | 41 +- .../PageviewsPerOperatingSystemTest.php | 39 +- .../Provider/PageviewsPerPageTest.php | 89 ++-- .../Dashboard/Provider/RecordviewsTest.php | 95 ++-- .../Domain/Recordview/FactoryTest.php | 277 ++++++------ Tests/Functional/Fixtures/BackendUser.php | 2 + .../Extensions/recordview/ext_emconf.php | 2 + Tests/Functional/Fixtures/Pages.php | 2 + Tests/Functional/Fixtures/SysCategories.php | 2 + .../Typo3FeaturesTest/PageWithRecords.php | 2 + .../PageviewsWithMissingOperatingSystem.php | 2 + .../PageviewsWithOperatingSystem.php | 2 + Tests/Functional/PageviewTest.php | 50 +-- Tests/Functional/RecordviewTest.php | 42 +- Tests/Functional/Typo3FeaturesTest.php | 37 +- Tests/Unit/Domain/Model/ExtractorTest.php | 32 +- Tests/Unit/Domain/Model/PageviewTest.php | 94 ++-- Tests/Unit/Domain/Model/RecordRuleTest.php | 33 +- Tests/Unit/Domain/Model/RecordviewTest.php | 86 ++-- Tests/Unit/Domain/Pageview/FactoryTest.php | 226 +++++----- Tests/Unit/Domain/Repository/PageviewTest.php | 190 ++++---- .../Unit/Domain/Repository/RecordviewTest.php | 83 ++-- composer.json | 7 +- ext_localconf.php | 6 +- phpstan-baseline.neon | 51 --- phpstan.neon | 11 +- shell.nix | 18 +- 56 files changed, 1252 insertions(+), 1489 deletions(-) create mode 100644 Classes/LanguageAspectFactory.php rename Tests/Functional/{AbstractFunctionalTest.php => AbstractFunctionalTestCase.php} (75%) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 2a7eada..6cfe70e 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,63 +1,365 @@ ignoreVCSIgnored(true) - ->in(realpath(__DIR__)) -; -return (new \PhpCsFixer\Config()) +declare(strict_types=1); + +use PhpCsFixer\Config; +use PhpCsFixer\Finder; +use PhpCsFixer\Fixer\Alias\MbStrFunctionsFixer; +use PhpCsFixer\Fixer\Alias\NoAliasFunctionsFixer; +use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer; +use PhpCsFixer\Fixer\ArrayNotation\NoMultilineWhitespaceAroundDoubleArrowFixer; +use PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer; +use PhpCsFixer\Fixer\ArrayNotation\NormalizeIndexBraceFixer; +use PhpCsFixer\Fixer\ArrayNotation\ReturnToYieldFromFixer; +use PhpCsFixer\Fixer\ArrayNotation\TrimArraySpacesFixer; +use PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer; +use PhpCsFixer\Fixer\ArrayNotation\YieldFromArrayToYieldsFixer; +use PhpCsFixer\Fixer\AttributeNotation\AttributeEmptyParenthesesFixer; +use PhpCsFixer\Fixer\Basic\NoMultipleStatementsPerLineFixer; +use PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer; +use PhpCsFixer\Fixer\Basic\NonPrintableCharacterFixer; +use PhpCsFixer\Fixer\Basic\NumericLiteralSeparatorFixer; +use PhpCsFixer\Fixer\Casing\ClassReferenceNameCasingFixer; +use PhpCsFixer\Fixer\Casing\NativeFunctionCasingFixer; +use PhpCsFixer\Fixer\Casing\NativeTypeDeclarationCasingFixer; +use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer; +use PhpCsFixer\Fixer\CastNotation\ModernizeTypesCastingFixer; +use PhpCsFixer\Fixer\CastNotation\NoUnsetCastFixer; +use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer; +use PhpCsFixer\Fixer\ClassNotation\NoNullPropertyInitializationFixer; +use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer; +use PhpCsFixer\Fixer\ClassNotation\OrderedInterfacesFixer; +use PhpCsFixer\Fixer\ClassNotation\OrderedTraitsFixer; +use PhpCsFixer\Fixer\ClassNotation\OrderedTypesFixer; +use PhpCsFixer\Fixer\ClassNotation\SelfAccessorFixer; +use PhpCsFixer\Fixer\Comment\MultilineCommentOpeningClosingFixer; +use PhpCsFixer\Fixer\Comment\NoEmptyCommentFixer; +use PhpCsFixer\Fixer\Comment\SingleLineCommentStyleFixer; +use PhpCsFixer\Fixer\ControlStructure\NoSuperfluousElseifFixer; +use PhpCsFixer\Fixer\ControlStructure\NoUnneededBracesFixer; +use PhpCsFixer\Fixer\ControlStructure\NoUnneededControlParenthesesFixer; +use PhpCsFixer\Fixer\ControlStructure\NoUselessElseFixer; +use PhpCsFixer\Fixer\ControlStructure\SimplifiedIfReturnFixer; +use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer; +use PhpCsFixer\Fixer\FunctionNotation\DateTimeCreateFromFormatCallFixer; +use PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer; +use PhpCsFixer\Fixer\FunctionNotation\NoUnreachableDefaultArgumentValueFixer; +use PhpCsFixer\Fixer\FunctionNotation\NoUselessSprintfFixer; +use PhpCsFixer\Fixer\FunctionNotation\NullableTypeDeclarationForDefaultNullValueFixer; +use PhpCsFixer\Fixer\FunctionNotation\PhpdocToParamTypeFixer; +use PhpCsFixer\Fixer\FunctionNotation\PhpdocToPropertyTypeFixer; +use PhpCsFixer\Fixer\FunctionNotation\PhpdocToReturnTypeFixer; +use PhpCsFixer\Fixer\FunctionNotation\RegularCallableCallFixer; +use PhpCsFixer\Fixer\FunctionNotation\StaticLambdaFixer; +use PhpCsFixer\Fixer\Import\FullyQualifiedStrictTypesFixer; +use PhpCsFixer\Fixer\Import\GlobalNamespaceImportFixer; +use PhpCsFixer\Fixer\Import\NoUnneededImportAliasFixer; +use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer; +use PhpCsFixer\Fixer\Import\OrderedImportsFixer; +use PhpCsFixer\Fixer\LanguageConstruct\ClassKeywordFixer; +use PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveIssetsFixer; +use PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveUnsetsFixer; +use PhpCsFixer\Fixer\LanguageConstruct\NullableTypeDeclarationFixer; +use PhpCsFixer\Fixer\LanguageConstruct\SingleSpaceAroundConstructFixer; +use PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer; +use PhpCsFixer\Fixer\NamespaceNotation\BlankLinesBeforeNamespaceFixer; +use PhpCsFixer\Fixer\Naming\NoHomoglyphNamesFixer; +use PhpCsFixer\Fixer\Operator\ConcatSpaceFixer; +use PhpCsFixer\Fixer\Operator\IncrementStyleFixer; +use PhpCsFixer\Fixer\Operator\LongToShorthandOperatorFixer; +use PhpCsFixer\Fixer\Operator\NewWithParenthesesFixer; +use PhpCsFixer\Fixer\Operator\NoUselessConcatOperatorFixer; +use PhpCsFixer\Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer; +use PhpCsFixer\Fixer\Operator\OperatorLinebreakFixer; +use PhpCsFixer\Fixer\Operator\StandardizeIncrementFixer; +use PhpCsFixer\Fixer\Operator\TernaryOperatorSpacesFixer; +use PhpCsFixer\Fixer\Operator\TernaryToElvisOperatorFixer; +use PhpCsFixer\Fixer\Operator\TernaryToNullCoalescingFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitConstructFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitDataProviderReturnTypeFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitDataProviderStaticFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertInternalTypeFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitFqcnAnnotationFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitMethodCasingFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitMockFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitMockShortWillReturnFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitNamespacedFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitNoExpectationAnnotationFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitSetUpTearDownVisibilityFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer; +use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixer; +use PhpCsFixer\Fixer\Phpdoc\NoBlankLinesAfterPhpdocFixer; +use PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer; +use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocIndentFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocLineSpanFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocNoAccessFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocOrderByValueFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocOrderFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocParamOrderFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocScalarFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocSeparationFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocToCommentFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimConsecutiveBlankLineSeparationFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocVarAnnotationCorrectOrderFixer; +use PhpCsFixer\Fixer\Phpdoc\PhpdocVarWithoutNameFixer; +use PhpCsFixer\Fixer\ReturnNotation\NoUselessReturnFixer; +use PhpCsFixer\Fixer\Semicolon\MultilineWhitespaceBeforeSemicolonsFixer; +use PhpCsFixer\Fixer\Semicolon\NoEmptyStatementFixer; +use PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer; +use PhpCsFixer\Fixer\Semicolon\SemicolonAfterInstructionFixer; +use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer; +use PhpCsFixer\Fixer\StringNotation\NoTrailingWhitespaceInStringFixer; +use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer; +use PhpCsFixer\Fixer\StringNotation\StringImplicitBackslashesFixer; +use PhpCsFixer\Fixer\StringNotation\StringLengthToEmptyFixer; +use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer; +use PhpCsFixer\Fixer\Whitespace\CompactNullableTypeDeclarationFixer; +use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer; +use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer; +use PhpCsFixer\Fixer\Whitespace\NoSpacesAroundOffsetFixer; +use PhpCsFixer\Fixer\Whitespace\StatementIndentationFixer; +use PhpCsFixer\Fixer\Whitespace\TypeDeclarationSpacesFixer; +use PhpCsFixer\Fixer\Whitespace\TypesSpacesFixer; +use PhpCsFixer\Preg; + +/** + * Transforms a given class to php-cs-fixer rule name. + * That way we can use auto completion, phpstan, etc. + * + * @param class-string $className + */ +function transform(string $className): string +{ + $nameParts = explode('\\', $className); + $name = mb_substr(end($nameParts), 0, -mb_strlen('Fixer')); + + return mb_strtolower(Preg::replace( + '/(?setRiskyAllowed(true) + ->setFinder( + (new Finder()) + ->ignoreVCSIgnored(true) + ->in(realpath(__DIR__)) + ) ->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], + '@PSR12' => true, + transform(ArrayIndentationFixer::class) => true, + transform(ArraySyntaxFixer::class) => [ + 'syntax' => 'short', + ], + transform(AttributeEmptyParenthesesFixer::class) => true, + transform(BlankLinesBeforeNamespaceFixer::class) => true, + transform(CastSpacesFixer::class) => true, + transform(ClassAttributesSeparationFixer::class) => [ + 'elements' => [ + 'const' => 'one', + 'method' => 'one', + 'property' => 'one', + 'trait_import' => 'one', + ], + ], + transform(ClassKeywordFixer::class) => true, + transform(ClassReferenceNameCasingFixer::class) => true, + transform(CombineConsecutiveIssetsFixer::class) => true, + transform(CombineConsecutiveUnsetsFixer::class) => true, + transform(CompactNullableTypeDeclarationFixer::class) => true, + transform(ConcatSpaceFixer::class) => [ + 'spacing' => 'one', + ], + transform(DateTimeCreateFromFormatCallFixer::class) => true, + transform(DeclareStrictTypesFixer::class) => true, + transform(FullyQualifiedStrictTypesFixer::class) => [ + 'import_symbols' => true, + 'leading_backslash_in_global_namespace' => true, + ], + transform(GlobalNamespaceImportFixer::class) => true, + transform(IncrementStyleFixer::class) => [ + 'style' => 'post', + ], + transform(ListSyntaxFixer::class) => true, + transform(LongToShorthandOperatorFixer::class) => true, + transform(MbStrFunctionsFixer::class) => true, + transform(MethodArgumentSpaceFixer::class) => [ + 'on_multiline' => 'ensure_fully_multiline', + 'attribute_placement' => 'standalone', + ], + transform(MethodChainingIndentationFixer::class) => true, + transform(ModernizeTypesCastingFixer::class) => true, + transform(MultilineCommentOpeningClosingFixer::class) => true, + transform(MultilineWhitespaceBeforeSemicolonsFixer::class) => [ + 'strategy' => 'new_line_for_chained_calls', + ], + transform(NativeFunctionCasingFixer::class) => true, + transform(NativeTypeDeclarationCasingFixer::class) => true, + transform(NewWithParenthesesFixer::class) => [ + 'anonymous_class' => false, + 'named_class' => true, + ], + transform(NoAliasFunctionsFixer::class) => true, + transform(NoBlankLinesAfterPhpdocFixer::class) => true, + transform(NoEmptyCommentFixer::class) => true, + transform(NoEmptyPhpdocFixer::class) => true, + transform(NoEmptyStatementFixer::class) => true, + transform(NoExtraBlankLinesFixer::class) => true, + transform(NoHomoglyphNamesFixer::class) => true, + transform(NoMultilineWhitespaceAroundDoubleArrowFixer::class) => true, + transform(NoMultipleStatementsPerLineFixer::class) => true, + transform(NoNullPropertyInitializationFixer::class) => true, + transform(NoSinglelineWhitespaceBeforeSemicolonsFixer::class) => true, + transform(NoSpacesAroundOffsetFixer::class) => true, + transform(NoSuperfluousElseifFixer::class) => true, + transform(NoSuperfluousPhpdocTagsFixer::class) => [ + 'allow_mixed' => true, + ], + transform(NoTrailingCommaInSinglelineFixer::class) => true, + transform(NoTrailingWhitespaceInStringFixer::class) => true, + transform(NoUnneededBracesFixer::class) => true, + transform(NoUnneededControlParenthesesFixer::class) => true, + transform(NoUnneededImportAliasFixer::class) => true, + transform(NoUnreachableDefaultArgumentValueFixer::class) => true, + transform(NoUnsetCastFixer::class) => true, + transform(NoUnusedImportsFixer::class) => true, + transform(NoUselessConcatOperatorFixer::class) => true, + transform(NoUselessElseFixer::class) => true, + transform(NoUselessReturnFixer::class) => true, + transform(NoUselessSprintfFixer::class) => true, + transform(NoWhitespaceBeforeCommaInArrayFixer::class) => true, + transform(NonPrintableCharacterFixer::class) => true, + transform(NormalizeIndexBraceFixer::class) => true, + transform(NullableTypeDeclarationFixer::class) => true, + transform(NullableTypeDeclarationForDefaultNullValueFixer::class) => true, + transform(NumericLiteralSeparatorFixer::class) => [ + 'strategy' => NumericLiteralSeparatorFixer::STRATEGY_NO_SEPARATOR, + ], + transform(ObjectOperatorWithoutWhitespaceFixer::class) => true, + transform(OperatorLinebreakFixer::class) => [ + 'position' => 'beginning', ], + transform(OrderedClassElementsFixer::class) => [ + 'order' => [ + 'use_trait', + 'case', + 'constant_public', + 'constant_protected', + 'constant_private', + 'property_public', + 'property_protected', + 'property_private', + 'construct', + 'destruct', + 'phpunit', + 'method_public', + 'method_protected', + 'method_private', + 'magic', + ], + 'case_sensitive' => true, + ], + transform(OrderedImportsFixer::class) => [ + 'sort_algorithm' => 'alpha', + 'case_sensitive' => true, + ], + transform(OrderedInterfacesFixer::class) => [ + 'case_sensitive' => true, + ], + transform(OrderedTraitsFixer::class) => [ + 'case_sensitive' => true, + ], + transform(OrderedTypesFixer::class) => [ + 'case_sensitive' => true, + ], + transform(PhpUnitConstructFixer::class) => true, + transform(PhpUnitDataProviderReturnTypeFixer::class) => true, + transform(PhpUnitDataProviderStaticFixer::class) => [ + 'force' => true, + ], + transform(PhpUnitDedicateAssertFixer::class) => true, + transform(PhpUnitDedicateAssertInternalTypeFixer::class) => true, + transform(PhpUnitFqcnAnnotationFixer::class) => true, + transform(PhpUnitMethodCasingFixer::class) => true, + transform(PhpUnitMockFixer::class) => true, + transform(PhpUnitMockShortWillReturnFixer::class) => true, + transform(PhpUnitNamespacedFixer::class) => true, + transform(PhpUnitNoExpectationAnnotationFixer::class) => true, + transform(PhpUnitSetUpTearDownVisibilityFixer::class) => true, + transform(PhpUnitStrictFixer::class) => true, + transform(PhpUnitTestAnnotationFixer::class) => [ + 'style' => 'annotation', + ], + transform(PhpUnitTestCaseStaticMethodCallsFixer::class) => [ + 'call_type' => 'self', + ], + transform(PhpdocAlignFixer::class) => [ + 'align' => 'left', + ], + transform(PhpdocIndentFixer::class) => true, + transform(PhpdocLineSpanFixer::class) => true, + transform(PhpdocNoAccessFixer::class) => true, + transform(PhpdocOrderByValueFixer::class) => [ + 'annotations' => [ + 'covers', 'throws', + ], + ], + transform(PhpdocOrderFixer::class) => true, + transform(PhpdocParamOrderFixer::class) => true, + transform(PhpdocScalarFixer::class) => true, + transform(PhpdocSeparationFixer::class) => [ + 'groups' => [ + ['see'], + ['throw'], + ['param'], + ['return'], + ], + ], + transform(PhpdocToCommentFixer::class) => true, + transform(PhpdocToParamTypeFixer::class) => true, + transform(PhpdocToPropertyTypeFixer::class) => true, + transform(PhpdocToReturnTypeFixer::class) => true, + transform(PhpdocTrimConsecutiveBlankLineSeparationFixer::class) => true, + transform(PhpdocTrimFixer::class) => true, + transform(PhpdocTypesFixer::class) => true, + transform(PhpdocTypesOrderFixer::class) => [ + 'case_sensitive' => true, + ], + transform(PhpdocVarAnnotationCorrectOrderFixer::class) => true, + transform(PhpdocVarWithoutNameFixer::class) => true, + transform(RegularCallableCallFixer::class) => true, + transform(ReturnToYieldFromFixer::class) => true, + transform(SelfAccessorFixer::class) => true, + transform(SemicolonAfterInstructionFixer::class) => true, + transform(SimplifiedIfReturnFixer::class) => true, + transform(SingleLineCommentStyleFixer::class) => true, + transform(SingleQuoteFixer::class) => true, + transform(SingleSpaceAroundConstructFixer::class) => true, + transform(StandardizeIncrementFixer::class) => true, + transform(StatementIndentationFixer::class) => true, + transform(StaticLambdaFixer::class) => true, + transform(StringImplicitBackslashesFixer::class) => [ + 'single_quoted' => 'ignore', + ], + transform(StringLengthToEmptyFixer::class) => true, + transform(TernaryOperatorSpacesFixer::class) => true, + transform(TernaryToElvisOperatorFixer::class) => true, + transform(TernaryToNullCoalescingFixer::class) => true, + transform(TrailingCommaInMultilineFixer::class) => true, + transform(TrimArraySpacesFixer::class) => true, + transform(TypeDeclarationSpacesFixer::class) => true, + transform(TypesSpacesFixer::class) => true, + transform(WhitespaceAfterCommaInArrayFixer::class) => [ + 'ensure_single_space' => true, + ], + transform(YieldFromArrayToYieldsFixer::class) => true, ]) - ->setFinder($finder); +; diff --git a/Classes/Command/UpdateDataCommand.php b/Classes/Command/UpdateDataCommand.php index d9ae240..874606e 100644 --- a/Classes/Command/UpdateDataCommand.php +++ b/Classes/Command/UpdateDataCommand.php @@ -31,15 +31,9 @@ class UpdateDataCommand extends Command { - /** - * @var Pageview - */ - private $repository; - - public function __construct(Pageview $repository) - { - $this->repository = $repository; - + public function __construct( + private readonly Pageview $repository + ) { parent::__construct(); } diff --git a/Classes/Dashboard/Provider/NewestPageviews.php b/Classes/Dashboard/Provider/NewestPageviews.php index 41a2eda..84c094f 100644 --- a/Classes/Dashboard/Provider/NewestPageviews.php +++ b/Classes/Dashboard/Provider/NewestPageviews.php @@ -23,6 +23,7 @@ namespace DanielSiepmann\Tracking\Dashboard\Provider; +use Exception; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Dashboard\Widgets\ListDataProviderInterface; @@ -30,35 +31,14 @@ class NewestPageviews implements ListDataProviderInterface { /** - * @var QueryBuilder + * @param int[] $languageLimitation */ - private $queryBuilder; - - /** - * @var int - */ - private $maxResults; - - /** - * @var array - */ - private $pagesToExclude; - - /** - * @var array - */ - private $languageLimitation; - public function __construct( - QueryBuilder $queryBuilder, - int $maxResults = 6, - array $pagesToExclude = [], - array $languageLimitation = [] + private readonly QueryBuilder $queryBuilder, + private readonly int $maxResults = 6, + private readonly array $pagesToExclude = [], + private readonly array $languageLimitation = [] ) { - $this->queryBuilder = $queryBuilder; - $this->maxResults = $maxResults; - $this->pagesToExclude = $pagesToExclude; - $this->languageLimitation = $languageLimitation; } public function getItems(): array @@ -98,10 +78,13 @@ public function getItems(): array $this->queryBuilder->where(...$constraints); } - $items = $this->queryBuilder->execute()->fetchAll(); + $items = $this->queryBuilder->executeQuery()->fetchAllAssociative(); foreach ($items as $item) { - if (is_array($item) === false) { - continue; + if (is_string($item['url']) === false) { + throw new Exception('url of item was not string: ' . var_export($item['url'], true), 1707327319); + } + if (is_string($item['user_agent']) === false) { + throw new Exception('user_agent of item was not string: ' . var_export($item['user_agent'], true), 1707327344); } $preparedItems[] = sprintf( diff --git a/Classes/Dashboard/Provider/PageviewsPerDay.php b/Classes/Dashboard/Provider/PageviewsPerDay.php index 1a71837..3273670 100644 --- a/Classes/Dashboard/Provider/PageviewsPerDay.php +++ b/Classes/Dashboard/Provider/PageviewsPerDay.php @@ -24,6 +24,7 @@ namespace DanielSiepmann\Tracking\Dashboard\Provider; use DanielSiepmann\Tracking\Extension; +use Doctrine\DBAL\Platforms\SqlitePlatform; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Localization\LanguageService; @@ -32,49 +33,20 @@ class PageviewsPerDay implements ChartDataProviderInterface { - /** - * @var LanguageService - */ - private $languageService; - - /** - * @var QueryBuilder - */ - private $queryBuilder; - - /** - * @var int - */ - private $days; + private LanguageService $languageService; /** - * @var array + * @param int[] $pagesToExclude + * @param int[] $languageLimitation */ - private $pagesToExclude; - - /** - * @var string - */ - private $dateFormat; - - /** - * @var array - */ - private $languageLimitation; - public function __construct( - QueryBuilder $queryBuilder, - int $days = 31, - array $pagesToExclude = [], - array $languageLimitation = [], - string $dateFormat = 'Y-m-d' + private readonly QueryBuilder $queryBuilder, + private readonly int $days = 31, + private readonly array $pagesToExclude = [], + private readonly array $languageLimitation = [], + private readonly string $dateFormat = 'Y-m-d' ) { $this->languageService = $GLOBALS['LANG']; - $this->queryBuilder = $queryBuilder; - $this->days = $days; - $this->pagesToExclude = $pagesToExclude; - $this->languageLimitation = $languageLimitation; - $this->dateFormat = $dateFormat; } public function getChartData(): array @@ -102,16 +74,16 @@ private function calculateData(): array $data = []; for ($daysBefore = $this->days; $daysBefore >= 0; $daysBefore--) { - $label = date($this->dateFormat, (int)strtotime('-' . $daysBefore . ' day')); + $label = date($this->dateFormat, (int) strtotime('-' . $daysBefore . ' day')); $labels[$label] = $label; $data[$label] = 0; } - $start = (int)strtotime('-' . $this->days . ' day 0:00:00'); - $end = (int)strtotime('tomorrow midnight'); + $start = (int) strtotime('-' . $this->days . ' day 0:00:00'); + $end = (int) strtotime('tomorrow midnight'); foreach ($this->getPageviewsInPeriod($start, $end) as $day) { - $data[$day['label']] = (int)$day['count']; + $data[$day['label']] = (int) $day['count']; } return [ @@ -154,13 +126,15 @@ private function getPageviewsInPeriod(int $start, int $end): array ->groupBy('label') ->orderBy('label', 'ASC') ; - - if ($this->queryBuilder->getConnection()->getDatabasePlatform()->getName() === 'sqlite') { + if ( + (class_exists(SqlitePlatform::class) && $this->queryBuilder->getConnection()->getDatabasePlatform() instanceof SqlitePlatform) + || (method_exists($this->queryBuilder->getConnection()->getDatabasePlatform(), 'getName') && $this->queryBuilder->getConnection()->getDatabasePlatform()->getName() === 'sqlite') + ) { $this->queryBuilder->addSelectLiteral('date(crdate, "unixepoch") as "label"'); } else { $this->queryBuilder->addSelectLiteral('FROM_UNIXTIME(crdate, "%Y-%m-%d") as "label"'); } - return $this->queryBuilder->execute()->fetchAll(); + return $this->queryBuilder->executeQuery()->fetchAllAssociative(); } } diff --git a/Classes/Dashboard/Provider/PageviewsPerOperatingSystem.php b/Classes/Dashboard/Provider/PageviewsPerOperatingSystem.php index 54ab8d4..6c27a8c 100644 --- a/Classes/Dashboard/Provider/PageviewsPerOperatingSystem.php +++ b/Classes/Dashboard/Provider/PageviewsPerOperatingSystem.php @@ -23,6 +23,7 @@ namespace DanielSiepmann\Tracking\Dashboard\Provider; +use Exception; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Dashboard\WidgetApi; @@ -31,35 +32,14 @@ class PageviewsPerOperatingSystem implements ChartDataProviderInterface { /** - * @var QueryBuilder + * @param int[] $languageLimitation */ - private $queryBuilder; - - /** - * @var int - */ - private $days; - - /** - * @var int - */ - private $maxResults; - - /** - * @var array - */ - private $languageLimitation; - public function __construct( - QueryBuilder $queryBuilder, - int $days = 31, - int $maxResults = 6, - array $languageLimitation = [] + private readonly QueryBuilder $queryBuilder, + private readonly int $days = 31, + private readonly int $maxResults = 6, + private readonly array $languageLimitation = [] ) { - $this->queryBuilder = $queryBuilder; - $this->days = $days; - $this->maxResults = $maxResults; - $this->languageLimitation = $languageLimitation; } public function getChartData(): array @@ -112,13 +92,13 @@ private function getPageViewsPerPage(): array ->orderBy('total', 'desc') ->addOrderBy('operating_system', 'asc') ->setMaxResults($this->maxResults) - ->execute() - ->fetchAll() + ->executeQuery() + ->fetchAllAssociative() ; foreach ($result as $row) { - if (is_array($row) === false) { - continue; + if (is_string($row['operating_system']) === false) { + throw new Exception('operating_system of row was not string: ' . var_export($row['operating_system'], true), 1707326866); } $labels[] = mb_strimwidth($row['operating_system'], 0, 50, '…'); diff --git a/Classes/Dashboard/Provider/PageviewsPerPage.php b/Classes/Dashboard/Provider/PageviewsPerPage.php index 723c95e..dbdfb77 100644 --- a/Classes/Dashboard/Provider/PageviewsPerPage.php +++ b/Classes/Dashboard/Provider/PageviewsPerPage.php @@ -23,6 +23,7 @@ namespace DanielSiepmann\Tracking\Dashboard\Provider; +use Exception; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\Query\QueryBuilder; @@ -33,49 +34,17 @@ class PageviewsPerPage implements ChartDataProviderInterface { /** - * @var QueryBuilder + * @param int[] $pagesToExclude + * @param int[] $languageLimitation */ - private $queryBuilder; - - /** - * @var PageRepository - */ - private $pageRepository; - - /** - * @var int - */ - private $days; - - /** - * @var int - */ - private $maxResults; - - /** - * @var array - */ - private $pagesToExclude; - - /** - * @var array - */ - private $languageLimitation; - public function __construct( - QueryBuilder $queryBuilder, - PageRepository $pageRepository, - int $days = 31, - int $maxResults = 6, - array $pagesToExclude = [], - array $languageLimitation = [] + private readonly QueryBuilder $queryBuilder, + private readonly PageRepository $pageRepository, + private readonly int $days = 31, + private readonly int $maxResults = 6, + private readonly array $pagesToExclude = [], + private readonly array $languageLimitation = [] ) { - $this->queryBuilder = $queryBuilder; - $this->pageRepository = $pageRepository; - $this->days = $days; - $this->maxResults = $maxResults; - $this->pagesToExclude = $pagesToExclude; - $this->languageLimitation = $languageLimitation; } public function getChartData(): array @@ -136,16 +105,16 @@ private function getPageviewsPerPage(): array ->orderBy('total', 'desc') ->addOrderBy('latest', 'desc') ->setMaxResults($this->maxResults) - ->execute() - ->fetchAll() + ->executeQuery() + ->fetchAllAssociative() ; foreach ($result as $row) { - if (is_array($row) === false) { - continue; + if (is_numeric($row['pid']) === false) { + throw new Exception('PID of row was not numeric: ' . var_export($row['pid'], true), 1707326783); } - $labels[] = $this->getRecordTitle((int)$row['pid']); + $labels[] = $this->getRecordTitle((int) $row['pid']); $data[] = $row['total']; } @@ -159,13 +128,16 @@ private function getRecordTitle(int $uid): string { $record = BackendUtility::getRecord('pages', $uid); if (count($this->languageLimitation) === 1 && $record !== null) { - $record = $this->pageRepository->getRecordOverlay('pages', $record, $this->languageLimitation[0]); + $record = $this->pageRepository->getPageOverlay( + $record, + $this->languageLimitation[0] + ); } if (is_array($record) === false) { return 'Unkown'; } - return strip_tags(BackendUtility::getRecordTitle('pages', $record, true)); + return strip_tags((string) BackendUtility::getRecordTitle('pages', $record, true)); } } diff --git a/Classes/Dashboard/Provider/Recordviews.php b/Classes/Dashboard/Provider/Recordviews.php index c6bd398..35c8857 100644 --- a/Classes/Dashboard/Provider/Recordviews.php +++ b/Classes/Dashboard/Provider/Recordviews.php @@ -23,9 +23,10 @@ namespace DanielSiepmann\Tracking\Dashboard\Provider; +use DanielSiepmann\Tracking\LanguageAspectFactory; +use Exception; use Generator; use TYPO3\CMS\Backend\Utility\BackendUtility; -use TYPO3\CMS\Core\Context\LanguageAspect; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Domain\Repository\PageRepository; @@ -35,63 +36,20 @@ class Recordviews implements ChartDataProviderInterface { /** - * @var PageRepository + * @param int[] $pagesToExclude + * @param int[] $languageLimitation */ - private $pageRepository; - - /** - * @var QueryBuilder - */ - private $queryBuilder; - - /** - * @var int - */ - private $days; - - /** - * @var int - */ - private $maxResults; - - /** - * @var array - */ - private $pagesToExclude; - - /** - * @var array - */ - private $languageLimitation; - - /** - * @var array - */ - private $recordTableLimitation; - - /** - * @var array - */ - private $recordTypeLimitation; - public function __construct( - PageRepository $pageRepository, - QueryBuilder $queryBuilder, - int $days = 31, - int $maxResults = 6, - array $pagesToExclude = [], - array $languageLimitation = [], - array $recordTableLimitation = [], - array $recordTypeLimitation = [] + private readonly PageRepository $pageRepository, + private readonly QueryBuilder $queryBuilder, + private readonly LanguageAspectFactory $languageAspectFactory, + private readonly int $days = 31, + private readonly int $maxResults = 6, + private readonly array $pagesToExclude = [], + private readonly array $languageLimitation = [], + private readonly array $recordTableLimitation = [], + private readonly array $recordTypeLimitation = [] ) { - $this->pageRepository = $pageRepository; - $this->queryBuilder = $queryBuilder; - $this->days = $days; - $this->pagesToExclude = $pagesToExclude; - $this->languageLimitation = $languageLimitation; - $this->maxResults = $maxResults; - $this->recordTableLimitation = $recordTableLimitation; - $this->recordTypeLimitation = $recordTypeLimitation; } public function getChartData(): array @@ -118,8 +76,13 @@ private function getRecordviews(): array if (is_numeric($recordview['record_uid']) === false) { continue; } + + if (is_string($recordview['record_table_name']) === false) { + throw new Exception('record_table_name of recordview was not string: ' . var_export($recordview['record_table_name'], true), 1707327404); + } + $record = $this->getRecord( - (int)$recordview['record_uid'], + (int) $recordview['record_uid'], $recordview['record_table_name'] ); @@ -133,7 +96,7 @@ private function getRecordviews(): array continue; } - $labels[] = mb_strimwidth($record['title'], 0, 25, '…'); + $labels[] = mb_strimwidth((string) $record['title'], 0, 25, '…'); $data[] = $recordview['total']; } @@ -143,6 +106,9 @@ private function getRecordviews(): array ]; } + /** + * @return Generator + */ private function getRecordviewsRecords(): Generator { $constraints = [ @@ -194,10 +160,10 @@ private function getRecordviewsRecords(): Generator ->orderBy('total', 'desc') ->addOrderBy('latest', 'desc') ->setMaxResults($this->maxResults) - ->execute() + ->executeQuery() ; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { yield $row; } } @@ -210,10 +176,10 @@ private function getRecord( $record = BackendUtility::getRecord($table, $uid); if (count($this->languageLimitation) === 1 && $record !== null) { - $record = $this->pageRepository->getRecordOverlay( + $record = $this->pageRepository->getLanguageOverlay( $table, $record, - $this->createLanguageAspect($this->languageLimitation[0]) + $this->languageAspectFactory->createFromLanguageUid($this->languageLimitation[0]) ); } @@ -222,17 +188,8 @@ private function getRecord( } return [ - 'title' => strip_tags(BackendUtility::getRecordTitle($table, $record, true)), + 'title' => strip_tags((string) BackendUtility::getRecordTitle($table, $record, true)), 'type' => $record[$recordTypeField] ?? '', ]; } - - private function createLanguageAspect(int $languageUid): LanguageAspect - { - return new LanguageAspect( - $languageUid, - null, - LanguageAspect::OVERLAYS_MIXED - ); - } } diff --git a/Classes/Domain/ExpressionLanguage/SymfonyExpressionLanguage.php b/Classes/Domain/ExpressionLanguage/SymfonyExpressionLanguage.php index f30cf06..eb90340 100644 --- a/Classes/Domain/ExpressionLanguage/SymfonyExpressionLanguage.php +++ b/Classes/Domain/ExpressionLanguage/SymfonyExpressionLanguage.php @@ -61,7 +61,7 @@ static function ($arguments, $array, $path) { } try { return ArrayUtility::getValueByPath($array, $path); - } catch (MissingArrayPathException $e) { + } catch (MissingArrayPathException) { return ''; } } diff --git a/Classes/Domain/Model/Expression.php b/Classes/Domain/Model/Expression.php index 2766e4f..5926b62 100644 --- a/Classes/Domain/Model/Expression.php +++ b/Classes/Domain/Model/Expression.php @@ -25,8 +25,5 @@ interface Expression { - /** - * @return mixed - */ - public function evaluate(); + public function evaluate(): mixed; } diff --git a/Classes/Domain/Model/Pageview.php b/Classes/Domain/Model/Pageview.php index eef5058..cfd3917 100644 --- a/Classes/Domain/Model/Pageview.php +++ b/Classes/Domain/Model/Pageview.php @@ -28,57 +28,15 @@ class Pageview implements HasUserAgent { - /** - * @var int - */ - private $uid = 0; - - /** - * @var int - */ - private $pageUid; - - /** - * @var SiteLanguage - */ - private $language; - - /** - * @var DateTimeImmutable - */ - private $crdate; - - /** - * @var int - */ - private $pageType; - - /** - * @var string - */ - private $url; - - /** - * @var string - */ - private $userAgent; - public function __construct( - int $pageUid, - SiteLanguage $language, - DateTimeImmutable $crdate, - int $pageType, - string $url, - string $userAgent, - int $uid = 0 + private readonly int $pageUid, + private readonly SiteLanguage $language, + private readonly DateTimeImmutable $crdate, + private readonly int $pageType, + private readonly string $url, + private readonly string $userAgent, + private readonly int $uid = 0 ) { - $this->uid = $uid; - $this->pageUid = $pageUid; - $this->language = $language; - $this->crdate = $crdate; - $this->pageType = $pageType; - $this->url = $url; - $this->userAgent = $userAgent; } public function getUid(): int diff --git a/Classes/Domain/Model/RecordRule.php b/Classes/Domain/Model/RecordRule.php index 3f64c31..0d7f6e9 100644 --- a/Classes/Domain/Model/RecordRule.php +++ b/Classes/Domain/Model/RecordRule.php @@ -25,29 +25,11 @@ class RecordRule { - /** - * @var string - */ - private $matches; - - /** - * @var string - */ - private $recordUid; - - /** - * @var string - */ - private $tableName; - public function __construct( - string $matches, - string $recordUid, - string $tableName + private readonly string $matches, + private readonly string $recordUid, + private readonly string $tableName ) { - $this->matches = $matches; - $this->recordUid = $recordUid; - $this->tableName = $tableName; } public static function fromArray(array $config): self diff --git a/Classes/Domain/Model/Recordview.php b/Classes/Domain/Model/Recordview.php index a89fdca..e5d7576 100644 --- a/Classes/Domain/Model/Recordview.php +++ b/Classes/Domain/Model/Recordview.php @@ -28,57 +28,15 @@ class Recordview implements HasUserAgent { - /** - * @var int - */ - private $pageUid; - - /** - * @var SiteLanguage - */ - private $language; - - /** - * @var DateTimeImmutable - */ - private $crdate; - - /** - * @var string - */ - private $url; - - /** - * @var string - */ - private $userAgent; - - /** - * @var int - */ - private $recordUid; - - /** - * @var string - */ - private $tableName; - public function __construct( - int $pageUid, - SiteLanguage $language, - DateTimeImmutable $crdate, - string $url, - string $userAgent, - int $recordUid, - string $tableName + private readonly int $pageUid, + private readonly SiteLanguage $language, + private readonly DateTimeImmutable $crdate, + private readonly string $url, + private readonly string $userAgent, + private readonly int $recordUid, + private readonly string $tableName ) { - $this->pageUid = $pageUid; - $this->language = $language; - $this->crdate = $crdate; - $this->url = $url; - $this->userAgent = $userAgent; - $this->recordUid = $recordUid; - $this->tableName = $tableName; } public function getPageUid(): int diff --git a/Classes/Domain/Model/SymfonyExpression.php b/Classes/Domain/Model/SymfonyExpression.php index a659902..a0bdb43 100644 --- a/Classes/Domain/Model/SymfonyExpression.php +++ b/Classes/Domain/Model/SymfonyExpression.php @@ -27,32 +27,14 @@ class SymfonyExpression implements Expression { - /** - * @var string - */ - private $expression; - - /** - * @var array - */ - private $values; - - /** - * @var ExpressionLanguage - */ - private $symfonyExpression; - public function __construct( - string $expression, - array $values, - ExpressionLanguage $symfonyExpression + private readonly string $expression, + private readonly array $values, + private readonly ExpressionLanguage $symfonyExpression ) { - $this->expression = $expression; - $this->values = $values; - $this->symfonyExpression = $symfonyExpression; } - public function evaluate() + public function evaluate(): mixed { return $this->symfonyExpression->evaluate( $this->expression, diff --git a/Classes/Domain/Pageview/Factory.php b/Classes/Domain/Pageview/Factory.php index 4dd7b1e..a50f43a 100644 --- a/Classes/Domain/Pageview/Factory.php +++ b/Classes/Domain/Pageview/Factory.php @@ -33,14 +33,9 @@ class Factory { - /** - * @var SiteFinder - */ - private $siteFinder; - - public function __construct(SiteFinder $siteFinder) - { - $this->siteFinder = $siteFinder; + public function __construct( + private readonly SiteFinder $siteFinder + ) { } public function fromRequest(ServerRequestInterface $request): Pageview @@ -49,8 +44,8 @@ public function fromRequest(ServerRequestInterface $request): Pageview $this->getRouting($request)->getPageId(), $this->getLanguage($request), new DateTimeImmutable(), - (int)$this->getRouting($request)->getPageType(), - (string)$request->getUri(), + (int) $this->getRouting($request)->getPageType(), + (string) $request->getUri(), $request->getHeader('User-Agent')[0] ?? '' ); } @@ -58,13 +53,13 @@ public function fromRequest(ServerRequestInterface $request): Pageview public function fromDbRow(array $dbRow): Pageview { return new Pageview( - (int)$dbRow['pid'], - $this->siteFinder->getSiteByPageId((int)$dbRow['pid'])->getLanguageById((int)$dbRow['sys_language_uid']), + (int) $dbRow['pid'], + $this->siteFinder->getSiteByPageId((int) $dbRow['pid'])->getLanguageById((int) $dbRow['sys_language_uid']), new DateTimeImmutable('@' . $dbRow['crdate']), - (int)$dbRow['type'], + (int) $dbRow['type'], $dbRow['url'], $dbRow['user_agent'], - (int)$dbRow['uid'] + (int) $dbRow['uid'] ); } diff --git a/Classes/Domain/Recordview/Factory.php b/Classes/Domain/Recordview/Factory.php index a2b5c75..989cd6c 100644 --- a/Classes/Domain/Recordview/Factory.php +++ b/Classes/Domain/Recordview/Factory.php @@ -34,15 +34,9 @@ class Factory { - /** - * @var ExpressionFactory - */ - private $expressionFactory; - public function __construct( - ExpressionFactory $expressionFactory + private readonly ExpressionFactory $expressionFactory ) { - $this->expressionFactory = $expressionFactory; } public function fromRequest( @@ -69,9 +63,9 @@ public function fromRequest( self::getRouting($request)->getPageId(), self::getLanguage($request), new DateTimeImmutable(), - (string)$request->getUri(), + (string) $request->getUri(), $request->getHeader('User-Agent')[0] ?? '', - (int)$recordUid, + (int) $recordUid, $rule->getTableName() ); } diff --git a/Classes/Domain/Repository/Pageview.php b/Classes/Domain/Repository/Pageview.php index 75c8104..341bb4e 100644 --- a/Classes/Domain/Repository/Pageview.php +++ b/Classes/Domain/Repository/Pageview.php @@ -31,22 +31,10 @@ class Pageview { - /** - * @var Connection - */ - private $connection; - - /** - * @var Factory - */ - private $factory; - public function __construct( - Connection $connection, - Factory $factory + private readonly Connection $connection, + private readonly Factory $factory ) { - $this->connection = $connection; - $this->factory = $factory; } public function countAll(): int @@ -54,27 +42,26 @@ public function countAll(): int $result = $this->connection->createQueryBuilder() ->count('uid') ->from('tx_tracking_pageview') - ->execute() + ->executeQuery() ->fetchOne() ; if (is_numeric($result)) { - return (int)$result; + return (int) $result; } return 0; } + /** + * @return Generator + */ public function findAll(): Generator { $queryBuilder = $this->connection->createQueryBuilder(); - $pageViews = $queryBuilder->select('*')->from('tx_tracking_pageview')->execute(); - - while ($pageView = $pageViews->fetch()) { - if (is_array($pageView) === false) { - continue; - } + $pageViews = $queryBuilder->select('*')->from('tx_tracking_pageview')->executeQuery(); + while ($pageView = $pageViews->fetchAssociative()) { yield $this->factory->fromDbRow($pageView); } } diff --git a/Classes/Domain/Repository/Recordview.php b/Classes/Domain/Repository/Recordview.php index 0849dd8..7cff637 100644 --- a/Classes/Domain/Repository/Recordview.php +++ b/Classes/Domain/Repository/Recordview.php @@ -28,15 +28,9 @@ class Recordview { - /** - * @var Connection - */ - private $connection; - public function __construct( - Connection $connection + private readonly Connection $connection ) { - $this->connection = $connection; } public function add(Model $recordview): void diff --git a/Classes/Hooks/DataHandler.php b/Classes/Hooks/DataHandler.php index 92d4386..5a4aa23 100644 --- a/Classes/Hooks/DataHandler.php +++ b/Classes/Hooks/DataHandler.php @@ -55,9 +55,10 @@ private function preventCopyOfTrackingTables(Typo3DataHandler $dataHandler): voi $copyWhichTables = GeneralUtility::trimExplode(',', $dataHandler->copyWhichTables, true); } - $copyWhichTables = array_filter($copyWhichTables, static function (string $tableName) { - return \str_starts_with($tableName, 'tx_tracking_') === false; - }); + $copyWhichTables = array_filter( + $copyWhichTables, + static fn (int|string $tableName): bool => \str_starts_with((string) $tableName, 'tx_tracking_') === false + ); $dataHandler->copyWhichTables = implode(',', $copyWhichTables); } diff --git a/Classes/LanguageAspectFactory.php b/Classes/LanguageAspectFactory.php new file mode 100644 index 0000000..5e32ff5 --- /dev/null +++ b/Classes/LanguageAspectFactory.php @@ -0,0 +1,38 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +namespace DanielSiepmann\Tracking; + +use TYPO3\CMS\Core\Context\LanguageAspect; + +class LanguageAspectFactory +{ + public function createFromLanguageUid(int $languageUid): LanguageAspect + { + return new LanguageAspect( + $languageUid, + null, + LanguageAspect::OVERLAYS_MIXED + ); + } +} diff --git a/Classes/Middleware/Pageview.php b/Classes/Middleware/Pageview.php index 3eae658..23a9343 100644 --- a/Classes/Middleware/Pageview.php +++ b/Classes/Middleware/Pageview.php @@ -34,43 +34,13 @@ class Pageview implements MiddlewareInterface { - /** - * @var Repository - */ - private $repository; - - /** - * @var Context - */ - private $context; - - /** - * @var Factory - */ - private $factory; - - /** - * @var ExpressionFactory - */ - private $expressionFactory; - - /** - * @var string - */ - private $rule = ''; - public function __construct( - Repository $repository, - Context $context, - Factory $factory, - ExpressionFactory $expressionFactory, - string $rule + private readonly Repository $repository, + private readonly Context $context, + private readonly Factory $factory, + private readonly ExpressionFactory $expressionFactory, + private readonly string $rule ) { - $this->repository = $repository; - $this->context = $context; - $this->factory = $factory; - $this->expressionFactory = $expressionFactory; - $this->rule = $rule; } public function process( @@ -88,7 +58,7 @@ private function shouldTrack( ServerRequestInterface $request, Context $context ): bool { - return (bool)$this->expressionFactory->create( + return (bool) $this->expressionFactory->create( $this->rule, [ 'request' => $request, diff --git a/Classes/Middleware/Recordview.php b/Classes/Middleware/Recordview.php index 8427790..27f5a23 100644 --- a/Classes/Middleware/Recordview.php +++ b/Classes/Middleware/Recordview.php @@ -35,43 +35,18 @@ class Recordview implements MiddlewareInterface { - /** - * @var Repository - */ - private $repository; - - /** - * @var Context - */ - private $context; - - /** - * @var Factory - */ - private $factory; - - /** - * @var ExpressionFactory - */ - private $expressionFactory; - /** * @var array */ - private $rules = []; + private array $rules = []; public function __construct( - Repository $repository, - Context $context, - Factory $factory, - ExpressionFactory $expressionFactory, + private readonly Repository $repository, + private readonly Context $context, + private readonly Factory $factory, + private readonly ExpressionFactory $expressionFactory, array $rules ) { - $this->repository = $repository; - $this->context = $context; - $this->factory = $factory; - $this->expressionFactory = $expressionFactory; - $this->rules = RecordRule::multipleFromArray($rules); } @@ -93,7 +68,7 @@ private function shouldTrack( Context $context, RecordRule $rule ): bool { - return (bool)$this->expressionFactory->create( + return (bool) $this->expressionFactory->create( $rule->getMatchesExpression(), [ 'request' => $request, diff --git a/Configuration/Backend/DashboardWidgetGroups.php b/Configuration/Backend/DashboardWidgetGroups.php index a583646..af42f5b 100644 --- a/Configuration/Backend/DashboardWidgetGroups.php +++ b/Configuration/Backend/DashboardWidgetGroups.php @@ -1,5 +1,7 @@ [ 'title' => 'LLL:EXT:tracking/Resources/Private/Language/locallang.xlf:dashboard.widget.group.tracking', diff --git a/Configuration/Backend/DashboardWidgets.yaml b/Configuration/Backend/DashboardWidgets.yaml index 7fa7a7d..aad5363 100644 --- a/Configuration/Backend/DashboardWidgets.yaml +++ b/Configuration/Backend/DashboardWidgets.yaml @@ -14,7 +14,6 @@ services: dashboard.widget.danielsiepmann.tracking.pageViewsPerDay: class: 'TYPO3\CMS\Dashboard\Widgets\BarChartWidget' arguments: - $view: '@dashboard.views.widget' $dataProvider: '@DanielSiepmann\Tracking\Dashboard\Provider\PageviewsPerDay' tags: - name: 'dashboard.widget' @@ -34,7 +33,6 @@ services: dashboard.widget.danielsiepmann.tracking.pageViewsPerPage: class: 'TYPO3\CMS\Dashboard\Widgets\DoughnutChartWidget' arguments: - $view: '@dashboard.views.widget' $dataProvider: '@DanielSiepmann\Tracking\Dashboard\Provider\PageviewsPerPage' tags: - name: 'dashboard.widget' @@ -54,7 +52,6 @@ services: dashboard.widget.danielsiepmann.tracking.newestPageviews: class: 'TYPO3\CMS\Dashboard\Widgets\ListWidget' arguments: - $view: '@dashboard.views.widget' $dataProvider: '@DanielSiepmann\Tracking\Dashboard\Provider\NewestPageviews' tags: - name: 'dashboard.widget' @@ -74,7 +71,6 @@ services: dashboard.widget.danielsiepmann.tracking.operatingSystems: class: 'TYPO3\CMS\Dashboard\Widgets\DoughnutChartWidget' arguments: - $view: '@dashboard.views.widget' $dataProvider: '@DanielSiepmann\Tracking\Dashboard\Provider\PageviewsPerOperatingSystem' tags: - name: 'dashboard.widget' diff --git a/Configuration/RequestMiddlewares.php b/Configuration/RequestMiddlewares.php index 15dd5ef..24f8958 100644 --- a/Configuration/RequestMiddlewares.php +++ b/Configuration/RequestMiddlewares.php @@ -1,5 +1,7 @@ [ 'label' => 'url', 'label_alt' => 'crdate', @@ -69,16 +71,3 @@ ], ], ]; - -if ((new \TYPO3\CMS\Core\Information\Typo3Version())->getMajorVersion() < 12) { - $tca['ctrl']['cruser_id'] = 'cruser_id'; - - $tca['columns']['crdate']['config']['type'] = 'input'; - $tca['columns']['crdate']['config']['renderType'] = 'inputDateTime'; - $tca['columns']['crdate']['config']['eval'] = 'datetime'; - - $tca['columns']['type']['config']['type'] = 'input'; - $tca['columns']['type']['config']['eval'] = 'int'; -} - -return $tca; diff --git a/Configuration/TCA/tx_tracking_recordview.php b/Configuration/TCA/tx_tracking_recordview.php index feca156..0773949 100644 --- a/Configuration/TCA/tx_tracking_recordview.php +++ b/Configuration/TCA/tx_tracking_recordview.php @@ -1,6 +1,8 @@ [ 'label' => 'record', 'label_alt' => 'crdate', @@ -72,13 +74,3 @@ ], ], ]; - -if ((new \TYPO3\CMS\Core\Information\Typo3Version())->getMajorVersion() < 12) { - $tca['ctrl']['cruser_id'] = 'cruser_id'; - - $tca['columns']['crdate']['config']['type'] = 'input'; - $tca['columns']['crdate']['config']['renderType'] = 'inputDateTime'; - $tca['columns']['crdate']['config']['eval'] = 'datetime'; -} - -return $tca; diff --git a/Tests/Functional/AbstractFunctionalTest.php b/Tests/Functional/AbstractFunctionalTestCase.php similarity index 75% rename from Tests/Functional/AbstractFunctionalTest.php rename to Tests/Functional/AbstractFunctionalTestCase.php index 7677227..3141796 100644 --- a/Tests/Functional/AbstractFunctionalTest.php +++ b/Tests/Functional/AbstractFunctionalTestCase.php @@ -21,21 +21,16 @@ * 02110-1301, USA. */ -namespace DanielSiepmann\Tests\Functional; +namespace DanielSiepmann\Tracking\Tests\Functional; use Codappix\Typo3PhpDatasets\TestingFramework; -use DanielSiepmann\AbstractFunctional; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -abstract class AbstractFunctionalTest extends FunctionalTestCase +abstract class AbstractFunctionalTestCase extends FunctionalTestCase { use TestingFramework; - protected array $testExtensionsToLoad = [ - 'danielsiepmann/tracking', - ]; + protected array $testExtensionsToLoad = ['danielsiepmann/tracking']; - protected array $coreExtensionsToLoad = [ - 'typo3/cms-dashboard', - ]; + protected array $coreExtensionsToLoad = ['typo3/cms-dashboard']; } diff --git a/Tests/Functional/Command/UpdateDataCommandTest.php b/Tests/Functional/Command/UpdateDataCommandTest.php index 50345a5..06cc6c9 100644 --- a/Tests/Functional/Command/UpdateDataCommandTest.php +++ b/Tests/Functional/Command/UpdateDataCommandTest.php @@ -1,5 +1,7 @@ 'typo3conf/sites', ]; - /** - * @test - */ + #[Test] public function updatesAllEntriesWithMissingOperatingSystem(): void { $this->importPHPDataSet(__DIR__ . '/../Fixtures/UpdateDataCommandTest/PageviewsWithMissingOperatingSystem.php'); @@ -61,9 +54,7 @@ public function updatesAllEntriesWithMissingOperatingSystem(): void self::assertSame('Android', $records[1]['operating_system']); } - /** - * @test - */ + #[Test] public function doesNotChangeExistingOperatingSystem(): void { $this->importPHPDataSet(__DIR__ . '/../Fixtures/UpdateDataCommandTest/PageviewsWithOperatingSystem.php'); @@ -80,9 +71,7 @@ public function doesNotChangeExistingOperatingSystem(): void self::assertSame('Android', $records[1]['operating_system']); } - /** - * @test - */ + #[Test] public function doesNothingIfNoRecordExists(): void { $this->importPHPDataSet(__DIR__ . '/../Fixtures/Pages.php'); diff --git a/Tests/Functional/Dashboard/Provider/NewestPageviewsTest.php b/Tests/Functional/Dashboard/Provider/NewestPageviewsTest.php index e88bd72..8729ebe 100644 --- a/Tests/Functional/Dashboard/Provider/NewestPageviewsTest.php +++ b/Tests/Functional/Dashboard/Provider/NewestPageviewsTest.php @@ -1,5 +1,7 @@ getConnectionPool()->getConnectionForTable('tx_tracking_pageview'); @@ -64,9 +60,7 @@ public function returnsRecentSixPageviews(): void ], $subject->getItems()); } - /** - * @test - */ + #[Test] public function respectsMaxResults(): void { $connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview'); @@ -90,9 +84,7 @@ public function respectsMaxResults(): void ], $subject->getItems()); } - /** - * @test - */ + #[Test] public function respectsPagesToExclude(): void { $connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview'); @@ -121,9 +113,7 @@ public function respectsPagesToExclude(): void ], $subject->getItems()); } - /** - * @test - */ + #[Test] public function respectsLimitToLanguages(): void { $connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview'); diff --git a/Tests/Functional/Dashboard/Provider/PageviewsPerDayTest.php b/Tests/Functional/Dashboard/Provider/PageviewsPerDayTest.php index 2336757..fa59762 100644 --- a/Tests/Functional/Dashboard/Provider/PageviewsPerDayTest.php +++ b/Tests/Functional/Dashboard/Provider/PageviewsPerDayTest.php @@ -1,5 +1,7 @@ getContainer()->get(LanguageServiceFactory::class)->create('default'); + $GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->create('default'); } protected function tearDown(): void @@ -51,9 +46,7 @@ protected function tearDown(): void parent::tearDown(); } - /** - * @test - */ + #[Test] public function listsResultsForLast31DaysByDefault(): void { $connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview'); @@ -73,9 +66,7 @@ public function listsResultsForLast31DaysByDefault(): void self::assertCount(32, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectedNumberOfDays(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php'); @@ -102,9 +93,7 @@ public function respectedNumberOfDays(): void ], $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectedExcludedPages(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php'); @@ -132,9 +121,7 @@ public function respectedExcludedPages(): void ], $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectedDateFormat(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php'); @@ -156,9 +143,7 @@ public function respectedDateFormat(): void self::assertCount(2, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectsLimitToLanguages(): void { $connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_pageview'); diff --git a/Tests/Functional/Dashboard/Provider/PageviewsPerOperatingSystemTest.php b/Tests/Functional/Dashboard/Provider/PageviewsPerOperatingSystemTest.php index 334ba9f..a9e60ae 100644 --- a/Tests/Functional/Dashboard/Provider/PageviewsPerOperatingSystemTest.php +++ b/Tests/Functional/Dashboard/Provider/PageviewsPerOperatingSystemTest.php @@ -1,5 +1,7 @@ getConnectionPool()->getConnectionForTable('tx_tracking_pageview'); @@ -68,9 +61,7 @@ public function listsSixResultsForLast31DaysByDefault(): void self::assertCount(6, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectedOrdering(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php'); @@ -109,9 +100,7 @@ public function respectedOrdering(): void self::assertCount(3, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectedNumberOfDays(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php'); @@ -145,9 +134,7 @@ public function respectedNumberOfDays(): void self::assertCount(2, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectedMaxResults(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php'); @@ -176,9 +163,7 @@ public function respectedMaxResults(): void self::assertCount(4, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectsLimitToLanguages(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php'); diff --git a/Tests/Functional/Dashboard/Provider/PageviewsPerPageTest.php b/Tests/Functional/Dashboard/Provider/PageviewsPerPageTest.php index b1f44fb..6b9058d 100644 --- a/Tests/Functional/Dashboard/Provider/PageviewsPerPageTest.php +++ b/Tests/Functional/Dashboard/Provider/PageviewsPerPageTest.php @@ -1,5 +1,7 @@ getContainer()->get(LanguageServiceFactory::class)->create('default'); + $this->importPHPDataSet(__DIR__ . '/../../Fixtures/BackendUser.php'); + $GLOBALS['BE_USER'] = $this->setUpBackendUser(1); + $GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->create('default'); } protected function tearDown(): void { - unset($GLOBALS['LANG']); + unset( + $GLOBALS['BE_USER'], + $GLOBALS['LANG'] + ); parent::tearDown(); } - /** - * @test - */ + #[Test] public function listsSixResultsForLast31DaysByDefault(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php'); @@ -67,8 +64,8 @@ public function listsSixResultsForLast31DaysByDefault(): void } $subject = new PageviewsPerPage( - GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'), - GeneralUtility::makeInstance(PageRepository::class) + $this->get(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'), + $this->get(PageRepository::class) ); $result = $subject->getChartData(); @@ -83,9 +80,7 @@ public function listsSixResultsForLast31DaysByDefault(): void self::assertCount(6, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectedOrdering(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php'); @@ -108,8 +103,8 @@ public function respectedOrdering(): void ]); $subject = new PageviewsPerPage( - GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'), - GeneralUtility::makeInstance(PageRepository::class) + $this->get(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'), + $this->get(PageRepository::class) ); $result = $subject->getChartData(); @@ -121,9 +116,7 @@ public function respectedOrdering(): void self::assertCount(3, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectedNumberOfDays(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php'); @@ -142,8 +135,8 @@ public function respectedNumberOfDays(): void ]); $subject = new PageviewsPerPage( - GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'), - GeneralUtility::makeInstance(PageRepository::class), + $this->get(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'), + $this->get(PageRepository::class), 2 ); @@ -155,9 +148,7 @@ public function respectedNumberOfDays(): void self::assertCount(2, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectedMaxResults(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php'); @@ -170,8 +161,8 @@ public function respectedMaxResults(): void } $subject = new PageviewsPerPage( - GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'), - GeneralUtility::makeInstance(PageRepository::class), + $this->get(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'), + $this->get(PageRepository::class), 31, 4 ); @@ -186,9 +177,7 @@ public function respectedMaxResults(): void self::assertCount(4, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectedExcludedPages(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php'); @@ -201,8 +190,8 @@ public function respectedExcludedPages(): void } $subject = new PageviewsPerPage( - GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'), - GeneralUtility::makeInstance(PageRepository::class), + $this->get(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'), + $this->get(PageRepository::class), 31, 6, [1, 2, 3, 4, 5, 6] @@ -218,9 +207,7 @@ public function respectedExcludedPages(): void self::assertCount(4, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function localizedRecordTitlesIfLimitedToSingleLanguage(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php'); @@ -249,8 +236,8 @@ public function localizedRecordTitlesIfLimitedToSingleLanguage(): void ]); $subject = new PageviewsPerPage( - GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'), - GeneralUtility::makeInstance(PageRepository::class), + $this->get(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'), + $this->get(PageRepository::class), 31, 6, [], @@ -260,14 +247,12 @@ public function localizedRecordTitlesIfLimitedToSingleLanguage(): void $result = $subject->getChartData(); self::assertSame([ 'Page 2', - 'Page 1', + 'Seite 1', ], $result['labels']); self::assertCount(2, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function defaultLanguageTitleIsUsedIfMultipleLanguagesAreAllowed(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/Pages.php'); @@ -296,12 +281,12 @@ public function defaultLanguageTitleIsUsedIfMultipleLanguagesAreAllowed(): void ]); $subject = new PageviewsPerPage( - GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'), - GeneralUtility::makeInstance(PageRepository::class), + $this->get(ConnectionPool::class)->getQueryBuilderForTable('tx_tracking_pageview'), + $this->get(PageRepository::class), 31, 6, [], - [1, '0'] + [1, 0] ); $result = $subject->getChartData(); diff --git a/Tests/Functional/Dashboard/Provider/RecordviewsTest.php b/Tests/Functional/Dashboard/Provider/RecordviewsTest.php index 1d6b454..02002b1 100644 --- a/Tests/Functional/Dashboard/Provider/RecordviewsTest.php +++ b/Tests/Functional/Dashboard/Provider/RecordviewsTest.php @@ -1,5 +1,7 @@ getContainer()->get(LanguageServiceFactory::class)->create('default'); + $this->importPHPDataSet(__DIR__ . '/../../Fixtures/BackendUser.php'); + $GLOBALS['BE_USER'] = $this->setUpBackendUser(1); + $GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->create('default'); } protected function tearDown(): void { - unset($GLOBALS['LANG']); + unset( + $GLOBALS['BE_USER'], + $GLOBALS['LANG'] + ); parent::tearDown(); } - /** - * @test - */ + #[Test] public function listsSixResultsForLast31DaysByDefault(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/SysCategories.php'); @@ -68,8 +66,9 @@ public function listsSixResultsForLast31DaysByDefault(): void } $subject = new Recordviews( - GeneralUtility::makeInstance(PageRepository::class), - $this->getConnectionPool()->getQueryBuilderForTable('tx_tracking_recordview') + $this->get(PageRepository::class), + $this->getConnectionPool()->getQueryBuilderForTable('tx_tracking_recordview'), + new LanguageAspectFactory() ); $result = $subject->getChartData(); @@ -84,9 +83,7 @@ public function listsSixResultsForLast31DaysByDefault(): void self::assertCount(6, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectedOrdering(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/SysCategories.php'); @@ -117,8 +114,9 @@ public function respectedOrdering(): void ]); $subject = new Recordviews( - GeneralUtility::makeInstance(PageRepository::class), + $this->get(PageRepository::class), $this->getConnectionPool()->getQueryBuilderForTable('tx_tracking_recordview'), + new LanguageAspectFactory(), 2 ); @@ -131,9 +129,7 @@ public function respectedOrdering(): void self::assertCount(3, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectedNumberOfDays(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/SysCategories.php'); @@ -158,8 +154,9 @@ public function respectedNumberOfDays(): void ]); $subject = new Recordviews( - GeneralUtility::makeInstance(PageRepository::class), + $this->get(PageRepository::class), $this->getConnectionPool()->getQueryBuilderForTable('tx_tracking_recordview'), + new LanguageAspectFactory(), 2 ); @@ -171,9 +168,7 @@ public function respectedNumberOfDays(): void self::assertCount(2, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectedMaxResults(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/SysCategories.php'); @@ -188,8 +183,9 @@ public function respectedMaxResults(): void } $subject = new Recordviews( - GeneralUtility::makeInstance(PageRepository::class), + $this->get(PageRepository::class), $this->getConnectionPool()->getQueryBuilderForTable('tx_tracking_recordview'), + new LanguageAspectFactory(), 31, 2 ); @@ -202,9 +198,7 @@ public function respectedMaxResults(): void self::assertCount(2, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectedExcludedPages(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/SysCategories.php'); @@ -220,8 +214,9 @@ public function respectedExcludedPages(): void } $subject = new Recordviews( - GeneralUtility::makeInstance(PageRepository::class), + $this->get(PageRepository::class), $this->getConnectionPool()->getQueryBuilderForTable('tx_tracking_recordview'), + new LanguageAspectFactory(), 31, 6, [1, 2, 3, 4, 5] @@ -238,9 +233,7 @@ public function respectedExcludedPages(): void self::assertCount(5, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectLimitesTables(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/SysCategories.php'); @@ -261,8 +254,9 @@ public function respectLimitesTables(): void ]); $subject = new Recordviews( - GeneralUtility::makeInstance(PageRepository::class), + $this->get(PageRepository::class), $this->getConnectionPool()->getQueryBuilderForTable('tx_tracking_recordview'), + new LanguageAspectFactory(), 31, 6, [], @@ -279,9 +273,7 @@ public function respectLimitesTables(): void self::assertCount(3, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function respectsLimitedTypes(): void { $connection = $this->getConnectionPool()->getConnectionForTable('tx_tracking_recordview'); @@ -300,8 +292,9 @@ public function respectsLimitedTypes(): void } $subject = new Recordviews( - GeneralUtility::makeInstance(PageRepository::class), + $this->get(PageRepository::class), $this->getConnectionPool()->getQueryBuilderForTable('tx_tracking_recordview'), + new LanguageAspectFactory(), 31, 6, [], @@ -318,9 +311,7 @@ public function respectsLimitedTypes(): void self::assertCount(2, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function localizedRecordTitlesIfLimitedToSingleLanguage(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/SysCategories.php'); @@ -348,8 +339,9 @@ public function localizedRecordTitlesIfLimitedToSingleLanguage(): void ]); $subject = new Recordviews( - GeneralUtility::makeInstance(PageRepository::class), + $this->get(PageRepository::class), $this->getConnectionPool()->getQueryBuilderForTable('tx_tracking_recordview'), + new LanguageAspectFactory(), 31, 6, [], @@ -366,9 +358,7 @@ public function localizedRecordTitlesIfLimitedToSingleLanguage(): void self::assertCount(2, $result['datasets'][0]['data']); } - /** - * @test - */ + #[Test] public function defaultLanguageTitleIsUsedIfMultipleLanguagesAreAllowed(): void { $this->importPHPDataSet(__DIR__ . '/../../Fixtures/SysCategories.php'); @@ -396,8 +386,9 @@ public function defaultLanguageTitleIsUsedIfMultipleLanguagesAreAllowed(): void ]); $subject = new Recordviews( - GeneralUtility::makeInstance(PageRepository::class), + $this->get(PageRepository::class), $this->getConnectionPool()->getQueryBuilderForTable('tx_tracking_recordview'), + new LanguageAspectFactory(), 31, 6, [], diff --git a/Tests/Functional/Domain/Recordview/FactoryTest.php b/Tests/Functional/Domain/Recordview/FactoryTest.php index 9853086..b45a5e6 100644 --- a/Tests/Functional/Domain/Recordview/FactoryTest.php +++ b/Tests/Functional/Domain/Recordview/FactoryTest.php @@ -1,5 +1,7 @@ prophesize(RecordRule::class); - $rule->getUidExpression()->willReturn('request.getQueryParams()["category"]'); - $rule->getTableName()->willReturn('sys_category'); + $rule = $this->createStub(RecordRule::class); + $rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]'); + $rule->method('getTableName')->willReturn('sys_category'); - $routing = $this->prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn(''); - $request->getHeader('User-Agent')->willReturn([]); - $request->getQueryParams()->willReturn([ + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn(''); + $request->method('getHeader')->willReturn([]); + $request->method('getQueryParams')->willReturn([ 'category' => 10, ]); $subject = $this->get(Factory::class); - $result = $subject->fromRequest($request->reveal(), $rule->reveal()); + $result = $subject->fromRequest($request, $rule); self::assertInstanceOf(Recordview::class, $result); } - /** - * @test - */ + #[Test] public function returnedRecordviewContainsUserAgent(): void { - $rule = $this->prophesize(RecordRule::class); - $rule->getUidExpression()->willReturn('request.getQueryParams()["category"]'); - $rule->getTableName()->willReturn('sys_category'); + $rule = $this->createStub(RecordRule::class); + $rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]'); + $rule->method('getTableName')->willReturn('sys_category'); - $routing = $this->prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn(''); - $request->getHeader('User-Agent')->willReturn(['Some User Agent']); - $request->getQueryParams()->willReturn([ + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn(''); + $request->method('getHeader')->willReturn(['Some User Agent']); + $request->method('getQueryParams')->willReturn([ 'category' => 10, ]); $subject = $this->get(Factory::class); - $result = $subject->fromRequest($request->reveal(), $rule->reveal()); + $result = $subject->fromRequest($request, $rule); self::assertSame('Some User Agent', $result->getUserAgent()); } - /** - * @test - */ + #[Test] public function returnedRecordviewContainsUri(): void { - $rule = $this->prophesize(RecordRule::class); - $rule->getUidExpression()->willReturn('request.getQueryParams()["category"]'); - $rule->getTableName()->willReturn('sys_category'); + $rule = $this->createStub(RecordRule::class); + $rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]'); + $rule->method('getTableName')->willReturn('sys_category'); - $routing = $this->prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn('https://example.com'); - $request->getHeader('User-Agent')->willReturn(['']); - $request->getQueryParams()->willReturn([ + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn('https://example.com'); + $request->method('getHeader')->willReturn(['']); + $request->method('getQueryParams')->willReturn([ 'category' => 10, ]); $subject = $this->get(Factory::class); - $result = $subject->fromRequest($request->reveal(), $rule->reveal()); + $result = $subject->fromRequest($request, $rule); self::assertSame('https://example.com', $result->getUrl()); } - /** - * @test - */ + #[Test] public function returnedRecordviewContainsDateTime(): void { - $rule = $this->prophesize(RecordRule::class); - $rule->getUidExpression()->willReturn('request.getQueryParams()["category"]'); - $rule->getTableName()->willReturn('sys_category'); + $rule = $this->createStub(RecordRule::class); + $rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]'); + $rule->method('getTableName')->willReturn('sys_category'); - $routing = $this->prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn('https://example.com'); - $request->getHeader('User-Agent')->willReturn(['']); - $request->getQueryParams()->willReturn([ + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn('https://example.com'); + $request->method('getHeader')->willReturn(['']); + $request->method('getQueryParams')->willReturn([ 'category' => 10, ]); $subject = $this->get(Factory::class); - $result = $subject->fromRequest($request->reveal(), $rule->reveal()); + $result = $subject->fromRequest($request, $rule); self::assertInstanceOf(DateTimeImmutable::class, $result->getCrdate()); } - /** - * @test - */ + #[Test] public function returnedRecordviewContainsLanguage(): void { - $rule = $this->prophesize(RecordRule::class); - $rule->getUidExpression()->willReturn('request.getQueryParams()["category"]'); - $rule->getTableName()->willReturn('sys_category'); + $rule = $this->createStub(RecordRule::class); + $rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]'); + $rule->method('getTableName')->willReturn('sys_category'); - $routing = $this->prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn('https://example.com'); - $request->getHeader('User-Agent')->willReturn(['']); - $request->getQueryParams()->willReturn([ + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn('https://example.com'); + $request->method('getHeader')->willReturn(['']); + $request->method('getQueryParams')->willReturn([ 'category' => 10, ]); $subject = $this->get(Factory::class); - $result = $subject->fromRequest($request->reveal(), $rule->reveal()); - self::assertSame($language->reveal(), $result->getLanguage()); + $result = $subject->fromRequest($request, $rule); + self::assertSame($language, $result->getLanguage()); } - /** - * @test - */ + #[Test] public function returnedRecordviewContainsPageId(): void { - $rule = $this->prophesize(RecordRule::class); - $rule->getUidExpression()->willReturn('request.getQueryParams()["category"]'); - $rule->getTableName()->willReturn('sys_category'); + $rule = $this->createStub(RecordRule::class); + $rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]'); + $rule->method('getTableName')->willReturn('sys_category'); - $routing = $this->prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn('https://example.com'); - $request->getHeader('User-Agent')->willReturn(['']); - $request->getQueryParams()->willReturn([ + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn('https://example.com'); + $request->method('getHeader')->willReturn(['']); + $request->method('getQueryParams')->willReturn([ 'category' => 10, ]); $subject = $this->get(Factory::class); - $result = $subject->fromRequest($request->reveal(), $rule->reveal()); + $result = $subject->fromRequest($request, $rule); self::assertSame(10, $result->getPageUid()); } - /** - * @test - */ + #[Test] public function returnedRecordviewContainsRecordUid(): void { - $rule = $this->prophesize(RecordRule::class); - $rule->getUidExpression()->willReturn('request.getQueryParams()["category"]'); - $rule->getTableName()->willReturn('sys_category'); + $rule = $this->createStub(RecordRule::class); + $rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]'); + $rule->method('getTableName')->willReturn('sys_category'); - $routing = $this->prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn('https://example.com'); - $request->getHeader('User-Agent')->willReturn(['']); - $request->getQueryParams()->willReturn([ + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn('https://example.com'); + $request->method('getHeader')->willReturn(['']); + $request->method('getQueryParams')->willReturn([ 'category' => 20, ]); $subject = $this->get(Factory::class); - $result = $subject->fromRequest($request->reveal(), $rule->reveal()); + $result = $subject->fromRequest($request, $rule); self::assertSame(20, $result->getRecordUid()); } - /** - * @test - */ + #[Test] public function returnedRecordviewContainsTableName(): void { - $rule = $this->prophesize(RecordRule::class); - $rule->getUidExpression()->willReturn('request.getQueryParams()["category"]'); - $rule->getTableName()->willReturn('sys_category'); + $rule = $this->createStub(RecordRule::class); + $rule->method('getUidExpression')->willReturn('request.getQueryParams()["category"]'); + $rule->method('getTableName')->willReturn('sys_category'); - $routing = $this->prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn('https://example.com'); - $request->getHeader('User-Agent')->willReturn(['']); - $request->getQueryParams()->willReturn([ + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn('https://example.com'); + $request->method('getHeader')->willReturn(['']); + $request->method('getQueryParams')->willReturn([ 'category' => 20, ]); $subject = $this->get(Factory::class); - $result = $subject->fromRequest($request->reveal(), $rule->reveal()); + $result = $subject->fromRequest($request, $rule); self::assertSame('sys_category', $result->getTableName()); } } diff --git a/Tests/Functional/Fixtures/BackendUser.php b/Tests/Functional/Fixtures/BackendUser.php index d5d2a8d..9b1a16c 100644 --- a/Tests/Functional/Fixtures/BackendUser.php +++ b/Tests/Functional/Fixtures/BackendUser.php @@ -1,5 +1,7 @@ [ [ diff --git a/Tests/Functional/Fixtures/Extensions/recordview/ext_emconf.php b/Tests/Functional/Fixtures/Extensions/recordview/ext_emconf.php index 12d912b..edb15c8 100644 --- a/Tests/Functional/Fixtures/Extensions/recordview/ext_emconf.php +++ b/Tests/Functional/Fixtures/Extensions/recordview/ext_emconf.php @@ -1,5 +1,7 @@ 'TESTING: Tracking recordview', 'description' => 'Used by functional tests', diff --git a/Tests/Functional/Fixtures/Pages.php b/Tests/Functional/Fixtures/Pages.php index cb4860a..8cb02c7 100644 --- a/Tests/Functional/Fixtures/Pages.php +++ b/Tests/Functional/Fixtures/Pages.php @@ -1,5 +1,7 @@ [ [ diff --git a/Tests/Functional/Fixtures/SysCategories.php b/Tests/Functional/Fixtures/SysCategories.php index d26fd47..38b8760 100644 --- a/Tests/Functional/Fixtures/SysCategories.php +++ b/Tests/Functional/Fixtures/SysCategories.php @@ -1,5 +1,7 @@ [ [ diff --git a/Tests/Functional/Fixtures/Typo3FeaturesTest/PageWithRecords.php b/Tests/Functional/Fixtures/Typo3FeaturesTest/PageWithRecords.php index 7da1030..248a42b 100644 --- a/Tests/Functional/Fixtures/Typo3FeaturesTest/PageWithRecords.php +++ b/Tests/Functional/Fixtures/Typo3FeaturesTest/PageWithRecords.php @@ -1,5 +1,7 @@ [ [ diff --git a/Tests/Functional/Fixtures/UpdateDataCommandTest/PageviewsWithMissingOperatingSystem.php b/Tests/Functional/Fixtures/UpdateDataCommandTest/PageviewsWithMissingOperatingSystem.php index 673a034..d05aef7 100644 --- a/Tests/Functional/Fixtures/UpdateDataCommandTest/PageviewsWithMissingOperatingSystem.php +++ b/Tests/Functional/Fixtures/UpdateDataCommandTest/PageviewsWithMissingOperatingSystem.php @@ -1,5 +1,7 @@ [ [ diff --git a/Tests/Functional/Fixtures/UpdateDataCommandTest/PageviewsWithOperatingSystem.php b/Tests/Functional/Fixtures/UpdateDataCommandTest/PageviewsWithOperatingSystem.php index a4160f8..e22c7c8 100644 --- a/Tests/Functional/Fixtures/UpdateDataCommandTest/PageviewsWithOperatingSystem.php +++ b/Tests/Functional/Fixtures/UpdateDataCommandTest/PageviewsWithOperatingSystem.php @@ -1,5 +1,7 @@ [ [ diff --git a/Tests/Functional/PageviewTest.php b/Tests/Functional/PageviewTest.php index 8149fcb..e8368f2 100644 --- a/Tests/Functional/PageviewTest.php +++ b/Tests/Functional/PageviewTest.php @@ -1,5 +1,7 @@ 'typo3conf/sites', ]; @@ -53,31 +48,27 @@ protected function setUp(): void ]); } - /** - * @test - */ + #[Test] public function trackedWhenAllowed(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0'); - $response = $this->executeFrontendRequest($request); + $response = $this->executeFrontendSubRequest($request); self::assertSame(200, $response->getStatusCode()); $records = $this->getAllRecords('tx_tracking_pageview'); self::assertCount(1, $records); - self::assertSame('1', (string)$records[0]['pid']); - self::assertSame('1', (string)$records[0]['uid']); + self::assertSame('1', (string) $records[0]['pid']); + self::assertSame('1', (string) $records[0]['uid']); self::assertSame('http://localhost/?id=1', $records[0]['url']); self::assertSame('Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0', $records[0]['user_agent']); self::assertSame('Macintosh', $records[0]['operating_system']); - self::assertSame('0', (string)$records[0]['type']); + self::assertSame('0', (string) $records[0]['type']); } - /** - * @test - */ + #[Test] public function notTrackedWhenDisallowed(): void { $this->importPHPDataSet(__DIR__ . '/Fixtures/BackendUser.php'); @@ -87,7 +78,7 @@ public function notTrackedWhenDisallowed(): void $request = $request->withPageId(1); $context = new InternalRequestContext(); $context = $context->withBackendUserId(1); - $response = $this->executeFrontendRequest($request, $context); + $response = $this->executeFrontendSubRequest($request, $context); self::assertSame(200, $response->getStatusCode()); @@ -95,17 +86,14 @@ public function notTrackedWhenDisallowed(): void self::assertCount(0, $records); } - /** - * @test - * - * @dataProvider possibleDeniedUserAgents - */ + #[DataProvider('possibleDeniedUserAgents')] + #[Test] public function preventsTrackingOfUserAgents(string $userAgent): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withHeader('User-Agent', $userAgent); - $response = $this->executeFrontendRequest($request); + $response = $this->executeFrontendSubRequest($request); self::assertSame(200, $response->getStatusCode()); self::assertCount(0, $this->getAllRecords('tx_tracking_pageview')); diff --git a/Tests/Functional/RecordviewTest.php b/Tests/Functional/RecordviewTest.php index 619694a..1c0f452 100644 --- a/Tests/Functional/RecordviewTest.php +++ b/Tests/Functional/RecordviewTest.php @@ -1,5 +1,7 @@ 'typo3conf/sites', ]; @@ -53,6 +46,7 @@ class RecordviewTest extends FunctionalTestCase protected function setUp(): void { + $this->testExtensionsToLoad[] = 'typo3conf/ext/tracking/Tests/Functional/Fixtures/Extensions/recordview'; parent::setUp(); $this->importPHPDataSet(__DIR__ . '/Fixtures/Pages.php'); @@ -61,39 +55,35 @@ protected function setUp(): void ]); } - /** - * @test - */ + #[Test] public function trackedWhenAllowed(): void { $request = new InternalRequest(); $request = $request->withPageId(1); $request = $request->withQueryParameter('topic_id', 1); $request = $request->withHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0'); - $response = $this->executeFrontendRequest($request); + $response = $this->executeFrontendSubRequest($request); self::assertSame(200, $response->getStatusCode()); $records = $this->getAllRecords('tx_tracking_recordview'); self::assertCount(1, $records); - self::assertSame('1', (string)$records[0]['pid']); - self::assertSame('1', (string)$records[0]['uid']); + self::assertSame('1', (string) $records[0]['pid']); + self::assertSame('1', (string) $records[0]['uid']); self::assertSame('http://localhost/?id=1&topic_id=1', $records[0]['url']); self::assertSame('Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0', $records[0]['user_agent']); self::assertSame('Macintosh', $records[0]['operating_system']); self::assertSame('sys_category_1', $records[0]['record']); - self::assertSame('1', (string)$records[0]['record_uid']); + self::assertSame('1', (string) $records[0]['record_uid']); self::assertSame('sys_category', $records[0]['record_table_name']); } - /** - * @test - */ + #[Test] public function notTrackedWhenNotDetected(): void { $request = new InternalRequest(); $request = $request->withPageId(1); - $response = $this->executeFrontendRequest($request); + $response = $this->executeFrontendSubRequest($request); self::assertSame(200, $response->getStatusCode()); diff --git a/Tests/Functional/Typo3FeaturesTest.php b/Tests/Functional/Typo3FeaturesTest.php index 3a0fdb4..662f935 100644 --- a/Tests/Functional/Typo3FeaturesTest.php +++ b/Tests/Functional/Typo3FeaturesTest.php @@ -1,5 +1,7 @@ importPHPDataSet(__DIR__ . '/Fixtures/BackendUser.php'); $this->importPHPDataSet(__DIR__ . '/Fixtures/Typo3FeaturesTest/PageWithRecords.php'); $this->setUpBackendUser(1); - $languageServiceFactory = $this->getContainer()->get(LanguageServiceFactory::class); + $languageServiceFactory = $this->get(LanguageServiceFactory::class); if (!$languageServiceFactory instanceof LanguageServiceFactory) { throw new UnexpectedValueException('Did not retrieve LanguageServiceFactory.', 1637847250); } @@ -61,11 +52,8 @@ protected function tearDown(): void parent::tearDown(); } - /** - * @test - * - * @testdox Copy pages. Tracking records will not be copied. - */ + #[TestDox('Copy pages. Tracking records will not be copied.')] + #[Test] public function copyContainingRecords(): void { $dataHandler = new DataHandler(); @@ -84,11 +72,8 @@ public function copyContainingRecords(): void ); } - /** - * @test - * - * @testdox Copy individual tables, but always exclude tracking tables. - */ + #[TestDox('Copy individual tables, but always exclude tracking tables.')] + #[Test] public function copyCustomTablesViaDataHandler(): void { $dataHandler = new DataHandler(); diff --git a/Tests/Unit/Domain/Model/ExtractorTest.php b/Tests/Unit/Domain/Model/ExtractorTest.php index 99d2439..67a4a98 100644 --- a/Tests/Unit/Domain/Model/ExtractorTest.php +++ b/Tests/Unit/Domain/Model/ExtractorTest.php @@ -1,5 +1,7 @@ prophesize(HasUserAgent::class); - $model->getUserAgent()->willReturn($userAgent); + $model = $this->createStub(HasUserAgent::class); + $model->method('getUserAgent')->willReturn($userAgent); self::assertSame( $expectedOperatingSystem, - Extractor::getOperatingSystem($model->reveal()) + Extractor::getOperatingSystem($model) ); } - public function possibleUserStringWithOperatingSystems(): array + public static function possibleUserStringWithOperatingSystems(): array { return [ [ diff --git a/Tests/Unit/Domain/Model/PageviewTest.php b/Tests/Unit/Domain/Model/PageviewTest.php index 5392fd2..0e72800 100644 --- a/Tests/Unit/Domain/Model/PageviewTest.php +++ b/Tests/Unit/Domain/Model/PageviewTest.php @@ -1,5 +1,7 @@ prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Pageview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), 0, '', @@ -53,16 +49,14 @@ public function canBeCreated(): void self::assertInstanceOf(Pageview::class, $subject); } - /** - * @test - */ + #[Test] public function returnsPageUid(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Pageview( 500, - $language->reveal(), + $language, new DateTimeImmutable(), 0, '', @@ -72,36 +66,32 @@ public function returnsPageUid(): void self::assertSame(500, $subject->getPageUid()); } - /** - * @test - */ + #[Test] public function returnsLanguage(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Pageview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), 0, '', '' ); - self::assertSame($language->reveal(), $subject->getLanguage()); + self::assertSame($language, $subject->getLanguage()); } - /** - * @test - */ + #[Test] public function returnsCrdate(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $crdate = new DateTimeImmutable(); $subject = new Pageview( 0, - $language->reveal(), + $language, $crdate, 0, '', @@ -111,16 +101,14 @@ public function returnsCrdate(): void self::assertSame($crdate, $subject->getCrdate()); } - /** - * @test - */ + #[Test] public function returnsPageType(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Pageview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), 999, '', @@ -130,16 +118,14 @@ public function returnsPageType(): void self::assertSame(999, $subject->getPageType()); } - /** - * @test - */ + #[Test] public function returnsUrl(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Pageview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), 0, 'https://example.com/path.html', @@ -149,16 +135,14 @@ public function returnsUrl(): void self::assertSame('https://example.com/path.html', $subject->getUrl()); } - /** - * @test - */ + #[Test] public function returnsUserAgent(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Pageview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), 0, '', @@ -171,16 +155,14 @@ public function returnsUserAgent(): void ); } - /** - * @test - */ + #[Test] public function returnsZeroAsDefaultUid(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Pageview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), 0, '', @@ -193,16 +175,14 @@ public function returnsZeroAsDefaultUid(): void ); } - /** - * @test - */ + #[Test] public function returnsSetAsUid(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Pageview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), 0, '', @@ -216,16 +196,14 @@ public function returnsSetAsUid(): void ); } - /** - * @test - */ + #[Test] public function returnsOperatingSystem(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Pageview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), 0, '', diff --git a/Tests/Unit/Domain/Model/RecordRuleTest.php b/Tests/Unit/Domain/Model/RecordRuleTest.php index 8a9b107..a1b8fe5 100644 --- a/Tests/Unit/Domain/Model/RecordRuleTest.php +++ b/Tests/Unit/Domain/Model/RecordRuleTest.php @@ -1,5 +1,7 @@ getMatchesExpression()); } - /** - * @test - */ + #[Test] public function returnsUidExpression(): void { $subject = new RecordRule( @@ -109,9 +100,7 @@ public function returnsUidExpression(): void self::assertSame('match expression', $subject->getUidExpression()); } - /** - * @test - */ + #[Test] public function returnsTableName(): void { $subject = new RecordRule( diff --git a/Tests/Unit/Domain/Model/RecordviewTest.php b/Tests/Unit/Domain/Model/RecordviewTest.php index bef5707..3c9a3e3 100644 --- a/Tests/Unit/Domain/Model/RecordviewTest.php +++ b/Tests/Unit/Domain/Model/RecordviewTest.php @@ -1,5 +1,7 @@ prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Recordview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), '', '', @@ -54,16 +50,14 @@ public function canBeCreated(): void self::assertInstanceOf(Recordview::class, $subject); } - /** - * @test - */ + #[Test] public function returnsPageUid(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Recordview( 500, - $language->reveal(), + $language, new DateTimeImmutable(), '', '', @@ -74,16 +68,14 @@ public function returnsPageUid(): void self::assertSame(500, $subject->getPageUid()); } - /** - * @test - */ + #[Test] public function returnsLanguage(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Recordview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), '', '', @@ -91,20 +83,18 @@ public function returnsLanguage(): void 'sys_category' ); - self::assertSame($language->reveal(), $subject->getLanguage()); + self::assertSame($language, $subject->getLanguage()); } - /** - * @test - */ + #[Test] public function returnsCrdate(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $crdate = new DateTimeImmutable(); $subject = new Recordview( 0, - $language->reveal(), + $language, $crdate, '', '', @@ -115,16 +105,14 @@ public function returnsCrdate(): void self::assertSame($crdate, $subject->getCrdate()); } - /** - * @test - */ + #[Test] public function returnsUrl(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Recordview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), 'https://example.com/path.html', '', @@ -135,16 +123,14 @@ public function returnsUrl(): void self::assertSame('https://example.com/path.html', $subject->getUrl()); } - /** - * @test - */ + #[Test] public function returnsUserAgent(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Recordview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), '', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0', @@ -158,16 +144,14 @@ public function returnsUserAgent(): void ); } - /** - * @test - */ + #[Test] public function returnsRecordUid(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Recordview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), '', '', @@ -181,16 +165,14 @@ public function returnsRecordUid(): void ); } - /** - * @test - */ + #[Test] public function returnsTableName(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Recordview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), '', '', @@ -204,16 +186,14 @@ public function returnsTableName(): void ); } - /** - * @test - */ + #[Test] public function returnsOperatingSystem(): void { - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); $subject = new Recordview( 0, - $language->reveal(), + $language, new DateTimeImmutable(), '', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36', diff --git a/Tests/Unit/Domain/Pageview/FactoryTest.php b/Tests/Unit/Domain/Pageview/FactoryTest.php index 7edfdb6..c3399f5 100644 --- a/Tests/Unit/Domain/Pageview/FactoryTest.php +++ b/Tests/Unit/Domain/Pageview/FactoryTest.php @@ -1,5 +1,7 @@ prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); - $routing->getPageType()->willReturn(0); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); + $routing->method('getPageType')->willReturn('0'); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn(''); - $request->getHeader('User-Agent')->willReturn([]); + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn(''); + $request->method('getHeader')->willReturn([]); - $subject = new Factory($this->prophesize(SiteFinder::class)->reveal()); + $subject = new Factory($this->createStub(SiteFinder::class)); - $result = $subject->fromRequest($request->reveal()); + $result = $subject->fromRequest($request); self::assertInstanceOf(Pageview::class, $result); } - /** - * @test - */ + #[Test] public function returnedPageviewContainsUserAgent(): void { - $routing = $this->prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); - $routing->getPageType()->willReturn(0); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); + $routing->method('getPageType')->willReturn('0'); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn(''); - $request->getHeader('User-Agent')->willReturn([ + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn(''); + $request->method('getHeader')->willReturn([ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0', ]); - $subject = new Factory($this->prophesize(SiteFinder::class)->reveal()); + $subject = new Factory($this->createStub(SiteFinder::class)); - $result = $subject->fromRequest($request->reveal()); + $result = $subject->fromRequest($request); self::assertSame( 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0', $result->getUserAgent() ); } - /** - * @test - */ + #[Test] public function returnedPageviewContainsUri(): void { - $routing = $this->prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); - $routing->getPageType()->willReturn(0); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); + $routing->method('getPageType')->willReturn('0'); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn('https://example.com/path?query=params&some=more#anchor'); - $request->getHeader('User-Agent')->willReturn([]); + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn('https://example.com/path?query=params&some=more#anchor'); + $request->method('getHeader')->willReturn([]); - $subject = new Factory($this->prophesize(SiteFinder::class)->reveal()); + $subject = new Factory($this->createStub(SiteFinder::class)); - $result = $subject->fromRequest($request->reveal()); + $result = $subject->fromRequest($request); self::assertSame( 'https://example.com/path?query=params&some=more#anchor', $result->getUrl() ); } - /** - * @test - */ + #[Test] public function returnedPageviewContainsPageType(): void { - $routing = $this->prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); - $routing->getPageType()->willReturn(50); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); + $routing->method('getPageType')->willReturn('50'); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn(''); - $request->getHeader('User-Agent')->willReturn([]); + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn(''); + $request->method('getHeader')->willReturn([]); - $subject = new Factory($this->prophesize(SiteFinder::class)->reveal()); + $subject = new Factory($this->createStub(SiteFinder::class)); - $result = $subject->fromRequest($request->reveal()); + $result = $subject->fromRequest($request); self::assertSame( 50, $result->getPageType() ); } - /** - * @test - */ + #[Test] public function returnedPageviewContainsDateTime(): void { - $routing = $this->prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); - $routing->getPageType()->willReturn(0); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); + $routing->method('getPageType')->willReturn('0'); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn(''); - $request->getHeader('User-Agent')->willReturn([]); + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn(''); + $request->method('getHeader')->willReturn([]); - $subject = new Factory($this->prophesize(SiteFinder::class)->reveal()); + $subject = new Factory($this->createStub(SiteFinder::class)); - $result = $subject->fromRequest($request->reveal()); + $result = $subject->fromRequest($request); self::assertInstanceOf(DateTimeImmutable::class, $result->getCrdate()); } - /** - * @test - */ + #[Test] public function returnedPageviewContainsLanguage(): void { - $routing = $this->prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); - $routing->getPageType()->willReturn(0); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); + $routing->method('getPageType')->willReturn('0'); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn(''); - $request->getHeader('User-Agent')->willReturn([]); + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn(''); + $request->method('getHeader')->willReturn([]); - $subject = new Factory($this->prophesize(SiteFinder::class)->reveal()); + $subject = new Factory($this->createStub(SiteFinder::class)); - $result = $subject->fromRequest($request->reveal()); + $result = $subject->fromRequest($request); self::assertInstanceOf(SiteLanguage::class, $result->getLanguage()); } - /** - * @test - */ + #[Test] public function returnedPageviewContainsPageId(): void { - $routing = $this->prophesize(PageArguments::class); - $routing->getPageId()->willReturn(10); - $routing->getPageType()->willReturn(0); + $routing = $this->createStub(PageArguments::class); + $routing->method('getPageId')->willReturn(10); + $routing->method('getPageType')->willReturn('0'); - $language = $this->prophesize(SiteLanguage::class); + $language = $this->createStub(SiteLanguage::class); - $request = $this->prophesize(ServerRequestInterface::class); - $request->getAttribute('routing')->willReturn($routing->reveal()); - $request->getAttribute('language')->willReturn($language->reveal()); - $request->getUri()->willReturn(''); - $request->getHeader('User-Agent')->willReturn([]); + $request = $this->createStub(ServerRequestInterface::class); + $request->method('getAttribute')->willReturnMap([ + ['routing', null, $routing], + ['language', null, $language], + ]); + $request->method('getUri')->willReturn(''); + $request->method('getHeader')->willReturn([]); - $subject = new Factory($this->prophesize(SiteFinder::class)->reveal()); + $subject = new Factory($this->createStub(SiteFinder::class)); - $result = $subject->fromRequest($request->reveal()); + $result = $subject->fromRequest($request); self::assertSame( 10, $result->getPageUid() ); } - /** - * @test - */ + #[Test] public function returnsPageviewFromDbRow(): void { - $siteLanguage = $this->prophesize(SiteLanguage::class); - $site = $this->prophesize(Site::class); - $site->getLanguageById(0)->willReturn($siteLanguage->reveal()); - $siteFinder = $this->prophesize(SiteFinder::class); - $siteFinder->getSiteByPageId(2)->willReturn($site->reveal()); + $siteLanguage = $this->createStub(SiteLanguage::class); + $site = $this->createStub(Site::class); + $site->method('getLanguageById')->willReturn($siteLanguage); + $siteFinder = $this->createStub(SiteFinder::class); + $siteFinder->method('getSiteByPageId')->willReturn($site); - $subject = new Factory($siteFinder->reveal()); + $subject = new Factory($siteFinder); $result = $subject->fromDbRow([ 'uid' => 1, @@ -240,7 +236,7 @@ public function returnsPageviewFromDbRow(): void self::assertInstanceOf(Pageview::class, $result); self::assertSame(1, $result->getUid()); self::assertSame(2, $result->getPageUid()); - self::assertSame($siteLanguage->reveal(), $result->getLanguage()); + self::assertSame($siteLanguage, $result->getLanguage()); self::assertSame('1533906435', $result->getCrdate()->format('U')); self::assertSame(0, $result->getPageType()); self::assertSame('https://example.com/path', $result->getUrl()); diff --git a/Tests/Unit/Domain/Repository/PageviewTest.php b/Tests/Unit/Domain/Repository/PageviewTest.php index 2be1d42..a3107b2 100644 --- a/Tests/Unit/Domain/Repository/PageviewTest.php +++ b/Tests/Unit/Domain/Repository/PageviewTest.php @@ -1,5 +1,7 @@ prophesize(Connection::class); - $factory = $this->prophesize(Factory::class); - - $dateTime = $this->prophesize(DateTimeImmutable::class); - $dateTime->format('U')->willReturn(1582660189); - - $language = $this->prophesize(SiteLanguage::class); - $language->getLanguageId()->willReturn(2); - - $model = $this->prophesize(Model::class); - $model->getPageUid()->willReturn(10); - $model->getCrdate()->willReturn($dateTime->reveal()); - $model->getPageType()->willReturn(999); - $model->getLanguage()->willReturn($language->reveal()); - $model->getUrl()->willReturn('https://example.com/path.html'); - $model->getUserAgent()->willReturn('Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/74.0'); - $model->getOperatingSystem()->willReturn('Linux'); - - $connection->insert( - 'tx_tracking_pageview', - [ - 'pid' => 10, - 'crdate' => 1582660189, - 'tstamp' => 1582660189, - 'type' => 999, - 'sys_language_uid' => 2, - 'url' => 'https://example.com/path.html', - 'user_agent' => 'Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/74.0', - 'operating_system' => 'Linux', - ] - )->willReturn(1)->shouldBeCalledTimes(1); - - $subject = new Pageview($connection->reveal(), $factory->reveal()); - $subject->add($model->reveal()); + $connection = $this->createMock(Connection::class); + $factory = $this->createMock(Factory::class); + + $dateTime = $this->createStub(DateTimeImmutable::class); + $dateTime->method('format')->willReturn('1582660189'); + + $language = $this->createStub(SiteLanguage::class); + $language->method('getLanguageId')->willReturn(2); + + $model = $this->createStub(Model::class); + $model->method('getPageUid')->willReturn(10); + $model->method('getCrdate')->willReturn($dateTime); + $model->method('getPageType')->willReturn(999); + $model->method('getLanguage')->willReturn($language); + $model->method('getUrl')->willReturn('https://example.com/path.html'); + $model->method('getUserAgent')->willReturn('Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/74.0'); + $model->method('getOperatingSystem')->willReturn('Linux'); + + $connection + ->expects(self::once()) + ->method('insert') + ->with( + 'tx_tracking_pageview', + [ + 'pid' => 10, + 'crdate' => 1582660189, + 'tstamp' => 1582660189, + 'type' => 999, + 'sys_language_uid' => 2, + 'url' => 'https://example.com/path.html', + 'user_agent' => 'Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/74.0', + 'operating_system' => 'Linux', + ] + ) + ->willReturn(1) + ; + + $subject = new Pageview($connection, $factory); + $subject->add($model); } - /** - * @test - */ + #[Test] public function throwsExceptionIfModelToUodateHasNoUid(): void { - $connection = $this->prophesize(Connection::class); - $factory = $this->prophesize(Factory::class); + $connection = $this->createMock(Connection::class); + $factory = $this->createMock(Factory::class); - $model = $this->prophesize(Model::class); - $model->getUid()->willReturn(0); + $model = $this->createStub(Model::class); + $model->method('getUid')->willReturn(0); - $subject = new Pageview($connection->reveal(), $factory->reveal()); + $subject = new Pageview($connection, $factory); $this->expectExceptionMessage('Can not update pageview if uid is 0.'); - $subject->update($model->reveal()); + $subject->update($model); } - /** - * @test - */ + #[Test] public function modelCanBeUpdated(): void { - $connection = $this->prophesize(Connection::class); - $factory = $this->prophesize(Factory::class); - - $dateTime = $this->prophesize(DateTimeImmutable::class); - $dateTime->format('U')->willReturn(1582660189); - - $language = $this->prophesize(SiteLanguage::class); - $language->getLanguageId()->willReturn(2); - - $model = $this->prophesize(Model::class); - $model->getUid()->willReturn(1); - $model->getPageUid()->willReturn(10); - $model->getCrdate()->willReturn($dateTime->reveal()); - $model->getPageType()->willReturn(999); - $model->getLanguage()->willReturn($language->reveal()); - $model->getUrl()->willReturn('https://example.com/path.html'); - $model->getUserAgent()->willReturn('Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/74.0'); - $model->getOperatingSystem()->willReturn('Linux'); - - $connection->update( - 'tx_tracking_pageview', - [ - 'pid' => 10, - 'crdate' => 1582660189, - 'tstamp' => 1582660189, - 'type' => 999, - 'sys_language_uid' => 2, - 'url' => 'https://example.com/path.html', - 'user_agent' => 'Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/74.0', - 'operating_system' => 'Linux', - ], - [ - 'uid' => 1, - ] - )->willReturn(1)->shouldBeCalledTimes(1); - - $subject = new Pageview($connection->reveal(), $factory->reveal()); - $subject->update($model->reveal()); + $connection = $this->createMock(Connection::class); + $factory = $this->createMock(Factory::class); + + $dateTime = $this->createStub(DateTimeImmutable::class); + $dateTime->method('format')->willReturn('1582660189'); + + $language = $this->createStub(SiteLanguage::class); + $language->method('getLanguageId')->willReturn(2); + + $model = $this->createStub(Model::class); + $model->method('getUid')->willReturn(1); + $model->method('getPageUid')->willReturn(10); + $model->method('getCrdate')->willReturn($dateTime); + $model->method('getPageType')->willReturn(999); + $model->method('getLanguage')->willReturn($language); + $model->method('getUrl')->willReturn('https://example.com/path.html'); + $model->method('getUserAgent')->willReturn('Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/74.0'); + $model->method('getOperatingSystem')->willReturn('Linux'); + + $connection + ->expects(self::once()) + ->method('update') + ->with( + 'tx_tracking_pageview', + [ + 'pid' => 10, + 'crdate' => 1582660189, + 'tstamp' => 1582660189, + 'type' => 999, + 'sys_language_uid' => 2, + 'url' => 'https://example.com/path.html', + 'user_agent' => 'Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/74.0', + 'operating_system' => 'Linux', + ], + [ + 'uid' => 1, + ] + ) + ->willReturn(1) + ; + + $subject = new Pageview($connection, $factory); + $subject->update($model); } } diff --git a/Tests/Unit/Domain/Repository/RecordviewTest.php b/Tests/Unit/Domain/Repository/RecordviewTest.php index 5cac445..e47650c 100644 --- a/Tests/Unit/Domain/Repository/RecordviewTest.php +++ b/Tests/Unit/Domain/Repository/RecordviewTest.php @@ -1,5 +1,7 @@ prophesize(Connection::class); + $connection = $this->createMock(Connection::class); - $dateTime = $this->prophesize(DateTimeImmutable::class); - $dateTime->format('U')->willReturn(1582660189); + $dateTime = $this->createStub(DateTimeImmutable::class); + $dateTime->method('format')->willReturn('1582660189'); - $language = $this->prophesize(SiteLanguage::class); - $language->getLanguageId()->willReturn(2); + $language = $this->createStub(SiteLanguage::class); + $language->method('getLanguageId')->willReturn(2); - $model = $this->prophesize(Model::class); - $model->getPageUid()->willReturn(10); - $model->getCrdate()->willReturn($dateTime->reveal()); - $model->getLanguage()->willReturn($language->reveal()); - $model->getUrl()->willReturn('https://example.com/path.html'); - $model->getUserAgent()->willReturn('Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/74.0'); - $model->getOperatingSystem()->willReturn('Linux'); - $model->getRecordUid()->willReturn(10); - $model->getTableName()->willReturn('sys_category'); + $model = $this->createStub(Model::class); + $model->method('getPageUid')->willReturn(10); + $model->method('getCrdate')->willReturn($dateTime); + $model->method('getLanguage')->willReturn($language); + $model->method('getUrl')->willReturn('https://example.com/path.html'); + $model->method('getUserAgent')->willReturn('Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/74.0'); + $model->method('getOperatingSystem')->willReturn('Linux'); + $model->method('getRecordUid')->willReturn(10); + $model->method('getTableName')->willReturn('sys_category'); - $connection->insert( - 'tx_tracking_recordview', - [ - 'pid' => 10, - 'crdate' => 1582660189, - 'tstamp' => 1582660189, - 'sys_language_uid' => 2, - 'url' => 'https://example.com/path.html', - 'user_agent' => 'Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/74.0', - 'operating_system' => 'Linux', - 'record_uid' => 10, - 'record_table_name' => 'sys_category', - 'record' => 'sys_category_10', - ] - )->willReturn(1)->shouldBeCalledTimes(1); + $connection + ->expects(self::once()) + ->method('insert') + ->with( + 'tx_tracking_recordview', + [ + 'pid' => 10, + 'crdate' => 1582660189, + 'tstamp' => 1582660189, + 'sys_language_uid' => 2, + 'url' => 'https://example.com/path.html', + 'user_agent' => 'Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/74.0', + 'operating_system' => 'Linux', + 'record_uid' => 10, + 'record_table_name' => 'sys_category', + 'record' => 'sys_category_10', + ] + ) + ->willReturn(1) + ; - $subject = new Recordview($connection->reveal()); - $subject->add($model->reveal()); + $subject = new Recordview($connection); + $subject->add($model); } } diff --git a/composer.json b/composer.json index 1805b19..8b49d79 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "require": { "php": "~8.1.0 || ~8.2.0 || ~8.3.0", "ext-mbstring": "*", - "doctrine/dbal": "^2.12 || ^3.3 || 4.0.0-RC2@rc", + "doctrine/dbal": "^2.12 || ^3.3 || 4.0.0-RC2", "psr/http-message": "^1.0", "psr/http-server-handler": "^1.0", "psr/http-server-middleware": "^1.0", @@ -39,14 +39,13 @@ "typo3/cms-dashboard": "^12.4 || ^13.0" }, "require-dev": { - "codappix/typo3-php-datasets": "^1.3", + "codappix/typo3-php-datasets": "^1.5", "cweagans/composer-patches": "^1.7", "friendsofphp/php-cs-fixer": "^3.14", - "jangregor/phpstan-prophecy": "^1.0", - "phpspec/prophecy-phpunit": "^2.0", "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^10.1", + "saschaegerer/phpstan-typo3": "^1.10", "typo3/testing-framework": "^8.0" }, "minimum-stability": "dev", diff --git a/ext_localconf.php b/ext_localconf.php index df41943..eff503e 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,3 +1,7 @@ \\|Doctrine\\\\DBAL\\\\Query\\\\Expression\\\\CompositeExpression, string given\\.$#" - '#^Variable \$_EXTKEY might not be defined\.$#' - - "#^Cannot access offset '.*' on mixed.$#" - - "#^Parameter .* expects .*, mixed given.$#" - - "#^Cannot call method .* on mixed.$#" diff --git a/shell.nix b/shell.nix index 24c561e..18bfdad 100644 --- a/shell.nix +++ b/shell.nix @@ -1,8 +1,20 @@ -{ pkgs ? import { } }: +{ + pkgs ? import { } + ,phps ? import +}: let - php = pkgs.php83; - inherit(pkgs.php83Packages) composer; + php = phps.packages.x86_64-linux.php83.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";