Skip to content

Commit

Permalink
[TASK] Use better suiting typing in SiteBasedTestTrait
Browse files Browse the repository at this point in the history
The `SiteBasedTestTrait` uses `AbstractInstruction` to declare
native types for method arguments and return types and PHPStan
complains about this because `typo3/testing-framework` methods
uses the `InstructionInterface` instead.

This change adopts `InstructionInterface` type hints to be in
line with the `typo3/testing-framework` and satisfy PHPStan,
which allows us to remove no longer matched ignored errors from
the PHPStan baseline.

Used command(s):

```shell
Build/Scripts/runTests.sh -t 12 -p 8.1 -s phpstanGenerateBaseline
```
  • Loading branch information
sbuerk committed Dec 12, 2024
1 parent ca208a9 commit bf3f529
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 30 deletions.
25 changes: 0 additions & 25 deletions Build/phpstan/Core12/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,6 @@ parameters:
count: 1
path: ../../../Tests/Functional/Hooks/TranslateHookTest.php

-
message: "#^Parameter \\#1 \\$current of method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Hooks\\\\TranslateHookTest\\:\\:mergeInstruction\\(\\) expects TYPO3\\\\TestingFramework\\\\Core\\\\Functional\\\\Framework\\\\Frontend\\\\Internal\\\\AbstractInstruction, TYPO3\\\\TestingFramework\\\\Core\\\\Functional\\\\Framework\\\\Frontend\\\\Internal\\\\AbstractInstruction\\|null given\\.$#"
count: 1
path: ../../../Tests/Functional/Hooks/TranslateHookTest.php

-
message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Regression\\\\GlossaryRegressionTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -315,11 +310,6 @@ parameters:
count: 1
path: ../../../Tests/Functional/Regression/GlossaryRegressionTest.php

-
message: "#^Parameter \\#1 \\$current of method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Regression\\\\GlossaryRegressionTest\\:\\:mergeInstruction\\(\\) expects TYPO3\\\\TestingFramework\\\\Core\\\\Functional\\\\Framework\\\\Frontend\\\\Internal\\\\AbstractInstruction, TYPO3\\\\TestingFramework\\\\Core\\\\Functional\\\\Framework\\\\Frontend\\\\Internal\\\\AbstractInstruction\\|null given\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/GlossaryRegressionTest.php

-
message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -370,11 +360,6 @@ parameters:
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Parameter \\#1 \\$current of method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Regression\\\\LocalizationInlineRegressionTest\\:\\:mergeInstruction\\(\\) expects TYPO3\\\\TestingFramework\\\\Core\\\\Functional\\\\Framework\\\\Frontend\\\\Internal\\\\AbstractInstruction, TYPO3\\\\TestingFramework\\\\Core\\\\Functional\\\\Framework\\\\Frontend\\\\Internal\\\\AbstractInstruction\\|null given\\.$#"
count: 1
path: ../../../Tests/Functional/Regression/LocalizationInlineRegressionTest.php

-
message: "#^Cannot access property \\$code on DeepL\\\\Language\\|null\\.$#"
count: 7
Expand Down Expand Up @@ -430,11 +415,6 @@ parameters:
count: 1
path: ../../../Tests/Functional/Services/LanguageServiceTest.php

-
message: "#^Parameter \\#1 \\$current of method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Services\\\\LanguageServiceTest\\:\\:mergeInstruction\\(\\) expects TYPO3\\\\TestingFramework\\\\Core\\\\Functional\\\\Framework\\\\Frontend\\\\Internal\\\\AbstractInstruction, TYPO3\\\\TestingFramework\\\\Core\\\\Functional\\\\Framework\\\\Frontend\\\\Internal\\\\AbstractInstruction\\|null given\\.$#"
count: 1
path: ../../../Tests/Functional/Services/LanguageServiceTest.php

-
message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Updates\\\\FormalityUpgradeWizardTest\\:\\:buildDefaultLanguageConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -484,8 +464,3 @@ parameters:
message: "#^Method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Updates\\\\FormalityUpgradeWizardTest\\:\\:writeSiteConfiguration\\(\\) has parameter \\$site with no value type specified in iterable type array\\.$#"
count: 1
path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php

-
message: "#^Parameter \\#1 \\$current of method WebVision\\\\Deepltranslate\\\\Core\\\\Tests\\\\Functional\\\\Updates\\\\FormalityUpgradeWizardTest\\:\\:mergeInstruction\\(\\) expects TYPO3\\\\TestingFramework\\\\Core\\\\Functional\\\\Framework\\\\Frontend\\\\Internal\\\\AbstractInstruction, TYPO3\\\\TestingFramework\\\\Core\\\\Functional\\\\Framework\\\\Frontend\\\\Internal\\\\AbstractInstruction\\|null given\\.$#"
count: 1
path: ../../../Tests/Functional/Updates/FormalityUpgradeWizardTest.php
10 changes: 5 additions & 5 deletions Tests/Functional/Fixtures/Traits/SiteBasedTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use TYPO3\CMS\Core\Configuration\SiteConfiguration;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\AbstractInstruction;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\ArrayValueInstruction;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\InstructionInterface;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\TypoScriptInstruction;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
use WebVision\Deepltranslate\Core\Tests\Functional\Fixtures\Frontend\PhpError;
Expand Down Expand Up @@ -242,13 +242,13 @@ protected function resolveLanguagePreset(string $identifier)
/**
* @todo Instruction handling should be part of Testing Framework (multiple instructions per identifier, merge in interface)
*/
protected function applyInstructions(InternalRequest $request, AbstractInstruction ...$instructions): InternalRequest
protected function applyInstructions(InternalRequest $request, InstructionInterface ...$instructions): InternalRequest
{
$modifiedInstructions = [];

$instructions = array_filter($instructions);
foreach ($instructions as $instruction) {
$identifier = $instruction->getIdentifier();
if (isset($modifiedInstructions[$identifier]) || $request->getInstruction($identifier) !== null) {
if (($modifiedInstructions[$identifier] ?? $request->getInstruction($identifier)) !== null) {
$modifiedInstructions[$identifier] = $this->mergeInstruction(
$modifiedInstructions[$identifier] ?? $request->getInstruction($identifier),
$instruction
Expand All @@ -261,7 +261,7 @@ protected function applyInstructions(InternalRequest $request, AbstractInstructi
return $request->withInstructions($modifiedInstructions);
}

protected function mergeInstruction(AbstractInstruction $current, AbstractInstruction $other): AbstractInstruction
protected function mergeInstruction(InstructionInterface $current, InstructionInterface $other): InstructionInterface
{
if (get_class($current) !== get_class($other)) {
throw new LogicException('Cannot merge different instruction types', 1565863174);
Expand Down

0 comments on commit bf3f529

Please sign in to comment.