diff --git a/.phpcq.lock b/.phpcq.lock index b91d34e09..593144f65 100644 --- a/.phpcq.lock +++ b/.phpcq.lock @@ -1 +1 @@ -{"plugins":{"phpunit":{"api-version":"1.0.0","version":"1.0.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpunit/phpunit-1.0.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0"},"tool":{"phpunit":"^6.0 || ^7.0 || ^8.0 || ^9.0"}},"checksum":{"type":"sha-512","value":"c73f15658e3ba62665f09492ec91c3a6a715760bfaa88473a987538439fff442540148e086e46a6aa18ce55a3ea2fbf76caaa581384cb84a38859fcc609ae7e4"},"tools":{"phpunit":{"version":"9.6.29","url":"https://phar.phpunit.de/phpunit-9.6.29.phar","requirements":{"php":{"php":">=7.3","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-xml":"*","ext-xmlwriter":"*"}},"checksum":{"type":"sha-256","value":"04aeb9aa94da2912a9d1ddfaa047bfb7a87ac74735d3f7d61585b47900ede2d7"},"signature":"https://phar.phpunit.de/phpunit-9.6.29.phar.asc"}},"composerLock":null},"psalm":{"api-version":"1.0.0","version":"1.3.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/psalm/psalm-1.3.0.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0","ext-dom":"*"},"tool":{"psalm":"^3.0 || ^4.0 || ^5.0 || ^6.0"}},"checksum":{"type":"sha-512","value":"4a550c9226d7bca582d7c10bd87cce01190c96398936b1613421640c83df62ed1c6e0d44c1b39635414ea8cf4a892a6458d27590793238add24e7cb5547e6ffd"},"tools":{"psalm":{"version":"6.13.1","url":"https://github.com/vimeo/psalm/releases/download/6.13.1/psalm.phar","requirements":{"php":{"php":"~8.2.27 || ~8.3.16 || ~8.4.3","ext-SimpleXML":"*","ext-ctype":"*","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-tokenizer":"*"}},"checksum":null,"signature":"https://github.com/vimeo/psalm/releases/download/6.13.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.16.1","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.16.1/composer-require-checker.phar","requirements":{"php":{"php":"~8.2.0 || ~8.3.0 || ~8.4.0","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.16.1/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.2.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpcs/phpcs-1.2.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":"b6ed00306e76068a6af5e3b1dec837724f9e1900ef1049ce88e7ce195b0583524ca33a73613fba13244307a7ca853b6ddaa14ded69f651c3f184ac130bd1aaad"},"tools":{"phpcs":{"version":"3.13.4","url":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.13.4/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.13.4/phpcs.phar.asc"},"phpcbf":{"version":"3.13.4","url":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.13.4/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.13.4/phpcbf.phar.asc"}},"composerLock":null},"composer-normalize":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/composer-normalize/composer-normalize-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-json":"*"},"tool":{"composer-normalize":"^2.1"}},"checksum":{"type":"sha-512","value":"d9abda440b85d501c58abf9c81bf76f417594b397129215ffa8b777e9bb5e5eda37d7661d661db3c8d11c24f20345bc6fbe56f013b3b9435d459d2b94f086e0f"},"tools":{"composer-normalize":{"version":"2.48.2","url":"https://github.com/ergebnis/composer-normalize/releases/download/2.48.2/composer-normalize.phar","requirements":{"php":{"php":"~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0","ext-json":"*"}},"checksum":null,"signature":"https://github.com/ergebnis/composer-normalize/releases/download/2.48.2/composer-normalize.phar.asc"}},"composerLock":null}},"tools":[]} +{"plugins":{"phpunit":{"api-version":"1.0.0","version":"1.1.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpunit/phpunit-1.1.0.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0"},"tool":{"phpunit":"^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0"}},"checksum":{"type":"sha-512","value":"c73f15658e3ba62665f09492ec91c3a6a715760bfaa88473a987538439fff442540148e086e46a6aa18ce55a3ea2fbf76caaa581384cb84a38859fcc609ae7e4"},"tools":{"phpunit":{"version":"11.5.50","url":"https://phar.phpunit.de/phpunit-11.5.50.phar","requirements":{"php":{"php":">=8.2","ext-dom":"*","ext-json":"*","ext-libxml":"*","ext-mbstring":"*","ext-xml":"*","ext-xmlwriter":"*"}},"checksum":{"type":"sha-256","value":"dc08233c4d6d83c830feff05c7ab701a1b52a154fbd454ce3670c1792e09e4a7"},"signature":"https://phar.phpunit.de/phpunit-11.5.50.phar.asc"}},"composerLock":null},"psalm":{"api-version":"1.0.0","version":"1.3.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/psalm/psalm-1.3.0.0.php","signature":null,"requirements":{"php":{"php":"^7.4 || ^8.0","ext-dom":"*"},"tool":{"psalm":"^3.0 || ^4.0 || ^5.0 || ^6.0"}},"checksum":{"type":"sha-512","value":"4a550c9226d7bca582d7c10bd87cce01190c96398936b1613421640c83df62ed1c6e0d44c1b39635414ea8cf4a892a6458d27590793238add24e7cb5547e6ffd"},"tools":{"psalm":{"version":"6.15.0","url":"https://github.com/vimeo/psalm/releases/download/6.15.0/psalm.phar","requirements":{"php":{"php":"~8.2.27 || ~8.3.16 || ~8.4.3 || ~8.5.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/6.15.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/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.18.0","url":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.18.0/composer-require-checker.phar","requirements":{"php":{"php":"~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0","ext-phar":"*"}},"checksum":null,"signature":"https://github.com/maglnet/ComposerRequireChecker/releases/download/4.18.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.2.0.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/phpcs/phpcs-1.2.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":"b6ed00306e76068a6af5e3b1dec837724f9e1900ef1049ce88e7ce195b0583524ca33a73613fba13244307a7ca853b6ddaa14ded69f651c3f184ac130bd1aaad"},"tools":{"phpcs":{"version":"3.13.5","url":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.13.5/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.13.5/phpcs.phar.asc"},"phpcbf":{"version":"3.13.5","url":"https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/3.13.5/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.13.5/phpcbf.phar.asc"}},"composerLock":null},"composer-normalize":{"api-version":"1.0.0","version":"1.1.1.0","type":"php-file","url":"https://phpcq.github.io/repository/plugin/composer-normalize/composer-normalize-1.1.1.0.php","signature":null,"requirements":{"php":{"php":"^7.3 || ^8.0","ext-json":"*"},"tool":{"composer-normalize":"^2.1"}},"checksum":{"type":"sha-512","value":"d9abda440b85d501c58abf9c81bf76f417594b397129215ffa8b777e9bb5e5eda37d7661d661db3c8d11c24f20345bc6fbe56f013b3b9435d459d2b94f086e0f"},"tools":{"composer-normalize":{"version":"2.49.0","url":"https://github.com/ergebnis/composer-normalize/releases/download/2.49.0/composer-normalize.phar","requirements":{"php":{"php":"~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0","ext-json":"*"}},"checksum":null,"signature":"https://github.com/ergebnis/composer-normalize/releases/download/2.49.0/composer-normalize.phar.asc"}},"composerLock":null}},"tools":[]} \ No newline at end of file diff --git a/.phpcq.yaml.dist b/.phpcq.yaml.dist index dac15ddbb..ac6a93fad 100644 --- a/.phpcq.yaml.dist +++ b/.phpcq.yaml.dist @@ -12,6 +12,9 @@ phpcq: phpunit: version: ^1.0 signed: false + requirements: + phpunit: + version: ^9.6.22 psalm: version: ^1.0 signed: false @@ -41,6 +44,7 @@ phpcq: # psalm - 8A03EA3B385DBAA1 - 12CE0F1D262429A5 + - 99BF4D9A33D65E1E # magl@magll.net - D2CCAC42F6295E7D # PHP_CodeSniffer diff --git a/composer.json b/composer.json index 7fd43d81d..0a40a89f2 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "contao-community-alliance/meta-palettes": "^2.0.10", "contao-community-alliance/translator": "^2.5", "contao-community-alliance/url-builder": "^2.0", - "contao/core-bundle": "^5.3 <5.7", + "contao/core-bundle": "^5.3", "discordier/justtextwidgets": "^2.0", "doctrine/cache": "^2.1", "doctrine/dbal": "^3.6", diff --git a/src/CoreBundle/EventListener/DcGeneral/Table/DcaSetting/ModelToLabelListener.php b/src/CoreBundle/EventListener/DcGeneral/Table/DcaSetting/ModelToLabelListener.php index 1358b5818..8fa46a61f 100644 --- a/src/CoreBundle/EventListener/DcGeneral/Table/DcaSetting/ModelToLabelListener.php +++ b/src/CoreBundle/EventListener/DcGeneral/Table/DcaSetting/ModelToLabelListener.php @@ -180,14 +180,14 @@ private function drawLegend(ModelToLabelEvent $event) assert($metaModel instanceof IMetaModel); if (\is_array($legend = StringUtil::deserialize($model->getProperty('legendtitle')))) { /** @psalm-suppress DeprecatedMethod */ - foreach ([$metaModel->getActiveLanguage(), $metaModel->getFallbackLanguage()] as $language) { - if (\array_key_exists($language ?? '', $legend) && !empty($legend[$language])) { + foreach ([$metaModel->getActiveLanguage(), (string) $metaModel->getFallbackLanguage()] as $language) { + if (\array_key_exists($language, $legend) && !empty($legend[$language])) { $legend = $legend[$language]; break; } } } - if (null === $legend) { + if (!\is_string($legend)) { $legend = 'legend'; } diff --git a/src/Helper/ToolboxFile.php b/src/Helper/ToolboxFile.php index af3f0a4b6..4820633f1 100644 --- a/src/Helper/ToolboxFile.php +++ b/src/Helper/ToolboxFile.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/core. * - * (c) 2012-2025 The MetaModels team. + * (c) 2012-2026 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -20,7 +20,7 @@ * @author Ingolf Steinhardt * @author Sven Baumann * @author Andreas Fischer - * @copyright 2012-2025 The MetaModels team. + * @copyright 2012-2026 The MetaModels team. * @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -802,6 +802,10 @@ protected function sortByIdList($sortIds) $fileKeys = array_flip(array_keys($this->uuidMap)); $sorted = []; foreach ($sortIds as $sortStringId) { + if (!isset($fileKeys[$sortStringId])) { + continue; + } + $key = $fileKeys[$sortStringId]; $sorted[$key] = $fileMap[$key]; unset($fileMap[$key]); @@ -1107,7 +1111,7 @@ private function addFileModels(Collection $files, array $skipPaths = []): void if (isset($meta[$baseLanguage])) { $this->metaInformation[dirname($path)][basename($path)] = $meta[$baseLanguage]; - } elseif (isset($meta[$fallbackLanguage]) && null !== $fallbackLanguage) { + } elseif (null !== $fallbackLanguage && isset($meta[$fallbackLanguage])) { $this->metaInformation[dirname($path)][basename($path)] = $meta[$fallbackLanguage]; } } diff --git a/tests/Attribute/AttributeFactoryTest.php b/tests/Attribute/AttributeFactoryTest.php index c8823ddb7..652141420 100644 --- a/tests/Attribute/AttributeFactoryTest.php +++ b/tests/Attribute/AttributeFactoryTest.php @@ -26,14 +26,12 @@ use MetaModels\Attribute\IAttributeFactory; use MetaModels\IMetaModelsServiceContainer; use MetaModels\MetaModelsEvents; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -/** - * Test the attribute factory. - * - * @covers \MetaModels\Attribute\AttributeFactory - */ +/** Test the attribute factory. */ +#[CoversClass(AttributeFactory::class)] class AttributeFactoryTest extends TestCase { /** @@ -41,24 +39,23 @@ class AttributeFactoryTest extends TestCase * * @return void */ - public function testCreateFactoryFiresEvent() + public function testCreateFactoryFiresEvent(): void { - $serviceContainer = $this->getMockForAbstractClass(IMetaModelsServiceContainer::class); + $serviceContainer = $this->getMockBuilder(IMetaModelsServiceContainer::class)->getMock(); - $eventDispatcher = $this->getMockForAbstractClass(EventDispatcherInterface::class); + $eventDispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); $eventDispatcher - ->expects(self::exactly(1)) + ->expects($this->once()) ->method('dispatch') - ->withConsecutive( - [ - self::isInstanceOf(CreateAttributeFactoryEvent::class), - self::equalTo(MetaModelsEvents::ATTRIBUTE_FACTORY_CREATE), - ] - ); + ->willReturnCallback(function (object $event, string $name) { + self::assertInstanceOf(CreateAttributeFactoryEvent::class, $event); + self::assertSame(MetaModelsEvents::ATTRIBUTE_FACTORY_CREATE, $name); + return $event; + }); $eventDispatcher - ->expects(self::exactly(1)) + ->expects($this->once()) ->method('hasListeners') - ->with(self::equalTo(MetaModelsEvents::ATTRIBUTE_FACTORY_CREATE)) + ->with(MetaModelsEvents::ATTRIBUTE_FACTORY_CREATE) ->willReturn(true); $factory = new AttributeFactory($eventDispatcher); @@ -72,9 +69,9 @@ public function testCreateFactoryFiresEvent() * * @return void */ - public function testAddTypeFactoryAndGetTypeFactory() + public function testAddTypeFactoryAndGetTypeFactory(): void { - $factory = new AttributeFactory($this->getMockForAbstractClass(EventDispatcherInterface::class)); + $factory = new AttributeFactory($this->getMockBuilder(EventDispatcherInterface::class)->getMock()); self::assertNull($factory->getTypeFactory('test')); $attributeFactory = $this->mockAttributeFactory('test', true, false, false); diff --git a/tests/Data/FilterBuilderSqlTest.php b/tests/Data/FilterBuilderSqlTest.php index f987c0092..ee8ca5f6b 100644 --- a/tests/Data/FilterBuilderSqlTest.php +++ b/tests/Data/FilterBuilderSqlTest.php @@ -23,14 +23,13 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Result; use MetaModels\DcGeneral\Data\FilterBuilderSql; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -/** - * Test the filter builder. - * - * @covers \MetaModels\DcGeneral\Data\FilterBuilderSql - */ +/** Test the filter builder. */ +#[CoversClass(FilterBuilderSql::class)] class FilterBuilderSqlTest extends TestCase { /** @@ -48,7 +47,7 @@ public function testBuilderIsInitiallyEmpty(): void /** * Data provider for testBuild() */ - public function buildTestProvider(): array + public static function buildTestProvider(): array { return [ 'equality compare' => [ @@ -85,9 +84,8 @@ public function buildTestProvider(): array * @param string $expectedSql The expected SQL query. * @param array $expectedParams The expected parameters. * @param array $filter The filter input array. - * - * @dataProvider buildTestProvider */ + #[DataProvider('buildTestProvider')] public function testBuild(string $expectedSql, array $expectedParams, array $filter): void { $connection = $this->mockConnection($expectedSql, $expectedParams, [['id' => 'succ'], ['id' => 'ess']]); @@ -157,11 +155,11 @@ private function mockConnection(string $queryString, array $params, array $resul ->disableOriginalConstructor() ->getMock(); $resultSet - ->expects(self::once()) + ->expects($this->once()) ->method('fetchAllAssociative') ->willReturn($result); $connection - ->expects(self::once()) + ->expects($this->once()) ->method('executeQuery') ->with($queryString, $params) ->willReturn($resultSet); diff --git a/tests/Data/FilterBuilderTest.php b/tests/Data/FilterBuilderTest.php index 155005769..c225967fe 100644 --- a/tests/Data/FilterBuilderTest.php +++ b/tests/Data/FilterBuilderTest.php @@ -177,7 +177,7 @@ public function testIssue700() $attribute = $this ->getMockBuilder(Base::class) ->setConstructorArgs([$metaModel, ['colname' => 'test1']]) - ->setMethods(['searchFor']) + ->onlyMethods(['searchFor']) ->getMockForAbstractClass(); $attribute diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index 7c299e4ed..c55de6fa4 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -47,12 +47,11 @@ public function testCreateMetaModelFiresEvent() $dispatcher ->expects(self::exactly(1)) ->method('dispatch') - ->withConsecutive( - [ - self::isInstanceOf(CreateMetaModelEvent::class), - self::equalTo(CreateMetaModelEvent::NAME) - ] - ); + ->willReturnCallback(function (object $event, string $name) { + self::assertInstanceOf(CreateMetaModelEvent::class, $event); + self::assertSame(CreateMetaModelEvent::NAME, $name); + return $event; + }); $factory->getMetaModel('mm_test'); } diff --git a/tests/Filter/FilterUrlBuilderTest.php b/tests/Filter/FilterUrlBuilderTest.php index a67aeb85a..2f760361a 100644 --- a/tests/Filter/FilterUrlBuilderTest.php +++ b/tests/Filter/FilterUrlBuilderTest.php @@ -22,16 +22,15 @@ use MetaModels\Filter\FilterUrl; use MetaModels\Filter\FilterUrlBuilder; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -/** - * This tests the filter url class. - * - * @covers \MetaModels\Filter\FilterUrlBuilder - */ +/** This tests the filter url class. */ +#[CoversClass(FilterUrlBuilder::class)] class FilterUrlBuilderTest extends TestCase { /** @@ -39,7 +38,7 @@ class FilterUrlBuilderTest extends TestCase * * @return array */ - public function generateProvider(): array + public static function generateProvider(): array { return [ 'test generating' => [ @@ -101,9 +100,8 @@ public function generateProvider(): array * @param string $requestUrl The current URL. * * @return void - * - * @dataProvider generateProvider */ + #[DataProvider('generateProvider')] public function testGenerate( string $expectedUrl, array $expectedParameters, @@ -124,7 +122,7 @@ public function testGenerate( ->getMock(); $generator - ->expects(self::once()) + ->expects($this->once()) ->method('generate') ->with($expectedUrl, $expectedParameters) ->willReturn('success'); @@ -150,7 +148,7 @@ public function testGeneratesNonStandardPorts(): void ->getMock(); $generator - ->expects(self::once()) + ->expects($this->once()) ->method('generate') ->with('tl_page.42', ['get2' => 'value', 'get-param' => 'get-value', 'parameters' => '/auto/slug/sluggy']) ->willReturn('success'); diff --git a/tests/Filter/Rules/Condition/ConditionAndTest.php b/tests/Filter/Rules/Condition/ConditionAndTest.php index cc5a5e508..3066cb960 100644 --- a/tests/Filter/Rules/Condition/ConditionAndTest.php +++ b/tests/Filter/Rules/Condition/ConditionAndTest.php @@ -22,13 +22,12 @@ use MetaModels\Filter\IFilter; use MetaModels\Filter\Rules\Condition\ConditionAnd; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * Test AND condition filter rules. - * - * @covers \MetaModels\Filter\Rules\Condition\ConditionAnd - */ +/** Test AND condition filter rules. */ +#[CoversClass(ConditionAnd::class)] class ConditionAndTest extends TestCase { /** @@ -36,7 +35,7 @@ class ConditionAndTest extends TestCase * * @return array */ - public function provider() + public static function provider(): array { return array( array( @@ -77,10 +76,9 @@ public function provider() * @param array $filters The filter result values to add to the AND condition. * * @return void - * - * @dataProvider provider */ - public function testAndCondition($message, $expected, $filters) + #[DataProvider('provider')] + public function testAndCondition($message, $expected, $filters): void { $condition = new ConditionAnd(); foreach ($filters as $filter) { @@ -97,9 +95,9 @@ public function testAndCondition($message, $expected, $filters) * * @return IFilter */ - private function mockFilter($result) + private function mockFilter(?array $result): IFilter { - $filter = $this->getMockForAbstractClass(IFilter::class); + $filter = $this->getMockBuilder(IFilter::class)->getMock(); $filter->method('getMatchingIds')->willReturn($result); return $filter; diff --git a/tests/Filter/Rules/Condition/ConditionOrTest.php b/tests/Filter/Rules/Condition/ConditionOrTest.php index f5ad948d8..939db41bb 100644 --- a/tests/Filter/Rules/Condition/ConditionOrTest.php +++ b/tests/Filter/Rules/Condition/ConditionOrTest.php @@ -22,13 +22,12 @@ use MetaModels\Filter\IFilter; use MetaModels\Filter\Rules\Condition\ConditionOr; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * Test OR condition filter rules. - * - * @covers \MetaModels\Filter\Rules\Condition\ConditionOr - */ +/** Test OR condition filter rules. */ +#[CoversClass(ConditionOr::class)] class ConditionOrTest extends TestCase { /** @@ -36,7 +35,7 @@ class ConditionOrTest extends TestCase * * @return array */ - public function provider() + public static function provider(): array { return array( array( @@ -77,10 +76,9 @@ public function provider() * @param array $filters The filter result values to add to the AND condition. * * @return void - * - * @dataProvider provider */ - public function testOrCondition($message, $expected, $filters) + #[DataProvider('provider')] + public function testOrCondition(string $message, ?array $expected, array $filters): void { $condition = new ConditionOr(); foreach ($filters as $filter) { @@ -97,9 +95,9 @@ public function testOrCondition($message, $expected, $filters) * * @return IFilter */ - private function mockFilter($result) + private function mockFilter(?array $result): IFilter { - $filter = $this->getMockForAbstractClass(IFilter::class); + $filter = $this->getMockBuilder(IFilter::class)->getMock(); $filter->method('getMatchingIds')->willReturn($result); return $filter; diff --git a/tests/Filter/Setting/CustomSqlTest.php b/tests/Filter/Setting/CustomSqlTest.php index 64508adef..c933300cb 100644 --- a/tests/Filter/Setting/CustomSqlTest.php +++ b/tests/Filter/Setting/CustomSqlTest.php @@ -38,6 +38,8 @@ use MetaModels\IMetaModel; use MetaModels\IMetaModelsServiceContainer; use MetaModels\Test\AutoLoadingTestCase; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use ReflectionProperty; use RuntimeException; use Symfony\Component\DependencyInjection\Container; @@ -51,14 +53,13 @@ /** * Unit test for testing the CustomSql filter setting. * - * @covers \MetaModels\Filter\Setting\CustomSql - * @covers \MetaModels\CoreBundle\Contao\InsertTag\ReplaceParam - * @covers \MetaModels\CoreBundle\Contao\InsertTag\ReplaceTableName - * * @SuppressWarnings(PHPMD.TooManyPublicMethods) * @SuppressWarnings(PHPMD.TooManyMethods) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ +#[CoversClass(CustomSql::class)] +#[CoversClass(ReplaceParam::class)] +#[CoversClass(ReplaceTableName::class)] class CustomSqlTest extends AutoLoadingTestCase { /** @@ -78,10 +79,10 @@ private function mockCustomSql( string $tableName = 'mm_unittest', array $services = [] ): CustomSql { - $metaModel = $this->getMockForAbstractClass(IMetaModel::class); + $metaModel = $this->getMockBuilder(IMetaModel::class)->getMock(); $metaModel->method('getTableName')->willReturn($tableName); - $filterSetting = $this->getMockForAbstractClass(ICollection::class); + $filterSetting = $this->getMockBuilder(ICollection::class)->getMock(); $filterSetting->method('getMetaModel')->willReturn($metaModel); if (!isset($services[InsertTagParser::class])) { @@ -627,84 +628,83 @@ public function testWithNullValueAndDefault(): void ); } - public function issue1495IfLangProvider(): Iterator + public static function issue1495IfLangProvider(): Iterator { yield [ 'sql' => '{{iflng::de}}1{{iflng::en}}3{{iflng::nl}}2{{iflng::es}}4{{iflng::el}}5{{iflng}}', 'language' => 'en', - 'exp_sql' => '3', + 'expectedSql' => '3', ]; yield [ 'sql' => '{{iflng::de}}1{{iflng::en}}3{{iflng::nl}}2{{iflng::es}}4{{iflng::el}}5{{iflng}}', 'language' => 'de', - 'exp_sql' => '1', + 'expectedSql' => '1', ]; yield [ 'sql' => '{{iflng::de}}1{{iflng::en}}3{{iflng::nl}}2{{iflng::es}}4{{iflng::el}}5{{iflng}}', 'language' => 'nl', - 'exp_sql' => '2', + 'expectedSql' => '2', ]; yield [ 'sql' => '{{iflng::de}}1{{iflng::en}}3{{iflng::nl}}2{{iflng::es}}4{{iflng::el}}5{{iflng}}', 'language' => 'es', - 'exp_sql' => '4', + 'expectedSql' => '4', ]; yield [ 'sql' => '{{iflng::de}}1{{iflng::en}}3{{iflng::nl}}2{{iflng::es}}4{{iflng::el}}5{{iflng}}', 'language' => 'el', - 'exp_sql' => '5', + 'expectedSql' => '5', ]; yield [ 'sql' => '{{iflng::de}}1{{iflng::en}}3{{iflng::nl}}2{{iflng::es}}4{{iflng::el}}5{{iflng}}', 'language' => 'cn', - 'exp_sql' => '', + 'expectedSql' => '', ]; yield [ 'sql' => '{{ifnlng::de}}1{{ifnlng::en}}3{{ifnlng::nl}}2{{ifnlng::es}}4{{ifnlng::el}}5{{iflng}}', 'language' => 'en', - 'exp_sql' => '1245', + 'expectedSql' => '1245', ]; yield [ 'sql' => '{{ifnlng::de}}1{{ifnlng::en}}3{{ifnlng::nl}}2{{ifnlng::es}}4{{ifnlng::el}}5{{iflng}}', 'language' => 'de', - 'exp_sql' => '3245', + 'expectedSql' => '3245', ]; yield [ 'sql' => '{{ifnlng::de}}1{{ifnlng::en}}3{{ifnlng::nl}}2{{ifnlng::es}}4{{ifnlng::el}}5{{iflng}}', 'language' => 'nl', - 'exp_sql' => '1345', + 'expectedSql' => '1345', ]; yield [ 'sql' => '{{ifnlng::de}}1{{ifnlng::en}}3{{ifnlng::nl}}2{{ifnlng::es}}4{{ifnlng::el}}5{{iflng}}', 'language' => 'es', - 'exp_sql' => '1325', + 'expectedSql' => '1325', ]; yield [ 'sql' => '{{ifnlng::de}}1{{ifnlng::en}}3{{ifnlng::nl}}2{{ifnlng::es}}4{{ifnlng::el}}5{{iflng}}', 'language' => 'el', - 'exp_sql' => '1324', + 'expectedSql' => '1324', ]; yield [ 'sql' => '{{ifnlng::de}}1{{ifnlng::en}}3{{ifnlng::nl}}2{{ifnlng::es}}4{{ifnlng::el}}5{{iflng}}', 'language' => 'cn', - 'exp_sql' => '13245', + 'expectedSql' => '13245', ]; yield [ 'sql' => 'SELECT id FROM {{table}} WHERE alias = {{iflng::de}}moe-yer-ss-hans-herbert-oeaeue' . '{{iflng::en}}3{{iflng::nl}}2{{iflng::es}}4{{iflng::el}}5{{iflng}}', 'language' => 'de', - 'exp_sql' => 'SELECT id FROM tableName + 'expectedSql' => 'SELECT id FROM tableName WHERE alias = moe-yer-ss-hans-herbert-oeaeue', ]; } /** * https://github.com/MetaModels/core/issues/1495 - * - * @dataProvider issue1495IfLangProvider */ + #[DataProvider('issue1495IfLangProvider')] public function testIssue1495IfLang(string $sql, string $language, string $expectedSql): void { $pageModel = $this diff --git a/tests/Helper/EmptyTestTest.php b/tests/Helper/EmptyTestTest.php index 131c2e46a..01706746d 100644 --- a/tests/Helper/EmptyTestTest.php +++ b/tests/Helper/EmptyTestTest.php @@ -20,13 +20,12 @@ namespace MetaModels\Test\Helper; use MetaModels\Helper\EmptyTest; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * This tests the empty value check helper. - * - * @covers \MetaModels\Helper\EmptyTest - */ +/** This tests the empty value check helper. */ +#[CoversClass(EmptyTest::class)] class EmptyTestTest extends TestCase { /** @@ -34,7 +33,7 @@ class EmptyTestTest extends TestCase * * @return array */ - public function emptyValueTestProvider(): array + public static function emptyValueTestProvider(): array { return [ [ @@ -99,10 +98,9 @@ public function emptyValueTestProvider(): array * @param mixed $value The value to test. * * @return void - * - * @dataProvider emptyValueTestProvider */ - public function testEmptyValue($expected, $value): void + #[DataProvider('emptyValueTestProvider')] + public function testEmptyValue(bool $expected, mixed $value): void { $message = sprintf( ' %s === %s::isEmptyValue(%s)', diff --git a/tests/InformationProvider/MetaModelInformationCollectorTest.php b/tests/InformationProvider/MetaModelInformationCollectorTest.php index 19e9a1bd1..e1a5033a5 100644 --- a/tests/InformationProvider/MetaModelInformationCollectorTest.php +++ b/tests/InformationProvider/MetaModelInformationCollectorTest.php @@ -91,7 +91,7 @@ public function testGetCollection(): void { $collector = $this ->getMockBuilder(MetaModelInformationCollector::class) - ->setMethods(['getNames', 'getInformationFor']) + ->onlyMethods(['getNames', 'getInformationFor']) ->disableOriginalConstructor() ->getMock();