From f6a8ae1b844858fe68f85fea9f8db68fcdef1216 Mon Sep 17 00:00:00 2001 From: David Molineus Date: Wed, 7 Feb 2024 09:19:03 +0100 Subject: [PATCH] Allow symfony v6 and work around issues with specs based on Contao models --- .phpcq.lock | 2 +- .phpcq.yaml.dist | 1 + composer.json | 8 +-- phpcs.xml.dist | 1 - psalm.xml | 7 ++- .../Hook/ActivateConsentToolListenerSpec.php | 47 +++++++++-------- .../Hook/GoogleWebfontsListenerSpec.php | 9 +++- .../Hook/RenderComponentsListenerSpec.php | 51 ++++++++++++++----- spec/HofffContaoConsentBridgeBundleSpec.php | 5 +- 9 files changed, 88 insertions(+), 43 deletions(-) diff --git a/.phpcq.lock b/.phpcq.lock index e229ad9..e80739e 100644 --- a/.phpcq.lock +++ b/.phpcq.lock @@ -1 +1 @@ -{"plugins":{"psalm":{"api-version":"1.0.0","version":"1.2.0.0","type":"php-file","url":"https://phpcq.github.io/repository/psalm-1.2.0.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0","ext-dom":"*"},"tool":{"psalm":"^3.0 || ^4.0 || ^5.0"}},"checksum":{"type":"sha-512","value":"4a550c9226d7bca582d7c10bd87cce01190c96398936b1613421640c83df62ed1c6e0d44c1b39635414ea8cf4a892a6458d27590793238add24e7cb5547e6ffd"},"tools":{"psalm":{"version":"5.19.0","url":"https://github.com/vimeo/psalm/releases/download/5.19.0/psalm.phar","requirements":{"php":{"php":"^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0","ext-SimpleXML":"*","ext-ctype":"*","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-tokenizer":"*"}},"checksum":null,"signature":"https://github.com/vimeo/psalm/releases/download/5.19.0/psalm.phar.asc"}},"composerLock":null},"composer-require-checker":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/composer-require-checker-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0"},"tool":{"composer-require-checker":"^3.8 || ^4.0"}},"checksum":{"type":"sha-512","value":"d5415bddfe024c5749d894034583882aee4e5c3e1087815d9fdd81cb5e71630f631a0e35de0ff84b97fbbf738c16ece5f83bd8c00695913eb846aa6f04577dc2"},"tools":{"composer-require-checker":{"version":"4.8.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.8.0/composer-require-checker.phar","requirements":{"php":{"php":"~8.2.0 || ~8.3.0","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.8.0/composer-require-checker.phar.asc"}},"composerLock":null},"phpmd":{"api-version":"1.0.0","version":"1.0.2.0","type":"php-file","url":"https://phpcq.github.io/repository/phpmd-1.0.2.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpmd":"^2.6.1"}},"checksum":{"type":"sha-512","value":"f22280a6dec8dbdd2ec1d83b294f23237fe32c34f4a298e52038e0a7a0074d541635b2b488b1a6098a42d8418a6cd8eb804406ea82b91e362be2b5d11a0915b0"},"tools":{"phpmd":{"version":"2.15.0","url":"https://github.com/phpmd/phpmd/releases/download/2.15.0/phpmd.phar","requirements":{"php":{"php":">=5.3.9","ext-xml":"*"}},"checksum":null,"signature":"https://github.com/phpmd/phpmd/releases/download/2.15.0/phpmd.phar.asc"}},"composerLock":null},"phpcpd":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/phpcpd-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcpd":"^6.0"}},"checksum":{"type":"sha-512","value":"1189ce0bf3fade4cb4241f1d96f915ef8fc7651f4450dc79fdf464ee3d6be3009316f0d423ce2d4af9d76ad50807b7fdf4d77bfa6d9ee2c91d6eda32ea214433"},"tools":{"phpcpd":{"version":"6.0.3","url":"https://phar.phpunit.de/phpcpd-6.0.3.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*"}},"checksum":{"type":"sha-256","value":"2cbaea7cfda1bb4299d863eb075e977c3f49055dd16d88529fae5150d48a84cb"},"signature":"https://phar.phpunit.de/phpcpd-6.0.3.phar.asc"}},"composerLock":null},"phploc":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phploc-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*","ext-json":"*"},"tool":{"phploc":"^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"}},"checksum":{"type":"sha-512","value":"f67b02d494796adf553cb3dd13ec06c1cb8e53c799954061749424251379541637538199afb3afa3c7a01cabd1cb6f1c53eb621f015dff9644c6c7cbf10c56d1"},"tools":{"phploc":{"version":"7.0.2","url":"https://phar.phpunit.de/phploc-7.0.2.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*"}},"checksum":{"type":"sha-256","value":"3d59778ec86faf25fd00e3a329b2f9ad4a3c751ca91601ea7dab70f887b0bf46"},"signature":"https://phar.phpunit.de/phploc-7.0.2.phar.asc"}},"composerLock":null},"phpcs":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/phpcs-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcs":"^3.0 || ^2.0","phpcbf":"^3.0 || ^2.0"}},"checksum":{"type":"sha-512","value":"2737022369da1318cc4e0ea194e8a81019f7b079080d869aab878b7486052fdbe68fee3f28131f35573226def1aabd4bd005e038ee7b767c137b1107c1492a83"},"tools":{"phpcs":{"version":"3.7.2","url":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.2/phpcs.phar","requirements":{"php":{"php":">=5.4.0","ext-tokenizer":"*","ext-xmlwriter":"*","ext-simplexml":"*"}},"checksum":null,"signature":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.2/phpcs.phar.asc"},"phpcbf":{"version":"3.7.2","url":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.2/phpcbf.phar","requirements":{"php":{"php":">=5.4.0","ext-tokenizer":"*","ext-xmlwriter":"*","ext-simplexml":"*"}},"checksum":null,"signature":"https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.7.2/phpcbf.phar.asc"}},"composerLock":null},"composer-normalize":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/composer-normalize-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-json":"*"},"tool":{"composer-normalize":"^2.1"}},"checksum":{"type":"sha-512","value":"d59d3557cb20630734878a9115df5dd32d5aff815e5b15be36f6fb5d6e9d83dd36efd84215ab6529edcc924f600946f739a0d9e67723deff95c88346ab502498"},"tools":{"composer-normalize":{"version":"2.41.1","url":"https://github.com/ergebnis/composer-normalize/releases/download/2.41.1/composer-normalize.phar","requirements":{"php":{"php":"~8.1.0 || ~8.2.0 || ~8.3.0","ext-json":"*"}},"checksum":null,"signature":"https://github.com/ergebnis/composer-normalize/releases/download/2.41.1/composer-normalize.phar.asc"}},"composerLock":null},"phpspec":{"api-version":"1.0.0","version":"1.0.0","type":"php-file","url":"./.phpcq/local/phpspec-plugin.php","signature":null,"requirements":{},"checksum":{"type":"sha-512","value":"0307cb00e814c3de436e2c0cc87e4cb949fdec8ce8b3f8fc5a25f7b3631f27dfe8e2b867f4e6419ad4668e252a29267d022c3f6fa20118e4016df66ccfce5605"},"tools":{},"composerLock":null}},"tools":[]} \ No newline at end of file +{"plugins":{"psalm":{"api-version":"1.0.0","version":"1.2.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/psalm/psalm-1.2.0.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0","ext-dom":"*"},"tool":{"psalm":"^3.0 || ^4.0 || ^5.0"}},"checksum":{"type":"sha-512","value":"4a550c9226d7bca582d7c10bd87cce01190c96398936b1613421640c83df62ed1c6e0d44c1b39635414ea8cf4a892a6458d27590793238add24e7cb5547e6ffd"},"tools":{"psalm":{"version":"5.21.1","url":"https://github.com/vimeo/psalm/releases/download/5.21.1/psalm.phar","requirements":{"php":{"php":"^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0","ext-SimpleXML":"*","ext-ctype":"*","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-tokenizer":"*"}},"checksum":null,"signature":"https://github.com/vimeo/psalm/releases/download/5.21.1/psalm.phar.asc"}},"composerLock":null},"composer-require-checker":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/composer-require-checker/composer-require-checker-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0"},"tool":{"composer-require-checker":"^3.8 || ^4.0"}},"checksum":{"type":"sha-512","value":"d5415bddfe024c5749d894034583882aee4e5c3e1087815d9fdd81cb5e71630f631a0e35de0ff84b97fbbf738c16ece5f83bd8c00695913eb846aa6f04577dc2"},"tools":{"composer-require-checker":{"version":"4.8.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.8.0/composer-require-checker.phar","requirements":{"php":{"php":"~8.2.0 || ~8.3.0","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.8.0/composer-require-checker.phar.asc"}},"composerLock":null},"phpmd":{"api-version":"1.0.0","version":"1.0.2.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpmd/phpmd-1.0.2.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpmd":"^2.6.1"}},"checksum":{"type":"sha-512","value":"f22280a6dec8dbdd2ec1d83b294f23237fe32c34f4a298e52038e0a7a0074d541635b2b488b1a6098a42d8418a6cd8eb804406ea82b91e362be2b5d11a0915b0"},"tools":{"phpmd":{"version":"2.15.0","url":"https://github.com/phpmd/phpmd/releases/download/2.15.0/phpmd.phar","requirements":{"php":{"php":">=5.3.9","ext-xml":"*"}},"checksum":null,"signature":"https://github.com/phpmd/phpmd/releases/download/2.15.0/phpmd.phar.asc"}},"composerLock":null},"phpcpd":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpcpd/phpcpd-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcpd":"^6.0"}},"checksum":{"type":"sha-512","value":"1189ce0bf3fade4cb4241f1d96f915ef8fc7651f4450dc79fdf464ee3d6be3009316f0d423ce2d4af9d76ad50807b7fdf4d77bfa6d9ee2c91d6eda32ea214433"},"tools":{"phpcpd":{"version":"6.0.3","url":"https://phar.phpunit.de/phpcpd-6.0.3.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*"}},"checksum":{"type":"sha-256","value":"2cbaea7cfda1bb4299d863eb075e977c3f49055dd16d88529fae5150d48a84cb"},"signature":"https://phar.phpunit.de/phpcpd-6.0.3.phar.asc"}},"composerLock":null},"phploc":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phploc/phploc-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*","ext-json":"*"},"tool":{"phploc":"^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"}},"checksum":{"type":"sha-512","value":"f67b02d494796adf553cb3dd13ec06c1cb8e53c799954061749424251379541637538199afb3afa3c7a01cabd1cb6f1c53eb621f015dff9644c6c7cbf10c56d1"},"tools":{"phploc":{"version":"7.0.2","url":"https://phar.phpunit.de/phploc-7.0.2.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*"}},"checksum":{"type":"sha-256","value":"3d59778ec86faf25fd00e3a329b2f9ad4a3c751ca91601ea7dab70f887b0bf46"},"signature":"https://phar.phpunit.de/phploc-7.0.2.phar.asc"}},"composerLock":null},"phpcs":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpcs/phpcs-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-dom":"*"},"tool":{"phpcs":"^3.0 || ^2.0","phpcbf":"^3.0 || ^2.0"}},"checksum":{"type":"sha-512","value":"2737022369da1318cc4e0ea194e8a81019f7b079080d869aab878b7486052fdbe68fee3f28131f35573226def1aabd4bd005e038ee7b767c137b1107c1492a83"},"tools":{"phpcs":{"version":"3.8.1","url":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.8.1/phpcs.phar","requirements":{"php":{"php":">=5.4.0","ext-simplexml":"*","ext-tokenizer":"*","ext-xmlwriter":"*"}},"checksum":null,"signature":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.8.1/phpcs.phar.asc"},"phpcbf":{"version":"3.8.1","url":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.8.1/phpcbf.phar","requirements":{"php":{"php":">=5.4.0","ext-simplexml":"*","ext-tokenizer":"*","ext-xmlwriter":"*"}},"checksum":null,"signature":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.8.1/phpcbf.phar.asc"}},"composerLock":null},"composer-normalize":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/composer-normalize/composer-normalize-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-json":"*"},"tool":{"composer-normalize":"^2.1"}},"checksum":{"type":"sha-512","value":"d59d3557cb20630734878a9115df5dd32d5aff815e5b15be36f6fb5d6e9d83dd36efd84215ab6529edcc924f600946f739a0d9e67723deff95c88346ab502498"},"tools":{"composer-normalize":{"version":"2.42.0","url":"https://github.com/ergebnis/composer-normalize/releases/download/2.42.0/composer-normalize.phar","requirements":{"php":{"php":"~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0","ext-json":"*"}},"checksum":null,"signature":"https://github.com/ergebnis/composer-normalize/releases/download/2.42.0/composer-normalize.phar.asc"}},"composerLock":null},"phpspec":{"api-version":"1.0.0","version":"1.0.0","type":"php-file","url":"./.phpcq/local/phpspec-plugin.php","signature":null,"requirements":{},"checksum":{"type":"sha-512","value":"0307cb00e814c3de436e2c0cc87e4cb949fdec8ce8b3f8fc5a25f7b3631f27dfe8e2b867f4e6419ad4668e252a29267d022c3f6fa20118e4016df66ccfce5605"},"tools":{},"composerLock":null}},"tools":[]} \ No newline at end of file diff --git a/.phpcq.yaml.dist b/.phpcq.yaml.dist index 349667a..f87a0df 100644 --- a/.phpcq.yaml.dist +++ b/.phpcq.yaml.dist @@ -52,6 +52,7 @@ phpcq: # phpmd - 0F9684B8B16B7AB0 - 9093F8B32E4815AA + - 5E6DDE998AB73B8E tasks: fix: diff --git a/composer.json b/composer.json index 13b2d1d..853e706 100644 --- a/composer.json +++ b/composer.json @@ -30,10 +30,10 @@ "doctrine/dbal": "^2.11 || ^3.0", "netzmacht/contao-toolkit": "^3.9 || ^4.0", "netzmacht/html": "^2.0 || ^3.0", - "symfony/config": "^4.4 || ^5.4", - "symfony/dependency-injection": "^4.4 || ^5.4", - "symfony/http-kernel": "^4.4 || ^5.4", - "symfony/translation-contracts": "^1.1 || ^2.0" + "symfony/config": "^4.4 || ^5.4 || ^6.0", + "symfony/dependency-injection": "^4.4 || ^5.4 || ^6.0", + "symfony/http-kernel": "^4.4 || ^5.4 || ^6.0", + "symfony/translation-contracts": "^1.1 || ^2.0 || ^3.0" }, "require-dev": { "contao/manager-plugin": "^2.1", diff --git a/phpcs.xml.dist b/phpcs.xml.dist index a17e10f..7d188c5 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -49,7 +49,6 @@ - diff --git a/psalm.xml b/psalm.xml index 1d9ecd2..f4c9f70 100644 --- a/psalm.xml +++ b/psalm.xml @@ -5,7 +5,7 @@ resolveFromConfigFile="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" - xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" + xsi:schemaLocation="https://getpsalm.org/schema/config https://getpsalm.org/schema/config" > @@ -29,6 +29,11 @@ + + + + + diff --git a/spec/EventListener/Hook/ActivateConsentToolListenerSpec.php b/spec/EventListener/Hook/ActivateConsentToolListenerSpec.php index 9a89ca2..dc43951 100644 --- a/spec/EventListener/Hook/ActivateConsentToolListenerSpec.php +++ b/spec/EventListener/Hook/ActivateConsentToolListenerSpec.php @@ -5,6 +5,8 @@ namespace spec\Hofff\Contao\Consent\Bridge\EventListener\Hook; use Contao\LayoutModel; +use Contao\Model; +use Contao\ModuleModel; use Contao\PageModel; use Hofff\Contao\Consent\Bridge\ConsentToolManager; use Hofff\Contao\Consent\Bridge\EventListener\Hook\ActivateConsentToolListener; @@ -12,6 +14,7 @@ use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use ReflectionClass; final class ActivateConsentToolListenerSpec extends ObjectBehavior { @@ -31,20 +34,19 @@ public function it_is_initializable(): void $this->shouldHaveType(ActivateConsentToolListener::class); } - public function it_activates_consent_tool( - ConsentToolManager $consentToolManager, - Repository $pageRepository, - PageModel $rootPageModel, - PageModel $pageModel, - LayoutModel $layoutModel, - ): void { - $pageModel - ->getWrappedObject() - ->rootId = 1; + public function it_activates_consent_tool(ConsentToolManager $consentToolManager, Repository $pageRepository): void + { + $modelReflection = (new ReflectionClass(Model::class)); + if ($modelReflection->hasProperty('arrColumnCastTypes')) { + $modelReflection->getProperty('arrColumnCastTypes')->setValue(['arrColumnCastTypes' => []]); + } + + $layoutModel = (new ReflectionClass(LayoutModel::class))->newInstanceWithoutConstructor(); + $pageModel = (new ReflectionClass(PageModel::class))->newInstanceWithoutConstructor(); + $rootPageModel = (new ReflectionClass(PageModel::class))->newInstanceWithoutConstructor(); - $rootPageModel - ->getWrappedObject() - ->hofff_consent_bridge_consent_tool = 'example'; + $pageModel->rootId = 1; + $rootPageModel->hofff_consent_bridge_consent_tool = 'example'; $pageRepository->find(1) ->shouldBeCalled() @@ -62,17 +64,18 @@ public function it_activates_consent_tool( public function it_does_not_activate_unknown_consent_tool( ConsentToolManager $consentToolManager, Repository $pageRepository, - PageModel $rootPageModel, - PageModel $pageModel, - LayoutModel $layoutModel, ): void { - $pageModel - ->getWrappedObject() - ->rootId = 1; + $modelReflection = (new ReflectionClass(Model::class)); + if ($modelReflection->hasProperty('arrColumnCastTypes')) { + $modelReflection->getProperty('arrColumnCastTypes')->setValue(['arrColumnCastTypes' => []]); + } + + $layoutModel = (new ReflectionClass(LayoutModel::class))->newInstanceWithoutConstructor(); + $pageModel = (new ReflectionClass(PageModel::class))->newInstanceWithoutConstructor(); + $rootPageModel = (new ReflectionClass(PageModel::class))->newInstanceWithoutConstructor(); - $rootPageModel - ->getWrappedObject() - ->hofff_consent_bridge_consent_tool = 'example'; + $pageModel->rootId = 1; + $rootPageModel->hofff_consent_bridge_consent_tool = 'example'; $pageRepository->find(1) ->shouldBeCalled() diff --git a/spec/EventListener/Hook/GoogleWebfontsListenerSpec.php b/spec/EventListener/Hook/GoogleWebfontsListenerSpec.php index b5a1c60..08bb6de 100644 --- a/spec/EventListener/Hook/GoogleWebfontsListenerSpec.php +++ b/spec/EventListener/Hook/GoogleWebfontsListenerSpec.php @@ -5,6 +5,7 @@ namespace spec\Hofff\Contao\Consent\Bridge\EventListener\Hook; use Contao\LayoutModel; +use Contao\Model; use Contao\PageModel; use Hofff\Contao\Consent\Bridge\ConsentId; use Hofff\Contao\Consent\Bridge\ConsentId\ConsentIdParser; @@ -15,6 +16,7 @@ use Netzmacht\Html\Attributes; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use ReflectionClass; final class GoogleWebfontsListenerSpec extends ObjectBehavior { @@ -37,10 +39,15 @@ public function it_renders_supported_template( ConsentId $consentId, RequestScopeMatcher $scopeMatcher, PageModel $pageModel, - LayoutModel $layoutModel, ): void { $scopeMatcher->isFrontendRequest()->willReturn(true); + $modelReflection = (new ReflectionClass(Model::class)); + if ($modelReflection->hasProperty('arrColumnCastTypes')) { + $modelReflection->getProperty('arrColumnCastTypes')->setValue(['arrColumnCastTypes' => []]); + } + + $layoutModel = (new ReflectionClass(LayoutModel::class))->newInstanceWithoutConstructor(); $layoutModel->webfonts = 'foo'; $consentTool->determineConsentIdByName('google_webfonts') diff --git a/spec/EventListener/Hook/RenderComponentsListenerSpec.php b/spec/EventListener/Hook/RenderComponentsListenerSpec.php index 36bdbfd..f97d355 100644 --- a/spec/EventListener/Hook/RenderComponentsListenerSpec.php +++ b/spec/EventListener/Hook/RenderComponentsListenerSpec.php @@ -5,6 +5,8 @@ namespace spec\Hofff\Contao\Consent\Bridge\EventListener\Hook; use Contao\ContentModel; +use Contao\LayoutModel; +use Contao\Model; use Contao\ModuleModel; use Hofff\Contao\Consent\Bridge\Bridge; use Hofff\Contao\Consent\Bridge\ConsentId; @@ -16,6 +18,7 @@ use Netzmacht\Contao\Toolkit\Routing\RequestScopeMatcher; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use ReflectionClass; final class RenderComponentsListenerSpec extends ObjectBehavior { @@ -44,12 +47,18 @@ public function it_renders_supported_content_element( ConsentTool $consentTool, ConsentId $consentId, RequestScopeMatcher $scopeMatcher, - ContentModel $model, ): void { $scopeMatcher->isFrontendRequest()->willReturn(true); - $model->getWrappedObject()->type = 'foo'; - $model->getWrappedObject()->hofff_consent_bridge_tag = 'consent_id'; + $modelReflection = (new ReflectionClass(Model::class)); + if ($modelReflection->hasProperty('arrColumnCastTypes')) { + $modelReflection->getProperty('arrColumnCastTypes')->setValue(['arrColumnCastTypes' => []]); + } + + $model = (new ReflectionClass(ContentModel::class))->newInstanceWithoutConstructor(); + + $model->type = 'foo'; + $model->hofff_consent_bridge_tag = 'consent_id'; $consentTool->renderContent(Argument::type('string'), Argument::type(ConsentId::class), $model, null) ->shouldBeCalled() @@ -67,14 +76,20 @@ public function it_renders_supported_content_element( public function it_bypass_unsupported_content_element( ConsentTool $consentTool, RequestScopeMatcher $scopeMatcher, - ContentModel $model, ConsentIdParser $consentIdParser, ConsentId $consentId, ): void { $scopeMatcher->isFrontendRequest()->willReturn(true); - $model->getWrappedObject()->type = 'foo'; - $model->getWrappedObject()->hofff_consent_bridge_tag = 'consent_id'; + $modelReflection = (new ReflectionClass(Model::class)); + if ($modelReflection->hasProperty('arrColumnCastTypes')) { + $modelReflection->getProperty('arrColumnCastTypes')->setValue(['arrColumnCastTypes' => []]); + } + + $model = (new ReflectionClass(ContentModel::class))->newInstanceWithoutConstructor(); + + $model->type = 'foo'; + $model->hofff_consent_bridge_tag = 'consent_id'; $consentIdParser->parse(Argument::type('string'))->willReturn($consentId); @@ -92,14 +107,20 @@ public function it_bypass_unsupported_content_element( public function it_renders_supported_frontend_module( ConsentTool $consentTool, RequestScopeMatcher $scopeMatcher, - ModuleModel $model, ConsentIdParser $consentIdParser, ConsentId $consentId, ): void { $scopeMatcher->isFrontendRequest()->willReturn(true); - $model->getWrappedObject()->type = 'foo'; - $model->getWrappedObject()->hofff_consent_bridge_tag = 'consent_id'; + $modelReflection = (new ReflectionClass(Model::class)); + if ($modelReflection->hasProperty('arrColumnCastTypes')) { + $modelReflection->getProperty('arrColumnCastTypes')->setValue(['arrColumnCastTypes' => []]); + } + + $model = (new ReflectionClass(ModuleModel::class))->newInstanceWithoutConstructor(); + + $model->type = 'foo'; + $model->hofff_consent_bridge_tag = 'consent_id'; $consentIdParser->parse(Argument::type('string'))->willReturn($consentId); @@ -117,14 +138,20 @@ public function it_renders_supported_frontend_module( public function it_bypass_unsupported_frontend_module( ConsentTool $consentTool, RequestScopeMatcher $scopeMatcher, - ModuleModel $model, ConsentIdParser $consentIdParser, ConsentId $consentId, ): void { $scopeMatcher->isFrontendRequest()->willReturn(true); - $model->getWrappedObject()->type = 'foo'; - $model->getWrappedObject()->hofff_consent_bridge_tag = 'consent_id'; + $modelReflection = (new ReflectionClass(Model::class)); + if ($modelReflection->hasProperty('arrColumnCastTypes')) { + $modelReflection->getProperty('arrColumnCastTypes')->setValue(['arrColumnCastTypes' => []]); + } + + $model = (new ReflectionClass(ModuleModel::class))->newInstanceWithoutConstructor(); + + $model->type = 'foo'; + $model->hofff_consent_bridge_tag = 'consent_id'; $consentIdParser->parse(Argument::type('string'))->willReturn($consentId); diff --git a/spec/HofffContaoConsentBridgeBundleSpec.php b/spec/HofffContaoConsentBridgeBundleSpec.php index 6c864bb..432b749 100644 --- a/spec/HofffContaoConsentBridgeBundleSpec.php +++ b/spec/HofffContaoConsentBridgeBundleSpec.php @@ -27,7 +27,10 @@ public function it_is_a_kernel_bundle(): void public function it_registers_compiler_passes(ContainerBuilder $builder): void { - $builder->addCompilerPass(Argument::type(RegisterConsentToolPass::class))->shouldBeCalled(); + $builder + ->addCompilerPass(Argument::type(RegisterConsentToolPass::class)) + ->willReturn($builder->getWrappedObject()) + ->shouldBeCalled(); $this->build($builder); }