diff --git a/.github/actions/run-e2e/action.yml b/.github/actions/run-e2e/action.yml index 974d3fee0..0cc6baa44 100644 --- a/.github/actions/run-e2e/action.yml +++ b/.github/actions/run-e2e/action.yml @@ -137,6 +137,13 @@ runs: docker exec shop bash -c 'php bin/console dal:validate' # -------------------------------------------------------------------------------------------------------------------------------------- + - name: Integration Tests + shell: bash + run: | + docker exec shop bash -c 'cd /var/www/html/custom/plugins/MolliPayments && make phpintegration' + # -------------------------------------------------------------------------------------------------------------------------------------- + + - name: Install Cypress if: ${{ inputs.RUN_CYPRESS == 'true' }} diff --git a/.php_cs.php b/.php_cs.php index 2bf465fe7..501ba9681 100644 --- a/.php_cs.php +++ b/.php_cs.php @@ -2,6 +2,7 @@ $finder = \PhpCsFixer\Finder::create()->in([ __DIR__ . '/src', + __DIR__ . '/shopware', __DIR__.'/tests/PHPUnit', ]); diff --git a/CHANGELOG.md b/CHANGELOG.md index f90826c78..5e5f215a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,4 +10,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Features - Return over Shopware Commercial plugins is now transfered to Mollie when the Return status is set to "Done" and can be cancelled with the "Cancelled" status. Please note that the refund cannot be cancelled after two hours. ### Changes -- Minimum Supported Shopware version is now 6.4.5.0 \ No newline at end of file +- Minimum Supported Shopware version is now 6.4.5.0 +- Add new monolog channel "mollie". You can now add custom handler and assign them to the mollie channel \ No newline at end of file diff --git a/composer.json b/composer.json index efd20eb58..68f824998 100644 --- a/composer.json +++ b/composer.json @@ -42,12 +42,15 @@ }, "autoload": { "psr-4": { + "Mollie\\Shopware\\": "shopware/", "Kiener\\MolliePayments\\": "src/", "Mollie\\Api\\": "vendor_manual/mollie/mollie-api-php/src/" } }, "autoload-dev": { "psr-4": { + "Mollie\\Unit\\": "tests/Unit/", + "Mollie\\Integration\\": "tests/Integration/", "MolliePayments\\Tests\\": "tests/PHPUnit/", "MolliePayments\\PHPStan\\": "tests/PHPStan/", "MolliePayments\\Fixtures\\": "tests/Fixtures/" @@ -70,7 +73,7 @@ "shopware/elasticsearch": "*" }, "require-dev": { - "phpunit/phpunit": "^9.5", + "phpunit/phpunit": "^9", "phpstan/phpstan": "1.10.0", "friendsofphp/php-cs-fixer": "^2.18", "phpcompatibility/php-compatibility": "^9.3", diff --git a/makefile b/makefile index e2debaeff..a4f14671c 100644 --- a/makefile +++ b/makefile @@ -94,10 +94,13 @@ stan: ##2 Starts the PHPStan Analyser @php vendor/bin/phpstan analyse -c ./.phpstan.neon phpunit: ##2 Starts all PHPUnit Tests - @XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration=phpunit.xml --coverage-html ./.reports/phpunit/coverage + @XDEBUG_MODE=coverage php vendor/bin/phpunit --testsuite unit --configuration=phpunit.xml + +phpintergration: ##2 Starts all PHPUnit Tests + @XDEBUG_MODE=coverage cd ../../.. && php vendor/bin/phpunit --testsuite integration --configuration=custom/plugins/MolliePayments/phpunit.xml infection: ##2 Starts all Infection/Mutation tests - @XDEBUG_MODE=coverage php vendor/bin/infection --configuration=./.infection.json --log-verbosity=all --debug + @XDEBUG_MODE=coverage php vendor/bin/infection --configuration=./.infection.json --log-verbosity=all --debug --test-framework-options="--testsuite=unit --no-coverage" insights: ##2 Starts the PHPInsights Analyser @php vendor/bin/phpinsights analyse --no-interaction @@ -151,6 +154,7 @@ pr: ##2 Prepares everything for a Pull Request @make phpmin -B @make stan -B @make phpunit -B + @make phpintergration -B @make jest -B @make eslint mode=no-dry-run -B @make stylelint -B diff --git a/phpunit.xml b/phpunit.xml index 23ea1e636..30f260190 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,23 +1,35 @@ + + + + + + + - + ./tests/PHPUnit + ./tests/Unit + + + ./tests/Integration - + - ./src + ./src + ./shopware + diff --git a/polyfill/Shopware/Core/Content/Flow/Dispatching/Aware/ScalarValuesAware.php b/polyfill/Shopware/Core/Content/Flow/Dispatching/Aware/ScalarValuesAware.php new file mode 100644 index 000000000..b6fced9ab --- /dev/null +++ b/polyfill/Shopware/Core/Content/Flow/Dispatching/Aware/ScalarValuesAware.php @@ -0,0 +1,18 @@ +|null> + */ + public function getValues(): array; +} diff --git a/shopware/Component/Logger/PluginSettingsHandler.php b/shopware/Component/Logger/PluginSettingsHandler.php new file mode 100644 index 000000000..12e8122f6 --- /dev/null +++ b/shopware/Component/Logger/PluginSettingsHandler.php @@ -0,0 +1,83 @@ +connection = $connection; + $this->filePath = $filePath; + $this->settingsService = $settingsService; + } + + /** + * We need to define types here because shopware 6.4 uses old monologger where LogRecord does not exists. + * @param array|LogRecord $record + * @return bool + */ + public function handle($record): bool + { + if ($this->isConnected() === false) { + return false; + } + + $channel = $record['channel'] ?? null; + if ($channel !== self::LOG_CHANNEL) { + return false; + } + + + if ($this->fileHandler === null) { + $this->fileHandler = $this->initializeHandler(); + } + + $this->fileHandler->handle($record); + + return $this->bubble === false; + } + + private function isConnected(): bool + { + if ($this->connectedCache !== null) { + return $this->connectedCache; + } + + $this->connectedCache = $this->connection->isConnected(); + return $this->connectedCache; + } + + private function initializeHandler(): AbstractHandler + { + $loggerSettings = $this->settingsService->getLoggerSettings(); + + $logLevel = $loggerSettings->isDebugMode() ? LogLevel::DEBUG : LogLevel::INFO; + $maxFiles = $loggerSettings->getLogFileDays(); + return new RotatingFileHandler($this->filePath, $maxFiles, $logLevel); + } +} diff --git a/shopware/Component/Logger/RecordAnonymizer.php b/shopware/Component/Logger/RecordAnonymizer.php new file mode 100644 index 000000000..2f6a0d49f --- /dev/null +++ b/shopware/Component/Logger/RecordAnonymizer.php @@ -0,0 +1,49 @@ +anonymize($record['extra']['url']); + } + } + return $record; + } +} diff --git a/shopware/Component/Logger/Resources/config/services.xml b/shopware/Component/Logger/Resources/config/services.xml new file mode 100644 index 000000000..127b68f72 --- /dev/null +++ b/shopware/Component/Logger/Resources/config/services.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + %kernel.logs_dir%/mollie_%kernel.environment%.log + + + \ No newline at end of file diff --git a/shopware/Component/Settings/AbstractSettingsService.php b/shopware/Component/Settings/AbstractSettingsService.php new file mode 100644 index 000000000..fda2aef8e --- /dev/null +++ b/shopware/Component/Settings/AbstractSettingsService.php @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/shopware/Component/Settings/SettingsService.php b/shopware/Component/Settings/SettingsService.php new file mode 100644 index 000000000..f3440a5f7 --- /dev/null +++ b/shopware/Component/Settings/SettingsService.php @@ -0,0 +1,60 @@ +systemConfigService = $systemConfigService; + } + + public function getDecorated(): AbstractSettingsService + { + throw new DecorationPatternException(self::class); + } + + public function getLoggerSettings(?string $salesChannelId = null): LoggerSettings + { + $cacheKey = self::CACHE_KEY_LOGGER . '_' . ($salesChannelId ?? 'all'); + + if (isset($this->settingsCache[$cacheKey])) { + return $this->settingsCache[$cacheKey]; + } + + + $shopwareSettings = $this->getShopwareSettings($salesChannelId); + $loggerSettings = LoggerSettings::createFromShopwareArray($shopwareSettings); + $this->settingsCache[$cacheKey] = $loggerSettings; + + return $loggerSettings; + } + + private function getShopwareSettings(?string $salesChannelId = null): array + { + $cacheKey = self::CACHE_KEY_SHOPWARE . '_' . ($salesChannelId ?? 'all'); + + if (isset($this->settingsCache[$cacheKey])) { + return $this->settingsCache[$cacheKey]; + } + + $shopwareSettingsArray = $this->systemConfigService->get(self::SYSTEM_CONFIG_DOMAIN, $salesChannelId); + $this->settingsCache[$cacheKey] = $shopwareSettingsArray; + return $shopwareSettingsArray; + } +} diff --git a/shopware/Component/Settings/Struct/LoggerSettings.php b/shopware/Component/Settings/Struct/LoggerSettings.php new file mode 100644 index 000000000..c50485879 --- /dev/null +++ b/shopware/Component/Settings/Struct/LoggerSettings.php @@ -0,0 +1,43 @@ +isDebugMode = $isDebugMode; + $this->logFileDays = $logFileDays; + } + + public static function createFromShopwareArray(array $settings): LoggerSettings + { + $logFileDays = $settings[self::KEY_LOG_FILE_DAYS] ?? 0; + $debugMode = $settings[self::KEY_DEBUG_MODE] ?? false; + + return new LoggerSettings($debugMode, $logFileDays); + } + + public function isDebugMode(): bool + { + return $this->isDebugMode === true; + } + + public function getLogFileDays(): int + { + return $this->logFileDays; + } +} diff --git a/shopware/README.md b/shopware/README.md new file mode 100644 index 000000000..6a48a77e3 --- /dev/null +++ b/shopware/README.md @@ -0,0 +1,3 @@ +# New Namespace + +This directory will become new source, we want to refactor and move all classes from src into shopware in order to cleanup the namespace \ No newline at end of file diff --git a/shopware/Resources/config/services.xml b/shopware/Resources/config/services.xml new file mode 100644 index 000000000..3eb09e0ee --- /dev/null +++ b/shopware/Resources/config/services.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/src/Compatibility/Bundles/FlowBuilder/FlowBuilderFactory.php b/src/Compatibility/Bundles/FlowBuilder/FlowBuilderFactory.php index 334567dd3..6203a9ead 100644 --- a/src/Compatibility/Bundles/FlowBuilder/FlowBuilderFactory.php +++ b/src/Compatibility/Bundles/FlowBuilder/FlowBuilderFactory.php @@ -56,7 +56,7 @@ public function createDispatcher(): FlowBuilderDispatcherAdapterInterface return new ShopwareFlowBuilderDispatcher65($this->flowDispatcher); } - if ($this->versionCompare->lt(self::FLOW_BUILDER_MIN_VERSION)) { + if ($this->versionCompare->gt(self::FLOW_BUILDER_MIN_VERSION)) { return new DummyFlowBuilderDispatcher(); } diff --git a/src/Resources/config/compatibility/flowbuilder/6.4.6.0.xml b/src/Resources/config/compatibility/flowbuilder/6.4.6.0.xml index 5a87686ef..890710fc2 100644 --- a/src/Resources/config/compatibility/flowbuilder/6.4.6.0.xml +++ b/src/Resources/config/compatibility/flowbuilder/6.4.6.0.xml @@ -10,7 +10,7 @@ - + @@ -18,7 +18,7 @@ - + diff --git a/src/Resources/config/config.xml b/src/Resources/config/config.xml index a77198131..a903cb061 100644 --- a/src/Resources/config/config.xml +++ b/src/Resources/config/config.xml @@ -44,6 +44,15 @@ Staat de test modus toe met de Mollie Sandbox betalingspagina. De Storefront zal ook "(Test Mode)" tonen naast de naam van de betaalmethode. Abilita la modalità test con la pagina di pagamento di Mollie Sandbox. Lo Storefront mostrerà anche (Modalità test) accanto ai nomi dei metodi di pagamento. + + molliePluginConfigSectionApi + + + + Logger + Logger + Logger + Logger debugMode @@ -68,9 +77,6 @@ Stel het aantal dagen in hoe lang logbestanden worden bewaard totdat ze automatisch worden verwijderd. Imposta il numero di giorni per quanto tempo i file di log devono essere conservati prima di essere automaticamente eliminati. - - molliePluginConfigSectionApi - Payments diff --git a/src/Resources/config/packages/monolog.xml b/src/Resources/config/packages/monolog.xml new file mode 100644 index 000000000..3f3cd7ce1 --- /dev/null +++ b/src/Resources/config/packages/monolog.xml @@ -0,0 +1,21 @@ + + + + mollie + + + + \ No newline at end of file diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 936ac6257..db56f5b28 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -23,6 +23,8 @@ + + @@ -46,7 +48,7 @@ - + @@ -54,7 +56,7 @@ - + @@ -72,7 +74,7 @@ - + @@ -117,7 +119,7 @@ - + @@ -158,7 +160,7 @@ - + @@ -199,7 +201,7 @@ - + diff --git a/src/Resources/config/services/api.xml b/src/Resources/config/services/api.xml index 70d93c2b7..65d3a603f 100644 --- a/src/Resources/config/services/api.xml +++ b/src/Resources/config/services/api.xml @@ -12,7 +12,7 @@ %kernel.shopware_version% - + @@ -24,7 +24,7 @@ - + diff --git a/src/Resources/config/services/builder.xml b/src/Resources/config/services/builder.xml index ff974da4d..fc8aface6 100644 --- a/src/Resources/config/services/builder.xml +++ b/src/Resources/config/services/builder.xml @@ -16,7 +16,7 @@ - + diff --git a/src/Resources/config/services/commands.xml b/src/Resources/config/services/commands.xml index 80dcc3aed..5ea7ff5a1 100644 --- a/src/Resources/config/services/commands.xml +++ b/src/Resources/config/services/commands.xml @@ -8,26 +8,26 @@ - + - + - + - + diff --git a/src/Resources/config/services/components.xml b/src/Resources/config/services/components.xml index 6da8cc788..c998e5806 100644 --- a/src/Resources/config/services/components.xml +++ b/src/Resources/config/services/components.xml @@ -16,7 +16,7 @@ - + @@ -29,7 +29,7 @@ - + @@ -90,7 +90,7 @@ - + diff --git a/src/Resources/config/services/controller.xml b/src/Resources/config/services/controller.xml index 0070aee3b..3066c1195 100644 --- a/src/Resources/config/services/controller.xml +++ b/src/Resources/config/services/controller.xml @@ -50,7 +50,7 @@ - + @@ -71,7 +71,7 @@ - + @@ -82,7 +82,7 @@ - + @@ -92,7 +92,7 @@ - + @@ -113,7 +113,7 @@ - + @@ -155,7 +155,7 @@ - + @@ -173,7 +173,7 @@ - + @@ -183,7 +183,7 @@ - + @@ -207,7 +207,7 @@ - + @@ -224,7 +224,7 @@ - + @@ -236,7 +236,7 @@ - + @@ -251,13 +251,13 @@ - + - + @@ -271,7 +271,7 @@ - + diff --git a/src/Resources/config/services/facades.xml b/src/Resources/config/services/facades.xml index 90a0ae218..f081d5077 100644 --- a/src/Resources/config/services/facades.xml +++ b/src/Resources/config/services/facades.xml @@ -14,7 +14,7 @@ - + @@ -28,7 +28,7 @@ - + @@ -51,7 +51,7 @@ - + diff --git a/src/Resources/config/services/fixtures/fixtures.xml b/src/Resources/config/services/fixtures/fixtures.xml index f06bebcf6..74eafaac1 100644 --- a/src/Resources/config/services/fixtures/fixtures.xml +++ b/src/Resources/config/services/fixtures/fixtures.xml @@ -8,7 +8,7 @@ - + diff --git a/src/Resources/config/services/handlers.xml b/src/Resources/config/services/handlers.xml index d9a8d8eda..994b8f90a 100644 --- a/src/Resources/config/services/handlers.xml +++ b/src/Resources/config/services/handlers.xml @@ -8,28 +8,28 @@ - + - + - + - + @@ -37,21 +37,21 @@ - + - + - + @@ -59,21 +59,21 @@ - + - + - + @@ -81,133 +81,133 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -215,42 +215,42 @@ - + - + - + - + - + - + diff --git a/src/Resources/config/services/payment.xml b/src/Resources/config/services/payment.xml index 24c841615..a739ce679 100644 --- a/src/Resources/config/services/payment.xml +++ b/src/Resources/config/services/payment.xml @@ -12,7 +12,7 @@ - + @@ -25,7 +25,7 @@ - + @@ -37,7 +37,7 @@ - + @@ -50,7 +50,7 @@ - + @@ -62,7 +62,7 @@ - + diff --git a/src/Resources/config/services/scheduled_tasks.xml b/src/Resources/config/services/scheduled_tasks.xml index 6d21e4e74..929cea5fb 100755 --- a/src/Resources/config/services/scheduled_tasks.xml +++ b/src/Resources/config/services/scheduled_tasks.xml @@ -18,14 +18,14 @@ - + - + @@ -36,7 +36,7 @@ - + diff --git a/src/Resources/config/services/services.xml b/src/Resources/config/services/services.xml index 5d7bec58b..fa0536616 100644 --- a/src/Resources/config/services/services.xml +++ b/src/Resources/config/services/services.xml @@ -6,15 +6,6 @@ - - - %kernel.logs_dir%/mollie_%kernel.environment%.log - - - - - - @@ -39,17 +30,17 @@ - + - + - + @@ -60,7 +51,7 @@ - + @@ -70,7 +61,7 @@ - + @@ -95,12 +86,12 @@ - + - + @@ -129,7 +120,7 @@ - + @@ -137,7 +128,7 @@ - + @@ -150,7 +141,7 @@ - + @@ -173,7 +164,7 @@ - + @@ -227,7 +218,7 @@ - + diff --git a/src/Resources/config/services/subscriber.xml b/src/Resources/config/services/subscriber.xml index 394d89a29..269ffb04c 100644 --- a/src/Resources/config/services/subscriber.xml +++ b/src/Resources/config/services/subscriber.xml @@ -11,7 +11,7 @@ - + @@ -19,14 +19,14 @@ - + - + @@ -68,7 +68,7 @@ - + @@ -92,7 +92,7 @@ - + diff --git a/src/Resources/config/services/subscription/services.xml b/src/Resources/config/services/subscription/services.xml index b7c8b6bd9..c6a6fccfd 100755 --- a/src/Resources/config/services/subscription/services.xml +++ b/src/Resources/config/services/subscription/services.xml @@ -47,7 +47,7 @@ - + @@ -113,7 +113,7 @@ - + @@ -128,7 +128,7 @@ - + @@ -142,7 +142,7 @@ - + @@ -157,7 +157,7 @@ - + @@ -174,7 +174,7 @@ - + @@ -190,7 +190,7 @@ - + @@ -204,7 +204,7 @@ - + @@ -218,7 +218,7 @@ - + @@ -232,7 +232,7 @@ - + @@ -246,7 +246,7 @@ - + diff --git a/src/Service/Logger/MollieLoggerFactory.php b/src/Service/Logger/MollieLoggerFactory.php deleted file mode 100644 index f3d7db7c9..000000000 --- a/src/Service/Logger/MollieLoggerFactory.php +++ /dev/null @@ -1,81 +0,0 @@ -settingsService = $settingsService; - $this->filename = $filename; - $this->connection = $connection; - } - - /** - * @return LoggerInterface - */ - public function createLogger(): LoggerInterface - { - if (!$this->connection->isConnected()) { - // deployment server without database - return new Logger(self::CHANNEL); - } - - $config = $this->settingsService->getSettings(); - - # 100 = DEBUG, 200 = INFO - $minLevel = ($config->isDebugMode()) ? 100 : 200; - $retentionDays = $config->getLogFileDays(); - - $fileHandler = new RotatingFileHandler($this->filename, $retentionDays, $minLevel); - - $processors = []; - $processors[] = new AnonymousWebProcessor(new WebProcessor(), new URLAnonymizer()); - $processors[] = new IntrospectionProcessor(); - - /** @var callable $processor */ - foreach ($processors as $processor) { - $fileHandler->pushProcessor($processor); - } - - return new Logger(self::CHANNEL, [$fileHandler]); - } -} diff --git a/src/Service/Logger/Processors/AnonymousWebProcessor.php b/src/Service/Logger/Processors/AnonymousWebProcessor.php deleted file mode 100644 index 8a8d8557a..000000000 --- a/src/Service/Logger/Processors/AnonymousWebProcessor.php +++ /dev/null @@ -1,62 +0,0 @@ -webProcessor = $webProcessor; - $this->urlAnonymizer = $urlAnonymizer; - } - - /** - * attention, if we just skip the data type (array/LogRecord) then it - * works for both monolog versions (old and new) for Shopware 6.4 and 6.5. - * - * @phpstan-param Record $record - * @param mixed $record - * @return array - */ - public function __invoke($record) - { - $record = $this->webProcessor->__invoke($record); - - /** @phpstan-ignore-next-line */ - if (isset($record['extra'])) { - if (array_key_exists('ip', $record['extra'])) { - # replace it with our anonymous IP - $record['extra']['ip'] = IpUtils::anonymize(trim($record['extra']['ip'])); - } - - if (array_key_exists('url', $record['extra'])) { - $record['extra']['url'] = $this->urlAnonymizer->anonymize($record['extra']['url']); - } - } - - return $record; - } -} diff --git a/src/Service/Logger/Services/URLAnonymizer.php b/src/Service/Logger/Services/URLAnonymizer.php deleted file mode 100644 index 7db2624d3..000000000 --- a/src/Service/Logger/Services/URLAnonymizer.php +++ /dev/null @@ -1,23 +0,0 @@ -getContainer()->get(SystemConfigService::class); + $systemConfigService->set(SettingsService::SYSTEM_CONFIG_DOMAIN . '.' . LoggerSettings::KEY_LOG_FILE_DAYS, 10); + $systemConfigService->set(SettingsService::SYSTEM_CONFIG_DOMAIN . '.' . LoggerSettings::KEY_DEBUG_MODE, false); + + $settingsService = new SettingsService($systemConfigService); + + $actualSettings = $settingsService->getLoggerSettings(); + + $this->assertSame(10, $actualSettings->getLogFileDays()); + $this->assertFalse($actualSettings->isDebugMode()); + } + + public function testSettingsAreCachedPerSalesChannel():void + { + + /** + * @var SystemConfigService $systemConfigService + */ + $systemConfigService = $this->getContainer()->get(SystemConfigService::class); + $settingsService = new SettingsService($systemConfigService); + + $expectedSettings = $settingsService->getLoggerSettings(); + $actualSettings = $settingsService->getLoggerSettings(); + $differentSalesChannelSettings = $settingsService->getLoggerSettings(Uuid::randomHex()); + + $this->assertSame($expectedSettings,$actualSettings); + $this->assertNotSame($actualSettings,$differentSalesChannelSettings); + } +} \ No newline at end of file diff --git a/tests/PHPUnit/Components/ApplePayDirect/Services/ApplePayDirectDomainSanitizerTest.php b/tests/PHPUnit/Components/ApplePayDirect/Services/ApplePayDirectDomainSanitizerTest.php index 3a0c5f8f1..689bb09ce 100644 --- a/tests/PHPUnit/Components/ApplePayDirect/Services/ApplePayDirectDomainSanitizerTest.php +++ b/tests/PHPUnit/Components/ApplePayDirect/Services/ApplePayDirectDomainSanitizerTest.php @@ -8,6 +8,7 @@ class ApplePayDirectDomainSanitizerTest extends TestCase { + private ApplePayDirectDomainSanitizer $sanitizer; protected function setUp(): void { $this->sanitizer = new ApplePayDirectDomainSanitizer(); diff --git a/tests/PHPUnit/Service/ApplePayDirect/Models/ApplePayLneItemTest.php b/tests/PHPUnit/Service/ApplePayDirect/Models/ApplePayLineItemTest.php similarity index 94% rename from tests/PHPUnit/Service/ApplePayDirect/Models/ApplePayLneItemTest.php rename to tests/PHPUnit/Service/ApplePayDirect/Models/ApplePayLineItemTest.php index 1cb07d17c..8c434e567 100644 --- a/tests/PHPUnit/Service/ApplePayDirect/Models/ApplePayLneItemTest.php +++ b/tests/PHPUnit/Service/ApplePayDirect/Models/ApplePayLineItemTest.php @@ -1,6 +1,6 @@ dispatcher = $this->createMock(EventDispatcherInterface::class); diff --git a/tests/PHPUnit/Service/Logger/Processors/AnonymousWebProcessorTest.php b/tests/PHPUnit/Service/Logger/Processors/AnonymousWebProcessorTest.php deleted file mode 100644 index fb1360ca7..000000000 --- a/tests/PHPUnit/Service/Logger/Processors/AnonymousWebProcessorTest.php +++ /dev/null @@ -1,96 +0,0 @@ -webProcessor = $this->createMock(ProcessorInterface::class); - $this->urlAnonymizer = $this->createMock(URLAnonymizerInterface::class); - - $this->subject = new AnonymousWebProcessor( - $this->webProcessor, - $this->urlAnonymizer - ); - } - - public function testInvokeCanReturnArrayWithIpV4(): void - { - $url = 'http://someurl'; - $some_array = [ - 'extra' => [ - 'ip' => '127.0.0.1', - 'url' => $url - ] - ]; - - $this->webProcessor->expects($this->once())->method('__invoke') - ->with([]) - ->willReturn($some_array); - - $this->urlAnonymizer->expects($this->once())->method('anonymize') - ->with($url) - ->willReturn($url); - - $this->assertSame( - [ - 'extra' => [ - 'ip' => '127.0.0.0', - 'url' => $url - ] - ], - $this->subject->__invoke([]) - ); - } - - public function testInvokeCanReturnArrayWithIpV6(): void - { - $url = 'http://someurl'; - $some_array = [ - 'extra' => [ - 'ip' => '2001:0db8:85a3:08d3::0370:7344', - 'url' => $url - ] - ]; - - $this->webProcessor->expects($this->once())->method('__invoke') - ->with([]) - ->willReturn($some_array); - - $this->urlAnonymizer->expects($this->once())->method('anonymize') - ->with($url) - ->willReturn($url); - - $this->assertSame( - [ - 'extra' => [ - 'ip' => '2001:db8:85a3:8d3::', - 'url' => $url - ] - ], - $this->subject->__invoke([]) - ); - } -} diff --git a/tests/PHPUnit/Service/Logger/Services/URLAnonymizerTest.php b/tests/PHPUnit/Service/Logger/Services/URLAnonymizerTest.php deleted file mode 100644 index 3214c3e91..000000000 --- a/tests/PHPUnit/Service/Logger/Services/URLAnonymizerTest.php +++ /dev/null @@ -1,23 +0,0 @@ -assertEquals('https://shop.phpunit.mollie/payment/finalize-transaction', $anonymizer->anonymize($url)); - } -} diff --git a/tests/PHPUnit/Subscriber/CheckoutConfirmPageSubscriberTest.php b/tests/PHPUnit/Subscriber/CheckoutConfirmPageSubscriberTest.php index f218b2138..7c298adbb 100644 --- a/tests/PHPUnit/Subscriber/CheckoutConfirmPageSubscriberTest.php +++ b/tests/PHPUnit/Subscriber/CheckoutConfirmPageSubscriberTest.php @@ -27,6 +27,7 @@ class CheckoutConfirmPageSubscriberTest extends TestCase /** @var CheckoutConfirmPage */ private $checkoutConfirmPage; + private PaymentMethodCollection $paymentMethodCollection; /** * Sets up the test. * diff --git a/tests/PHPUnit/Utils/Traits/PaymentBuilderTrait.php b/tests/PHPUnit/Utils/Traits/PaymentBuilderTrait.php index 5796fbbe9..31994ee33 100644 --- a/tests/PHPUnit/Utils/Traits/PaymentBuilderTrait.php +++ b/tests/PHPUnit/Utils/Traits/PaymentBuilderTrait.php @@ -75,7 +75,7 @@ private function getDummyCustomer(CustomerAddressEntity $billing, CustomerAddres * @param null|CurrencyEntity $currency * @return array */ - public function getExpectedLineItems(string $taxStatus, ?OrderLineItemCollection $lineItems = null, CurrencyEntity $currency): array + public function getExpectedLineItems(string $taxStatus, OrderLineItemCollection $lineItems, CurrencyEntity $currency): array { $expectedLineItems = []; @@ -99,7 +99,7 @@ public function getExpectedLineItems(string $taxStatus, ?OrderLineItemCollection return $hydrator->hydrate($expectedLineItems, $currency->getIsoCode()); } - public function getExpectedDeliveries(string $taxStatus, ?OrderDeliveryCollection $deliveries = null, CurrencyEntity $currency): array + public function getExpectedDeliveries(string $taxStatus, OrderDeliveryCollection $deliveries, CurrencyEntity $currency): array { $mollieShippingLineItemBuilder = new MollieShippingLineItemBuilder(new PriceCalculator()); diff --git a/tests/Unit/Logger/FakeSettingsService.php b/tests/Unit/Logger/FakeSettingsService.php new file mode 100644 index 000000000..214eb3ad8 --- /dev/null +++ b/tests/Unit/Logger/FakeSettingsService.php @@ -0,0 +1,29 @@ +settings = $settings; + } + public function getDecorated(): AbstractSettingsService + { + // TODO: Implement getDecorated() method. + } + + public function getLoggerSettings(?string $salesChannelId = null): LoggerSettings + { + return $this->settings; + } +} \ No newline at end of file diff --git a/tests/Unit/Logger/PluginSettingsHandlerTest.php b/tests/Unit/Logger/PluginSettingsHandlerTest.php new file mode 100644 index 000000000..80929c87b --- /dev/null +++ b/tests/Unit/Logger/PluginSettingsHandlerTest.php @@ -0,0 +1,95 @@ +createMock(Connection::class); + $connection->expects($this->once())->method('isConnected')->willReturn(false); + + $handler = new PluginSettingsHandler($fakeSettingsService,$connection,''); + $record = [ + 'message' => 'test' + ]; + $result = $handler->handle($record); + + $this->assertFalse($result); + } + public function testHandleIsFalseForDifferentChannel(): void + { + $fakeSettingsService = new FakeSettingsService(); + + $connection = $this->createMock(Connection::class); + $connection->expects($this->once())->method('isConnected')->willReturn(true); + + $handler = new PluginSettingsHandler($fakeSettingsService,$connection,''); + $record = [ + 'message' => 'test', + 'channel' => 'test' + ]; + $result = $handler->handle($record); + + $this->assertFalse($result); + } + public function testHandleIsFalseFowLowerLogLevel(): void + { + $loggerSettings = new LoggerSettings(false,0); + $fakeSettingsService = new FakeSettingsService($loggerSettings); + + $connection = $this->createMock(Connection::class); + $connection->expects($this->once())->method('isConnected')->willReturn(true); + + $handler = new PluginSettingsHandler($fakeSettingsService,$connection,''); + $record = [ + 'message' => 'test', + 'channel' => 'mollie', + 'level' => LogLevel::DEBUG, + + 'extra'=>[], + 'context'=>[], + 'datetime'=>new \DateTime() + ]; + $result = $handler->handle($record); + + $this->assertFalse($result); + } + public function testHandleIsWorking():void + { + $loggerSettings = new LoggerSettings(true,0); + $fakeSettingsService = new FakeSettingsService($loggerSettings); + + $connection = $this->createMock(Connection::class); + $connection->expects($this->once())->method('isConnected')->willReturn(true); + + $handler = new PluginSettingsHandler($fakeSettingsService,$connection,'',false); + $record = [ + 'message' => 'test', + 'channel' => 'mollie', + 'level' => LogLevel::DEBUG, + + 'extra'=>[], + 'context'=>[], + 'datetime'=>new \DateTime() + ]; + $result = $handler->handle($record); + + $this->assertTrue($result); + } +} \ No newline at end of file diff --git a/tests/Unit/Logger/RecordAnonymizerTest.php b/tests/Unit/Logger/RecordAnonymizerTest.php new file mode 100644 index 000000000..55b90bc24 --- /dev/null +++ b/tests/Unit/Logger/RecordAnonymizerTest.php @@ -0,0 +1,92 @@ +'nothing has changed' + ]; + + $result = $anonymizer($record); + + $this->assertSame($record,$result); + } + + public function testIpIsAnonymized(): void + { + $anonymizer = new RecordAnonymizer(); + + $record = [ + 'message'=>'nothing has changed', + 'extra'=>[ + 'ip'=>'127.0.0.1' + ] + ]; + + $result = $anonymizer($record); + $expected = [ + 'message'=>'nothing has changed', + 'extra' =>[ + 'ip'=>'127.0.0.0' + ] + ]; + $this->assertSame($expected,$result); + } + public function testIpV6IsAnonymized(): void + { + $anonymizer = new RecordAnonymizer(); + + $record = [ + 'message'=>'nothing has changed', + 'extra'=>[ + 'ip'=>'3c3d:d7f6:25ef:29fd:f5b7:1fb1:4241:5208' + ] + ]; + + $result = $anonymizer($record); + $expected = [ + 'message'=>'nothing has changed', + 'extra' =>[ + 'ip'=>'3c3d:d7f6:25ef:29fd::' + ] + ]; + $this->assertSame($expected,$result); + } + public function testUrlParametersAreAnonymized(): void + { + $anonymizer = new RecordAnonymizer(); + + $record = [ + 'message'=>'nothing has changed', + 'extra'=>[ + 'ip'=>'3c3d:d7f6:25ef:29fd:f5b7:1fb1:4241:5208', + 'url'=>'https://shop.phpunit.mollie/payment/finalize-transaction?token=abc' + ] + ]; + + $result = $anonymizer($record); + $expected = [ + 'message'=>'nothing has changed', + 'extra' =>[ + 'ip'=>'3c3d:d7f6:25ef:29fd::', + 'url' => 'https://shop.phpunit.mollie/payment/finalize-transaction' + ] + ]; + $this->assertSame($expected,$result); + } +} \ No newline at end of file diff --git a/tests/bootstrap/functions.php b/tests/bootstrap/functions.php new file mode 100644 index 000000000..97b84c735 --- /dev/null +++ b/tests/bootstrap/functions.php @@ -0,0 +1,37 @@ + $value) { + if (str_starts_with($value, '--')) { + $argumentsWithEqualSign[$index] = $value; + continue; + } + $argumentsWithEqualSign[$index - 1] .= "=" . $value; + } + $parsedArguments = []; + foreach ($argumentsWithEqualSign as $argumentWithEqual) { + $argumentWithEqual = trim(str_replace("-", "", $argumentWithEqual)); + $argumentParts = explode("=", $argumentWithEqual); + $argumentName = $argumentParts[0]; + $argumentValue = true; + if (isset($argumentParts[1])) { + $argumentValue = $argumentParts[1]; + } + + $parsedArguments[$argumentName] = $argumentValue; + } + + if (! isset($parsedArguments[$argument])) { + return $default; + } + return $parsedArguments[$argument]; +} diff --git a/tests/bootstrap/index.php b/tests/bootstrap/index.php new file mode 100644 index 000000000..56a9431a0 --- /dev/null +++ b/tests/bootstrap/index.php @@ -0,0 +1,15 @@ +setProjectDir($projectDir) + ->setPlatformEmbedded(false) + ->addCallingPlugin() + ->addActivePlugins('MolliePayments') + ->setForceInstallPlugins(true) + ->bootstrap() + ->getClassLoader(); + + +$loader->addPsr4('Kiener\\MolliePayments\\', __DIR__ . '/../../src/'); +$loader->addPsr4('Mollie\\Shopware\\', __DIR__ . '/../../shopware/'); +$loader->addPsr4("Shopware\\Core\\", __DIR__ . '/../../polyfill/Shopware/Core/'); +$loader->addPsr4('Mollie\\Integration\\', __DIR__ . '/../Integration/');