From eb430a75ab90dafd21b2748ae2561507c26ca473 Mon Sep 17 00:00:00 2001 From: Daniil Tkachev Date: Mon, 30 Oct 2023 16:08:16 +0100 Subject: [PATCH] OXDEV-7518 Upgrade phpunit from 9 to 10 --- .../Filters/PhpFunctionsExtensionTest.php | 2 +- .../Filters/RegexReplaceExtensionTest.php | 3 +- .../Filters/TranslateExtensionTest.php | 35 ++++--------- .../TranslateSalutationExtensionTest.php | 4 +- .../Filters/TruncateExtensionTest.php | 8 +-- .../Filters/WordwrapExtensionTest.php | 12 ++--- .../Extensions/FormatPriceExtensionTest.php | 2 +- .../GetRequestVariablesExtensionTest.php | 2 +- .../IncludeContentExtensionTest.php | 2 +- .../Extensions/InputHelpExtensionTest.php | 4 +- .../Extensions/MailtoExtensionTest.php | 3 +- .../Extensions/PhpFunctionsExtensionTest.php | 2 +- .../Extensions/ScriptExtensionTest.php | 4 +- .../Extensions/SmartyCycleExtensionTest.php | 2 +- .../Extensions/TranslateExtensionTest.php | 2 +- .../Extensions/UrlExtensionTest.php | 4 +- .../Resolver/TemplateFileResolverTest.php | 2 +- .../src/Contoller/ModuleController.php | 2 +- .../ModuleControllerMissingTemplate.php | 1 + .../ModulesTemplateChainSortingTest.php | 8 +-- tests/Unit/Escaper/DecEntityEscaperTest.php | 4 +- tests/Unit/Escaper/HexEntityEscaperTest.php | 4 +- tests/Unit/Escaper/HexEscaperTest.php | 2 +- tests/Unit/Escaper/HtmlAllEscaperTest.php | 2 +- tests/Unit/Escaper/MailEscaperTest.php | 2 +- tests/Unit/Escaper/NonStdEscaperTest.php | 9 ++-- tests/Unit/Escaper/QuotesEscaperTest.php | 2 +- tests/Unit/Escaper/UrlPathInfoEscaperTest.php | 2 +- .../Filters/DateFormatExtensionTest.php | 2 +- .../Filters/FileSizeExtensionTest.php | 2 +- .../Filters/FormatTimeExtensionTest.php | 2 +- .../Filters/SmartWordwrapExtensionTest.php | 3 +- .../Unit/Extensions/IncludeExtensionTest.php | 5 +- tests/Unit/Extensions/StyleExtensionTest.php | 2 +- tests/Unit/Loader/CmsLoaderTest.php | 9 ++-- .../Unit/Loader/CmsTemplateNameParserTest.php | 4 +- tests/Unit/Node/AbstractOxidTwigTestCase.php | 29 +++++++++++ tests/Unit/Node/CaptureNodeTest.php | 50 ++++++++++--------- tests/Unit/Node/HasRightsNodeTest.php | 14 +++--- tests/Unit/Node/IfContentNodeTest.php | 5 +- tests/Unit/Node/IncludeDynamicNodeTest.php | 23 +++++++-- .../ModulesTemplateDirectoryResolverTest.php | 25 +++++++--- .../TokenParser/CaptureTokenParserTest.php | 4 +- .../TokenParser/HasRightsTokenParserTest.php | 6 ++- 44 files changed, 180 insertions(+), 136 deletions(-) create mode 100644 tests/Unit/Node/AbstractOxidTwigTestCase.php diff --git a/tests/Integration/Extensions/Filters/PhpFunctionsExtensionTest.php b/tests/Integration/Extensions/Filters/PhpFunctionsExtensionTest.php index 08126c3..8b6bad5 100644 --- a/tests/Integration/Extensions/Filters/PhpFunctionsExtensionTest.php +++ b/tests/Integration/Extensions/Filters/PhpFunctionsExtensionTest.php @@ -25,7 +25,7 @@ protected function setUp(): void $this->extension = new PhpFunctionsExtension(); } - public function dummyTemplateProvider(): array + public static function dummyTemplateProvider(): array { return [ ["{% set foo = 'bar'|parse_url %}{{ foo['path'] }}", 'bar'], diff --git a/tests/Integration/Extensions/Filters/RegexReplaceExtensionTest.php b/tests/Integration/Extensions/Filters/RegexReplaceExtensionTest.php index 941a59e..1de76ae 100644 --- a/tests/Integration/Extensions/Filters/RegexReplaceExtensionTest.php +++ b/tests/Integration/Extensions/Filters/RegexReplaceExtensionTest.php @@ -24,7 +24,7 @@ protected function setUp(): void $this->extension = new RegexReplaceExtension(); } - public function dummyTemplateProvider(): array + public static function dummyTemplateProvider(): array { return [ ["{{ '1-foo-2'|regex_replace('/[0-9]/', 'bar') }}", "bar-foo-bar"], @@ -32,7 +32,6 @@ public function dummyTemplateProvider(): array } /** - * * @dataProvider dummyTemplateProvider */ public function testIfPhpFunctionsAreCallable(string $template, string $expected) diff --git a/tests/Integration/Extensions/Filters/TranslateExtensionTest.php b/tests/Integration/Extensions/Filters/TranslateExtensionTest.php index fe8adb8..82ec35a 100644 --- a/tests/Integration/Extensions/Filters/TranslateExtensionTest.php +++ b/tests/Integration/Extensions/Filters/TranslateExtensionTest.php @@ -1,4 +1,4 @@ -extension = $this->get(TranslateExtension::class); } - /** - * Provides data to testSimpleTranslating - */ - public function simpleTranslatingProvider(): array + public static function simpleTranslatingProvider(): array { return [ ["{{ 'FIRST_NAME'|translate }}", 0, 'Vorname'], @@ -41,9 +38,6 @@ public function simpleTranslatingProvider(): array } /** - * Tests simple translating, where only translation is fetched - * - * * @dataProvider simpleTranslatingProvider */ public function testSimpleTranslating(string $template, int $languageId, string $expected): void @@ -52,10 +46,7 @@ public function testSimpleTranslating(string $template, int $languageId, string $this->assertEquals($expected, $this->getTemplate($template)->render([])); } - /** - * Provides data to testTranslatingWithArguments - */ - public function withArgumentsProvider(): array + public static function withArgumentsProvider(): array { return [ ["{{ 'MANUFACTURER_S'|translate('Opel') }}", 0, '| Hersteller: Opel'], @@ -66,8 +57,6 @@ public function withArgumentsProvider(): array } /** - * Tests value translating when translating strings containing %s - * * @dataProvider withArgumentsProvider */ public function testTranslatingWithArguments(string $template, int $languageId, string $expected): void @@ -76,21 +65,22 @@ public function testTranslatingWithArguments(string $template, int $languageId, $this->assertEquals($expected, $this->getTemplate($template)->render([])); } - /** - * Provides data to testTranslateFrontend_isMissingTranslation - */ - public function missingTranslationProviderFrontend(): array + public static function missingTranslationProviderFrontend(): array { return [ [true, "{{ 'MY_MISING_TRANSLATION'|translate }}", 'MY_MISING_TRANSLATION'], - [false, "{{ 'MY_MISING_TRANSLATION'|translate }}", 'ERROR: Translation for MY_MISING_TRANSLATION not found!'], + [false, "{{ 'MY_MISING_TRANSLATION'|translate }}", 'ERROR: Translation for MY_MISING_TRANSLATION not found!'], //phpcs:disable ]; } /** * @dataProvider missingTranslationProviderFrontend */ - public function testTranslateFrontendIsMissingTranslation(bool $isProductiveMode, string $template, string $expected): void + public function testTranslateFrontendIsMissingTranslation( + bool $isProductiveMode, + string $template, + string $expected + ): void { $this->setAdminMode(false); $this->setLanguage(1); @@ -102,10 +92,7 @@ public function testTranslateFrontendIsMissingTranslation(bool $isProductiveMode $this->assertStringContainsString($expected, $this->getTemplate($template)->render([])); } - /** - * Provides data to testTranslateAdmin_isMissingTranslation - */ - public function missingTranslationProviderAdmin(): array + public static function missingTranslationProviderAdmin(): array { return [ ["{{ 'MY_MISING_TRANSLATION'|translate }}", 'ERROR: Translation for MY_MISING_TRANSLATION not found!'], diff --git a/tests/Integration/Extensions/Filters/TranslateSalutationExtensionTest.php b/tests/Integration/Extensions/Filters/TranslateSalutationExtensionTest.php index c91ebeb..1eadd5f 100644 --- a/tests/Integration/Extensions/Filters/TranslateSalutationExtensionTest.php +++ b/tests/Integration/Extensions/Filters/TranslateSalutationExtensionTest.php @@ -24,7 +24,7 @@ protected function setUp(): void $this->setLanguage(0); } - public function translateSalutationProvider(): array + public static function translateSalutationProvider(): array { return [ ["{{ 'MR'|translate_salutation }}", 'Herr'], @@ -39,7 +39,7 @@ public function testTranslateSalutation(string $template, string $expected): voi { $translateSalutationLogic = $this->getMockBuilder(TranslateSalutationLogic::class) ->disableOriginalConstructor() - ->setMethods(['translateSalutation'])->getMock(); + ->onlyMethods(['translateSalutation'])->getMock(); $translateSalutationLogic->expects($this->once())->method('translateSalutation')->willReturn( $expected diff --git a/tests/Integration/Extensions/Filters/TruncateExtensionTest.php b/tests/Integration/Extensions/Filters/TruncateExtensionTest.php index fce8a77..364c4d7 100644 --- a/tests/Integration/Extensions/Filters/TruncateExtensionTest.php +++ b/tests/Integration/Extensions/Filters/TruncateExtensionTest.php @@ -32,7 +32,7 @@ public function testTruncate(string $template, string $expected): void $this->assertEquals($expected, $this->getTemplate($template)->render([])); } - public function truncateProvider(): array + public static function truncateProvider(): array { return [ [ @@ -54,7 +54,7 @@ public function testTruncateWithLength(string $template, string $expected): void $this->assertEquals($expected, $this->getTemplate($template)->render([])); } - public function truncateProviderWithLength(): array + public static function truncateProviderWithLength(): array { return [ [ @@ -80,7 +80,7 @@ public function testTruncateWithSuffix(string $template, string $expected): void $this->assertEquals($expected, $this->getTemplate($template)->render([])); } - public function truncateProviderWithSuffix(): array + public static function truncateProviderWithSuffix(): array { return [ [ @@ -98,7 +98,7 @@ public function testTruncateWithBreakWords(string $template, string $expected): $this->assertEquals($expected, $this->getTemplate($template)->render([])); } - public function truncateProviderWithBreakWords(): array + public static function truncateProviderWithBreakWords(): array { return [ [ diff --git a/tests/Integration/Extensions/Filters/WordwrapExtensionTest.php b/tests/Integration/Extensions/Filters/WordwrapExtensionTest.php index 3901677..71ded35 100644 --- a/tests/Integration/Extensions/Filters/WordwrapExtensionTest.php +++ b/tests/Integration/Extensions/Filters/WordwrapExtensionTest.php @@ -24,10 +24,7 @@ protected function setUp(): void $this->extension = new WordwrapExtension(new WordwrapLogic()); } - /** - * Provides data for testWordWrapWithNonAscii - */ - public function nonAsciiProvider(): array + public static function nonAsciiProvider(): array { return [ ['{{ "HÖ HÖ"|wordwrap(2) }}', "HÖ\nHÖ"], @@ -45,10 +42,8 @@ public function testWordWrapWithNonAscii(string $template, string $expected): vo $this->assertEquals($expected, $this->getTemplate($template)->render([])); } - /** - * Provides data for testWordWrapAscii - */ - public function asciiProvider(): array + //phpcs:disable + public static function asciiProvider(): array { return [ ['{{ "aaa aaa"|wordwrap(2) }}', "aaa\naaa"], @@ -65,6 +60,7 @@ public function asciiProvider(): array ] ]; } + //phpcs:enable /** * @dataProvider asciiProvider diff --git a/tests/Integration/Extensions/FormatPriceExtensionTest.php b/tests/Integration/Extensions/FormatPriceExtensionTest.php index 35d3482..801a519 100644 --- a/tests/Integration/Extensions/FormatPriceExtensionTest.php +++ b/tests/Integration/Extensions/FormatPriceExtensionTest.php @@ -21,7 +21,7 @@ protected function setUp(): void $this->extension = new FormatPriceExtension($formatPriceLogic); } - public function priceProvider(): array + public static function priceProvider(): array { return [ ['{{ format_price(100) }}', '100,00 €'], diff --git a/tests/Integration/Extensions/GetRequestVariablesExtensionTest.php b/tests/Integration/Extensions/GetRequestVariablesExtensionTest.php index b585480..b23d4e3 100644 --- a/tests/Integration/Extensions/GetRequestVariablesExtensionTest.php +++ b/tests/Integration/Extensions/GetRequestVariablesExtensionTest.php @@ -31,7 +31,7 @@ protected function tearDown(): void unset($_GET['foo']); } - public function dummyTemplateProvider(): array + public static function dummyTemplateProvider(): array { return [ ['{{ get_global_cookie("foo") }}', 'bar'], diff --git a/tests/Integration/Extensions/IncludeContentExtensionTest.php b/tests/Integration/Extensions/IncludeContentExtensionTest.php index 892a4e0..6df404a 100644 --- a/tests/Integration/Extensions/IncludeContentExtensionTest.php +++ b/tests/Integration/Extensions/IncludeContentExtensionTest.php @@ -78,7 +78,7 @@ public function testContent(string $template, string $expected): void $this->assertEquals($expected, $this->getTemplate($template)->render([])); } - public function contentProvider(): array + public static function contentProvider(): array { return [ [ diff --git a/tests/Integration/Extensions/InputHelpExtensionTest.php b/tests/Integration/Extensions/InputHelpExtensionTest.php index 1b0efb7..a8a99a5 100644 --- a/tests/Integration/Extensions/InputHelpExtensionTest.php +++ b/tests/Integration/Extensions/InputHelpExtensionTest.php @@ -24,7 +24,7 @@ protected function setUp(): void $this->inputHelpExtension = new InputHelpExtension($inputHelpLogic); } - public function getIdentProvider(): array + public static function getIdentProvider(): array { return [ [null, 1, false, null], @@ -48,7 +48,7 @@ public function testGetIdent($params, $iLang, $blAdmin, $expected): void $this->assertEquals($expected, $this->inputHelpExtension->getHelpId($params)); } - public function getHelpTextProvider(): array + public static function getHelpTextProvider(): array { return [ [null, 1, false, null], diff --git a/tests/Integration/Extensions/MailtoExtensionTest.php b/tests/Integration/Extensions/MailtoExtensionTest.php index f36ddf0..7c2e03b 100644 --- a/tests/Integration/Extensions/MailtoExtensionTest.php +++ b/tests/Integration/Extensions/MailtoExtensionTest.php @@ -30,7 +30,8 @@ public function testMailto(string $template, string $expected, array $variables $this->assertEquals($expected, $this->getTemplate($template)->render($variables)); } - public function getMailtoTests(): array + //phpcs:disable + public static function getMailtoTests(): array { return [ [ diff --git a/tests/Integration/Extensions/PhpFunctionsExtensionTest.php b/tests/Integration/Extensions/PhpFunctionsExtensionTest.php index 2da94ba..06cecdb 100644 --- a/tests/Integration/Extensions/PhpFunctionsExtensionTest.php +++ b/tests/Integration/Extensions/PhpFunctionsExtensionTest.php @@ -22,7 +22,7 @@ protected function setUp(): void $this->extension = new PhpFunctionsExtension(); } - public function dummyTemplateProvider(): array + public static function dummyTemplateProvider(): array { return [ ["{{ count({0:0, 1:1, 2:2}) }}", 3], diff --git a/tests/Integration/Extensions/ScriptExtensionTest.php b/tests/Integration/Extensions/ScriptExtensionTest.php index fda1dd2..c38d0a1 100644 --- a/tests/Integration/Extensions/ScriptExtensionTest.php +++ b/tests/Integration/Extensions/ScriptExtensionTest.php @@ -32,10 +32,10 @@ public function testScript(string $template, string $expected): void $this->assertEquals($expected, $this->getTemplate($template)->render([])); } - public function getScriptTests(): array + //phpcs:disable + public static function getScriptTests(): array { return [ - // Empty buffer [ "{{ script() }}", "" diff --git a/tests/Integration/Extensions/SmartyCycleExtensionTest.php b/tests/Integration/Extensions/SmartyCycleExtensionTest.php index 63a1eb5..9c66249 100644 --- a/tests/Integration/Extensions/SmartyCycleExtensionTest.php +++ b/tests/Integration/Extensions/SmartyCycleExtensionTest.php @@ -27,7 +27,7 @@ public function testStaticCycle(string $template, string $expected, array $varia $this->assertEquals($expected, $this->getTemplate($template)->render($variables)); } - public function getStaticCycle(): array + public static function getStaticCycle(): array { return [ [ diff --git a/tests/Integration/Extensions/TranslateExtensionTest.php b/tests/Integration/Extensions/TranslateExtensionTest.php index 8c9de71..5273451 100644 --- a/tests/Integration/Extensions/TranslateExtensionTest.php +++ b/tests/Integration/Extensions/TranslateExtensionTest.php @@ -26,7 +26,7 @@ protected function setUp(): void $this->translateExtension = $this->get(TranslateExtension::class); } - public function dataProvider(): array + public static function dataProvider(): array { return [ [['ident' => 'foobar'], 'ERROR: Translation for foobar not found!'], diff --git a/tests/Integration/Extensions/UrlExtensionTest.php b/tests/Integration/Extensions/UrlExtensionTest.php index f8e03c5..b351fd2 100644 --- a/tests/Integration/Extensions/UrlExtensionTest.php +++ b/tests/Integration/Extensions/UrlExtensionTest.php @@ -38,7 +38,7 @@ public function testAddUrlParameters(string $template, string $expected, array $ $this->assertEquals($expected, $this->getTemplate($template)->render($variables)); } - public function getSeoUrlTests(): array + public static function getSeoUrlTests(): array { return [ [ @@ -48,7 +48,7 @@ public function getSeoUrlTests(): array ]; } - public function getAddUrlParametersTests(): array + public static function getAddUrlParametersTests(): array { return [ [ diff --git a/tests/Integration/Resolver/TemplateFileResolverTest.php b/tests/Integration/Resolver/TemplateFileResolverTest.php index 7233846..c7436a5 100644 --- a/tests/Integration/Resolver/TemplateFileResolverTest.php +++ b/tests/Integration/Resolver/TemplateFileResolverTest.php @@ -27,7 +27,7 @@ public function testResolveSmartyTemplate(string $templateName, string $expected $this->assertEquals($expectedFilename, $filename); } - public function templateNameFileDataProvider(): array + public static function templateNameFileDataProvider(): array { return [ [ diff --git a/tests/Integration/TwigEngine/ControllerRender/Fixtures/module1/src/Contoller/ModuleController.php b/tests/Integration/TwigEngine/ControllerRender/Fixtures/module1/src/Contoller/ModuleController.php index 49d0a54..2ed8c30 100644 --- a/tests/Integration/TwigEngine/ControllerRender/Fixtures/module1/src/Contoller/ModuleController.php +++ b/tests/Integration/TwigEngine/ControllerRender/Fixtures/module1/src/Contoller/ModuleController.php @@ -13,5 +13,5 @@ class ModuleController extends FrontendController { - protected $_sThisTemplate = '@module1/module_controller'; + protected $_sThisTemplate = '@module1/module_controller'; //phpcs:disable } diff --git a/tests/Integration/TwigEngine/ControllerRender/Fixtures/module1/src/Contoller/ModuleControllerMissingTemplate.php b/tests/Integration/TwigEngine/ControllerRender/Fixtures/module1/src/Contoller/ModuleControllerMissingTemplate.php index f1aa8ed..5d94b83 100644 --- a/tests/Integration/TwigEngine/ControllerRender/Fixtures/module1/src/Contoller/ModuleControllerMissingTemplate.php +++ b/tests/Integration/TwigEngine/ControllerRender/Fixtures/module1/src/Contoller/ModuleControllerMissingTemplate.php @@ -11,6 +11,7 @@ use OxidEsales\Eshop\Application\Controller\FrontendController; +//phpcs:disable class ModuleControllerMissingTemplate extends FrontendController { protected $_sThisTemplate = '@module1/module_controller_missing_template'; diff --git a/tests/Integration/TwigEngine/TemplateChainSorting/ModulesTemplateChainSortingTest.php b/tests/Integration/TwigEngine/TemplateChainSorting/ModulesTemplateChainSortingTest.php index b8a935d..2e99f2c 100644 --- a/tests/Integration/TwigEngine/TemplateChainSorting/ModulesTemplateChainSortingTest.php +++ b/tests/Integration/TwigEngine/TemplateChainSorting/ModulesTemplateChainSortingTest.php @@ -68,7 +68,7 @@ public function testRenderWithShopTemplateAndSorting(string $sorting, string $ex $this->assertStringContainsString($expectedResult, $actual); } - public function renderShopTemplateDataProvider(): array + public static function renderShopTemplateDataProvider(): array { return [ [ @@ -124,7 +124,7 @@ public function testRenderWithModuleTemplateAndSorting(string $sorting, string $ $this->assertStringContainsString($expectedResult, $actual); } - public function renderModuleTemplateDataProvider(): array + public static function renderModuleTemplateDataProvider(): array { return [ [ @@ -176,7 +176,7 @@ public function testRenderWithShopTemplateAmdFaultySortingConfiguration( $this->assertStringContainsString($expectedResult, $actual); } - public function renderWithShopTemplateAndFaultySortingConfigDataProvider(): array + public static function renderWithShopTemplateAndFaultySortingConfigDataProvider(): array { return [ [ @@ -223,7 +223,7 @@ public function testRenderWithModuleTemplateAndFaultySortingConfiguration( $this->assertStringContainsString($expectedResult, $actual); } - public function renderWithModuleTemplateAndFaultySortingConfigDataProvider(): array + public static function renderWithModuleTemplateAndFaultySortingConfigDataProvider(): array { return [ [ diff --git a/tests/Unit/Escaper/DecEntityEscaperTest.php b/tests/Unit/Escaper/DecEntityEscaperTest.php index c9066b2..bcc19e5 100644 --- a/tests/Unit/Escaper/DecEntityEscaperTest.php +++ b/tests/Unit/Escaper/DecEntityEscaperTest.php @@ -27,12 +27,12 @@ protected function setUp(): void $this->environment = $this->createMock(Environment::class); } - public function escapeProvider(): array + public static function escapeProvider(): array { return [ [ "A 'quote' is bold", - "A 'quote' is <b>bold</b>" + "A 'quote' is <b>bold</b>" //phpcs:disable ] ]; } diff --git a/tests/Unit/Escaper/HexEntityEscaperTest.php b/tests/Unit/Escaper/HexEntityEscaperTest.php index 3c653e1..2f6d839 100644 --- a/tests/Unit/Escaper/HexEntityEscaperTest.php +++ b/tests/Unit/Escaper/HexEntityEscaperTest.php @@ -27,12 +27,12 @@ protected function setUp(): void $this->environment = $this->createMock(Environment::class); } - public function escapeProvider(): array + public static function escapeProvider(): array { return [ [ "A 'quote' is bold", - "A 'quote' is <b>bold</b>" + "A 'quote' is <b>bold</b>" //phpcs:disable ] ]; } diff --git a/tests/Unit/Escaper/HexEscaperTest.php b/tests/Unit/Escaper/HexEscaperTest.php index b0eb5ce..df73a12 100644 --- a/tests/Unit/Escaper/HexEscaperTest.php +++ b/tests/Unit/Escaper/HexEscaperTest.php @@ -27,7 +27,7 @@ protected function setUp(): void $this->environment = $this->createMock(Environment::class); } - public function escapeProvider(): array + public static function escapeProvider(): array { return [ ["A 'quote' is bold", "%41%20%27%71%75%6f%74%65%27%20%69%73%20%3c%62%3e%62%6f%6c%64%3c%2f%62%3e"] diff --git a/tests/Unit/Escaper/HtmlAllEscaperTest.php b/tests/Unit/Escaper/HtmlAllEscaperTest.php index dd2cbef..827f982 100644 --- a/tests/Unit/Escaper/HtmlAllEscaperTest.php +++ b/tests/Unit/Escaper/HtmlAllEscaperTest.php @@ -27,7 +27,7 @@ protected function setUp(): void $this->environment = $this->createMock(Environment::class); } - public function escapeProvider(): array + public static function escapeProvider(): array { return [ ["A 'quote' is bold", "A 'quote' is <b>bold</b>"] diff --git a/tests/Unit/Escaper/MailEscaperTest.php b/tests/Unit/Escaper/MailEscaperTest.php index ce2bd47..2a56e45 100644 --- a/tests/Unit/Escaper/MailEscaperTest.php +++ b/tests/Unit/Escaper/MailEscaperTest.php @@ -27,7 +27,7 @@ protected function setUp(): void $this->environment = $this->createMock(Environment::class); } - public function escapeProvider(): array + public static function escapeProvider(): array { return [ [ diff --git a/tests/Unit/Escaper/NonStdEscaperTest.php b/tests/Unit/Escaper/NonStdEscaperTest.php index 692fb74..5fd5a2d 100644 --- a/tests/Unit/Escaper/NonStdEscaperTest.php +++ b/tests/Unit/Escaper/NonStdEscaperTest.php @@ -27,23 +27,20 @@ protected function setUp(): void $this->environment = $this->createMock(Environment::class); } - public function escapeProvider(): array + public static function escapeProvider(): array { return [ [ "Zażółć 'gęślą' jaźń", - "Zażółć 'gęślÄ…' jaźń" + "Zażółć 'gęślÄ…' jaźń" //phpcs:disable ] ]; } /** - * @param string $string - * @param string $expected - * * @dataProvider escapeProvider */ - public function testEscape($string, $expected) + public function testEscape(string $string, string $expected) { $this->assertEquals($expected, $this->escaper->escape($this->environment, $string, 'UTF-8')); } diff --git a/tests/Unit/Escaper/QuotesEscaperTest.php b/tests/Unit/Escaper/QuotesEscaperTest.php index 891d75e..942fab4 100644 --- a/tests/Unit/Escaper/QuotesEscaperTest.php +++ b/tests/Unit/Escaper/QuotesEscaperTest.php @@ -27,7 +27,7 @@ protected function setUp(): void $this->environment = $this->createMock(Environment::class); } - public function escapeProvider(): array + public static function escapeProvider(): array { return [ ["A 'quote' is bold", "A \'quote\' is bold"] diff --git a/tests/Unit/Escaper/UrlPathInfoEscaperTest.php b/tests/Unit/Escaper/UrlPathInfoEscaperTest.php index 5dac148..085e0f2 100644 --- a/tests/Unit/Escaper/UrlPathInfoEscaperTest.php +++ b/tests/Unit/Escaper/UrlPathInfoEscaperTest.php @@ -27,7 +27,7 @@ protected function setUp(): void $this->environment = $this->createMock(Environment::class); } - public function escapeProvider(): array + public static function escapeProvider(): array { return [ [ diff --git a/tests/Unit/Extensions/Filters/DateFormatExtensionTest.php b/tests/Unit/Extensions/Filters/DateFormatExtensionTest.php index d7c3c01..7f82aff 100644 --- a/tests/Unit/Extensions/Filters/DateFormatExtensionTest.php +++ b/tests/Unit/Extensions/Filters/DateFormatExtensionTest.php @@ -24,7 +24,7 @@ protected function setUp(): void $this->dateFormatExtension = new DateFormatExtension($dateFormatHelper); } - public function provider(): array + public static function provider(): array { return [ diff --git a/tests/Unit/Extensions/Filters/FileSizeExtensionTest.php b/tests/Unit/Extensions/Filters/FileSizeExtensionTest.php index e19ab03..db69e58 100644 --- a/tests/Unit/Extensions/Filters/FileSizeExtensionTest.php +++ b/tests/Unit/Extensions/Filters/FileSizeExtensionTest.php @@ -15,7 +15,7 @@ final class FileSizeExtensionTest extends TestCase { - public function provider() + public static function provider() { return [ [1023, '1023 B'], diff --git a/tests/Unit/Extensions/Filters/FormatTimeExtensionTest.php b/tests/Unit/Extensions/Filters/FormatTimeExtensionTest.php index 4d8c00e..c021ac3 100644 --- a/tests/Unit/Extensions/Filters/FormatTimeExtensionTest.php +++ b/tests/Unit/Extensions/Filters/FormatTimeExtensionTest.php @@ -15,7 +15,7 @@ final class FormatTimeExtensionTest extends TestCase { - public function provider(): array + public static function provider(): array { return [ [0, '00:00:00'], diff --git a/tests/Unit/Extensions/Filters/SmartWordwrapExtensionTest.php b/tests/Unit/Extensions/Filters/SmartWordwrapExtensionTest.php index 8599740..0368029 100644 --- a/tests/Unit/Extensions/Filters/SmartWordwrapExtensionTest.php +++ b/tests/Unit/Extensions/Filters/SmartWordwrapExtensionTest.php @@ -14,9 +14,10 @@ use OxidEsales\EshopCommunity\Tests\Unit\Application\Controller\contentTest_oxUtilsView; use PHPUnit\Framework\TestCase; +//phpcs:disable final class SmartWordwrapExtensionTest extends TestCase { - public function provider() + public static function provider() { return [ [ diff --git a/tests/Unit/Extensions/IncludeExtensionTest.php b/tests/Unit/Extensions/IncludeExtensionTest.php index 503d1ab..7476acf 100644 --- a/tests/Unit/Extensions/IncludeExtensionTest.php +++ b/tests/Unit/Extensions/IncludeExtensionTest.php @@ -19,7 +19,6 @@ final class IncludeExtensionTest extends TestCase { use ProphecyTrait; - /** @var IncludeExtension */ private IncludeExtension $includeExtension; public function setUp(): void @@ -39,7 +38,7 @@ public function testIncludeDynamicPrefix(array $parameters, array $expected): vo $this->assertEquals($this->includeExtension->includeDynamicPrefix($parameters), $expected); } - public function dataProviderTestIncludeDynamicPrefix(): array + public static function dataProviderTestIncludeDynamicPrefix(): array { return [ [[], []], @@ -63,7 +62,7 @@ public function testRenderForCache(array $parameters, string $expected): void $this->assertEquals($this->includeExtension->renderForCache($parameters), $expected); } - public function dataProviderTestRenderForCache(): array + public static function dataProviderTestRenderForCache(): array { return [ [[], ''], diff --git a/tests/Unit/Extensions/StyleExtensionTest.php b/tests/Unit/Extensions/StyleExtensionTest.php index c001e80..b0ad5f6 100644 --- a/tests/Unit/Extensions/StyleExtensionTest.php +++ b/tests/Unit/Extensions/StyleExtensionTest.php @@ -31,7 +31,7 @@ public function testCollectStyleSheets($params, $isDynamic): void $styleExtension->style($env, $params); } - public function dataProvider(): array + public static function dataProvider(): array { return [ [['foo' => 'bar', '__oxid_include_dynamic' => true], true], diff --git a/tests/Unit/Loader/CmsLoaderTest.php b/tests/Unit/Loader/CmsLoaderTest.php index b92d74c..c5e05e4 100644 --- a/tests/Unit/Loader/CmsLoaderTest.php +++ b/tests/Unit/Loader/CmsLoaderTest.php @@ -26,7 +26,7 @@ final class CmsLoaderTest extends TestCase public function setUp(): void { parent::setUp(); - $this->contentMockBuilder = $this->getMockBuilder(Content::class)->setMethods(['getLanguage']); + $this->contentMockBuilder = $this->getMockBuilder(Content::class)->onlyMethods(['getLanguage']); $validContentMock = $this->prepareContentMock( 0, @@ -40,7 +40,10 @@ public function setUp(): void $fieldContentMock = $this->prepareContentMock( 0, - ['oxactive' => true, 'customfield' => "Template code (custom field)", 'oxtimestamp' => '2018-10-09 09:32:06'] + [ + 'oxactive' => true, + 'customfield' => "Template code (custom field)", 'oxtimestamp' => '2018-10-09 09:32:06' + ] ); $notFreshContentMock = $this->prepareContentMock( @@ -52,7 +55,7 @@ public function setUp(): void $contentFactoryMock = $this ->getMockBuilder(ContentFactory::class) - ->setMethods(['getContent']) + ->onlyMethods(['getContent']) ->getMock(); $contentFactoryMock diff --git a/tests/Unit/Loader/CmsTemplateNameParserTest.php b/tests/Unit/Loader/CmsTemplateNameParserTest.php index 86210c0..46c8676 100644 --- a/tests/Unit/Loader/CmsTemplateNameParserTest.php +++ b/tests/Unit/Loader/CmsTemplateNameParserTest.php @@ -72,7 +72,7 @@ public function testGetKey(string $name, array $expected): void $this->assertEquals($this->cmsTemplateNameParser->getKey($name), $expected['key']); } - public function getInvalidNameTests(): array + public static function getInvalidNameTests(): array { $invalidNames = [ '', @@ -93,7 +93,7 @@ public function getInvalidNameTests(): array ); } - public function getValidNameTests(): array + public static function getValidNameTests(): array { return [ [ diff --git a/tests/Unit/Node/AbstractOxidTwigTestCase.php b/tests/Unit/Node/AbstractOxidTwigTestCase.php new file mode 100644 index 0000000..6bc4e38 --- /dev/null +++ b/tests/Unit/Node/AbstractOxidTwigTestCase.php @@ -0,0 +1,29 @@ +assertNodeCompilation($source, $node, $environment, $isPattern); + } +} diff --git a/tests/Unit/Node/CaptureNodeTest.php b/tests/Unit/Node/CaptureNodeTest.php index 2c42b39..09d0903 100644 --- a/tests/Unit/Node/CaptureNodeTest.php +++ b/tests/Unit/Node/CaptureNodeTest.php @@ -5,35 +5,28 @@ * See LICENSE file for license details. */ +declare(strict_types=1); + namespace OxidEsales\Twig\Tests\Unit\Node; use OxidEsales\Twig\Node\CaptureNode; use Twig\Node\TextNode; -use Twig\Test\NodeTestCase; -final class CaptureNodeTest extends NodeTestCase +final class CaptureNodeTest extends AbstractOxidTwigTestCase { - private string $variableName = 'foo'; - private int $line = 1; - private string $tag = 'capture'; - private $body; - - public function __construct($name = null, array $data = [], $dataName = '') - { - parent::__construct($name, $data, $dataName); - $this->body = new TextNode("Lorem Ipsum", 1); - } - - public function getTests() + public static function getOxidTwigTests(): array { - return array_merge($this->getTestForCaptureWithAttributeName(), $this->getTestForCaptureWithAttributeAssign(), $this->getTestForCaptureWithAttributeAppend()); + return array_merge( + self::getTestForCaptureWithAttributeName(), + self::getTestForCaptureWithAttributeAssign(), + self::getTestForCaptureWithAttributeAppend() + ); } - private function getTestForCaptureWithAttributeName() + private static function getTestForCaptureWithAttributeName(): array { $tests = []; - $nodeForCaptureName = new CaptureNode('name', $this->variableName, $this->body, $this->line, $this->tag); - + $nodeForCaptureName = self::getCaptureNode('name'); $tests[] = [$nodeForCaptureName, <<variableName, $this->body, $this->line, $this->tag); + $nodeForCaptureAssign = self::getCaptureNode('assign'); $tests[] = [$nodeForCaptureAssign, <<variableName, $this->body, $this->line, $this->tag); - $tests[] = [$nodeForCaptureAssign, <<assertEquals($parametersNode, $node->getNode('parameters')); } - public function getTests(): array + public static function getOxidTwigTests(): array { - return array_merge($this->getNonNestedBlocksTests(), $this->getNestedBlocksTests()); + return array_merge( + self::getNonNestedBlocksTests(), + self::getNestedBlocksTests() + ); } - private function getNonNestedBlocksTests(): array + private static function getNonNestedBlocksTests(): array { $tests = []; @@ -57,7 +59,7 @@ private function getNonNestedBlocksTests(): array return $tests; } - private function getNestedBlocksTests(): array + private static function getNestedBlocksTests(): array { $tests = []; diff --git a/tests/Unit/Node/IfContentNodeTest.php b/tests/Unit/Node/IfContentNodeTest.php index 9f56ea6..f960aaa 100644 --- a/tests/Unit/Node/IfContentNodeTest.php +++ b/tests/Unit/Node/IfContentNodeTest.php @@ -14,9 +14,8 @@ use Twig\Node\Expression\AssignNameExpression; use Twig\Node\Expression\ConstantExpression; use Twig\Node\TextNode; -use Twig\Test\NodeTestCase; -final class IfContentNodeTest extends NodeTestCase +final class IfContentNodeTest extends AbstractOxidTwigTestCase { public function testConstructor(): void { @@ -38,7 +37,7 @@ public function testConstructor(): void $this->assertFalse($node->hasNode('ident')); } - public function getTests(): array + public static function getOxidTwigTests(): array { $ifContentExtensionClass = IfContentExtension::class; diff --git a/tests/Unit/Node/IncludeDynamicNodeTest.php b/tests/Unit/Node/IncludeDynamicNodeTest.php index e43cbb0..598099b 100644 --- a/tests/Unit/Node/IncludeDynamicNodeTest.php +++ b/tests/Unit/Node/IncludeDynamicNodeTest.php @@ -13,9 +13,8 @@ use OxidEsales\Twig\Node\IncludeDynamicNode; use Twig\Node\Expression\ArrayExpression; use Twig\Node\Expression\ConstantExpression; -use Twig\Test\NodeTestCase; -final class IncludeDynamicNodeTest extends NodeTestCase +final class IncludeDynamicNodeTest extends AbstractOxidTwigTestCase { public function testConstructor(): void { @@ -26,13 +25,21 @@ public function testConstructor(): void $this->assertEquals($expr, $node->getNode('expr')); $this->assertFalse($node->getAttribute('only')); - $vars = new ArrayExpression([new ConstantExpression('foo', 1), new ConstantExpression(true, 1)], 1); + $vars = new ArrayExpression( + [ + new ConstantExpression('foo', 1), + new ConstantExpression(true, 1) + ], + 1 + ); + $node = new IncludeDynamicNode($expr, $vars, true, false, 1); $this->assertEquals($vars, $node->getNode('variables')); $this->assertTrue($node->getAttribute('only')); } - public function getTests(): array + //phpcs:disable + public static function getOxidTwigTests(): array { $includeExtensionClass = IncludeExtension::class; @@ -51,7 +58,13 @@ public function getTests(): array ]; $expr = new ConstantExpression('foo.twig', 1); - $vars = new ArrayExpression([new ConstantExpression('foo', 1), new ConstantExpression(true, 1)], 1); + $vars = new ArrayExpression( + [ + new ConstantExpression('foo', 1), + new ConstantExpression(true, 1) + ], + 1 + ); $node = new IncludeDynamicNode($expr, $vars, false, false, 1); $tests[] = [$node, <<modulePathResolver->getFullModulePathFromConfiguration($moduleId1, $this->shopId)->willReturn($modulePath1); + $this->modulePathResolver + ->getFullModulePathFromConfiguration($moduleId1, $this->shopId) + ->willReturn($modulePath1); $this->activeModulesDataProvider->getModuleIds()->willReturn([$moduleId1]); @@ -66,7 +68,9 @@ public function testGetTemplateDirectoriesWith1ModuleAnd1ExistingTemplate(): voi $modulePath1 = 'module-path-1'; $moduleTemplateDirectory1 = "$modulePath1/views/twig"; - $this->modulePathResolver->getFullModulePathFromConfiguration($moduleId1, $this->shopId)->willReturn($modulePath1); + $this->modulePathResolver + ->getFullModulePathFromConfiguration($moduleId1, $this->shopId) + ->willReturn($modulePath1); $this->activeModulesDataProvider->getModuleIds()->willReturn([$moduleId1]); @@ -86,8 +90,12 @@ public function testGetTemplateDirectoriesWith2ModulesAnd2ExistingTemplates(): v $moduleTemplateDirectory1 = "$modulePath1/views/twig"; $moduleTemplateDirectory2 = "$modulePath2/views/twig"; - $this->modulePathResolver->getFullModulePathFromConfiguration($moduleId1, $this->shopId)->willReturn($modulePath1); - $this->modulePathResolver->getFullModulePathFromConfiguration($moduleId2, $this->shopId)->willReturn($modulePath2); + $this->modulePathResolver + ->getFullModulePathFromConfiguration($moduleId1, $this->shopId) + ->willReturn($modulePath1); + $this->modulePathResolver + ->getFullModulePathFromConfiguration($moduleId2, $this->shopId) + ->willReturn($modulePath2); $this->activeModulesDataProvider->getModuleIds()->willReturn([$moduleId1, $moduleId2]); @@ -111,9 +119,12 @@ public function testGetTemplateDirectoriesWith3ModulesAnd1ExistingTemplate(): vo $moduleTemplateDirectory2 = "$modulePath2/views/twig"; $moduleTemplateDirectory3 = "$modulePath3/views/twig"; - $this->modulePathResolver->getFullModulePathFromConfiguration($moduleId1, $this->shopId)->willReturn($modulePath1); - $this->modulePathResolver->getFullModulePathFromConfiguration($moduleId2, $this->shopId)->willReturn($modulePath2); - $this->modulePathResolver->getFullModulePathFromConfiguration($moduleId3, $this->shopId)->willReturn($modulePath3); + $this->modulePathResolver + ->getFullModulePathFromConfiguration($moduleId1, $this->shopId)->willReturn($modulePath1); + $this->modulePathResolver + ->getFullModulePathFromConfiguration($moduleId2, $this->shopId)->willReturn($modulePath2); + $this->modulePathResolver + ->getFullModulePathFromConfiguration($moduleId3, $this->shopId)->willReturn($modulePath3); $this->activeModulesDataProvider->getModuleIds()->willReturn([$moduleId1, $moduleId2, $moduleId3]); diff --git a/tests/Unit/TokenParser/CaptureTokenParserTest.php b/tests/Unit/TokenParser/CaptureTokenParserTest.php index 90b2dc9..c8fdb8c 100644 --- a/tests/Unit/TokenParser/CaptureTokenParserTest.php +++ b/tests/Unit/TokenParser/CaptureTokenParserTest.php @@ -80,7 +80,7 @@ public function testParse($source): void $this->assertTrue($ifContentNode->hasNode('body')); } - public function templateSourceCodeProvider(): array + public static function templateSourceCodeProvider(): array { return [ ["{% capture name = \"foo\" %}Lorem Ipsum{% endcapture %}"], @@ -110,7 +110,7 @@ public function testParseException(): void $stream = $this->environment->tokenize(new Source($source, 'index')); $this->expectException(SyntaxError::class); - $this->expectExceptionMessage("Incorrect attribute name. Possible attribute names are: 'name', 'assign' and 'append'"); + $this->expectExceptionMessage("Incorrect attribute name. Possible attribute names are: 'name', 'assign' and 'append'"); //phpcs:disable $this->parser->parse($stream); } } diff --git a/tests/Unit/TokenParser/HasRightsTokenParserTest.php b/tests/Unit/TokenParser/HasRightsTokenParserTest.php index 4bbca3e..0f48343 100644 --- a/tests/Unit/TokenParser/HasRightsTokenParserTest.php +++ b/tests/Unit/TokenParser/HasRightsTokenParserTest.php @@ -71,7 +71,9 @@ public function testParse(): void $env = new Environment($loader, array('cache' => false, 'autoescape' => false)); $env->addExtension(new HasRightsExtension(new HasRightsTokenParser(HasRightsNode::class))); - $stream = $env->parse($env->tokenize(new Source('{% hasrights {\'id\' : \'1\'} %}{% endhasrights %}', 'index'))); + $stream = $env->parse( + $env->tokenize(new Source('{% hasrights {\'id\' : \'1\'} %}{% endhasrights %}', 'index')) + ); $stream->compile(new Compiler($env)); $tags = []; @@ -95,7 +97,7 @@ public function testParseException(): void $env->addExtension(new HasRightsExtension(new HasRightsTokenParser(HasRightsNode::class))); $this->expectException(SyntaxError::class); - $this->expectExceptionMessage('Unexpected "foo" tag (expecting closing tag for the "hasrights" tag defined near line 1) in "index" at line 1.'); + $this->expectExceptionMessage('Unexpected "foo" tag (expecting closing tag for the "hasrights" tag defined near line 1) in "index" at line 1.'); //phpcs:disable $env->parse($env->tokenize(new Source('{% hasrights {\'id\' : \'1\'} %}{% foo %}', 'index'))); }