From d478663067afa13100bd078775b24ba91e1bf398 Mon Sep 17 00:00:00 2001 From: SonataCI Date: Sun, 14 Sep 2025 10:29:23 +0000 Subject: [PATCH 1/6] DevKit updates --- phpunit.xml.dist | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8b84e36a..bcca9224 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,37 +6,32 @@ DO NOT EDIT THIS FILE! It's auto-generated by sonata-project/dev-kit package. --> - - ./tests/ + ./tests/ - + - ./src/ + src - - - - - + - + - From 7625e2e2ea597f00d8d54264e2291a84ae8b45a7 Mon Sep 17 00:00:00 2001 From: SonataCI Date: Sun, 14 Sep 2025 12:24:12 +0000 Subject: [PATCH 2/6] DevKit updates --- rector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rector.php b/rector.php index 254341a3..085115f2 100644 --- a/rector.php +++ b/rector.php @@ -34,7 +34,7 @@ $rectorConfig->sets([ LevelSetList::UP_TO_PHP_81, - PHPUnitSetList::PHPUNIT_90, + PHPUnitSetList::PHPUNIT_100, PHPUnitSetList::PHPUNIT_CODE_QUALITY, ]); From 9679844ae2e2ca1b0f5c1db383d72c8305fc9a4a Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 14 Sep 2025 15:49:22 +0200 Subject: [PATCH 3/6] Fix --- composer.json | 7 +++---- tests/Controller/CategoryAdminControllerTest.php | 12 +++++------- tests/Functional/Admin/CategoryAdminTest.php | 6 +++--- tests/Functional/Admin/CollectionAdminTest.php | 7 +++---- tests/Functional/Admin/ContextAdminTest.php | 7 +++---- tests/Functional/Admin/TagAdminTest.php | 7 +++---- 6 files changed, 20 insertions(+), 26 deletions(-) diff --git a/composer.json b/composer.json index 47a90bf6..4122b742 100644 --- a/composer.json +++ b/composer.json @@ -49,15 +49,15 @@ "knplabs/knp-menu": "^3.0", "knplabs/knp-menu-bundle": "^3.0", "masterminds/html5": "^2.7", - "matthiasnoback/symfony-config-test": "^4.2 || ^5.1", - "matthiasnoback/symfony-dependency-injection-test": "^4.0 || ^5.0", + "matthiasnoback/symfony-config-test": "^6.1", + "matthiasnoback/symfony-dependency-injection-test": "^6.1", "phpstan/extension-installer": "^1.0", "phpstan/phpdoc-parser": "^1.0", "phpstan/phpstan": "^1.0 || ^2.0", "phpstan/phpstan-phpunit": "^1.0 || ^2.0", "phpstan/phpstan-strict-rules": "^1.0 || ^2.0", "phpstan/phpstan-symfony": "^1.0 || ^2.0", - "phpunit/phpunit": "^9.5", + "phpunit/phpunit": "^10.5.54 || ^11.5.38 || ^12.3.10", "psalm/plugin-phpunit": "^0.18 || ^0.19", "psalm/plugin-symfony": "^5.0", "rector/rector": "^1.1 || ^2.0", @@ -67,7 +67,6 @@ "symfony/asset": "^6.4 || ^7.1", "symfony/browser-kit": "^6.4 || ^7.1", "symfony/filesystem": "^6.4 || ^7.1", - "symfony/phpunit-bridge": "^6.4 || ^7.1", "symfony/security-bundle": "^6.4 || ^7.1", "symfony/security-csrf": "^6.4 || ^7.1", "symfony/twig-bundle": "^6.4 || ^7.1", diff --git a/tests/Controller/CategoryAdminControllerTest.php b/tests/Controller/CategoryAdminControllerTest.php index 7e9138cd..cc494519 100644 --- a/tests/Controller/CategoryAdminControllerTest.php +++ b/tests/Controller/CategoryAdminControllerTest.php @@ -13,6 +13,7 @@ namespace Sonata\ClassificationBundle\Tests\Controller; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -172,9 +173,7 @@ public function testListActionWithoutFilter(): void static::assertSame('tree?hide_context=0', $result->getTargetUrl()); } - /** - * @dataProvider provideListActionCases - */ + #[DataProvider('provideListActionCases')] public function testListAction(string|false $context): void { $contextValue = false === $context ? '' : $context; @@ -219,17 +218,16 @@ public function testListAction(string|false $context): void /** * @return iterable */ - public function provideListActionCases(): iterable + public static function provideListActionCases(): iterable { yield 'context' => ['default']; yield 'no context' => [false]; } /** - * @dataProvider provideTreeActionCases - * * @param array $categories */ + #[DataProvider('provideTreeActionCases')] public function testTreeAction(string|false $context, array $categories): void { $datagrid = $this->createMock(DatagridInterface::class); @@ -290,7 +288,7 @@ public function testTreeAction(string|false $context, array $categories): void /** * @return iterable}> */ - public function provideTreeActionCases(): iterable + public static function provideTreeActionCases(): iterable { yield 'context and no categories' => ['default', []]; yield 'no context and no categories' => [false, []]; diff --git a/tests/Functional/Admin/CategoryAdminTest.php b/tests/Functional/Admin/CategoryAdminTest.php index 04d4f274..042d86b7 100644 --- a/tests/Functional/Admin/CategoryAdminTest.php +++ b/tests/Functional/Admin/CategoryAdminTest.php @@ -13,6 +13,7 @@ namespace Sonata\ClassificationBundle\Tests\Functional\Admin; +use PHPUnit\Framework\Attributes\DataProvider; use Doctrine\ORM\EntityManagerInterface; use Sonata\ClassificationBundle\Tests\App\Entity\Category; use Sonata\ClassificationBundle\Tests\App\Entity\Context; @@ -22,9 +23,8 @@ final class CategoryAdminTest extends WebTestCase { /** * @param array $parameters - * - * @dataProvider provideCrudUrlsCases */ + #[DataProvider('provideCrudUrlsCases')] public function testCrudUrls(string $url, array $parameters = []): void { $client = self::createClient(); @@ -57,11 +57,11 @@ public static function provideCrudUrlsCases(): iterable } /** - * @dataProvider provideFormsUrlsCases * * @param array $parameters * @param array $fieldValues */ + #[DataProvider('provideFormsUrlsCases')] public function testFormsUrls(string $url, array $parameters, string $button, array $fieldValues = []): void { $client = self::createClient(); diff --git a/tests/Functional/Admin/CollectionAdminTest.php b/tests/Functional/Admin/CollectionAdminTest.php index c65e71da..60e1a8e9 100644 --- a/tests/Functional/Admin/CollectionAdminTest.php +++ b/tests/Functional/Admin/CollectionAdminTest.php @@ -13,6 +13,7 @@ namespace Sonata\ClassificationBundle\Tests\Functional\Admin; +use PHPUnit\Framework\Attributes\DataProvider; use Doctrine\ORM\EntityManagerInterface; use Sonata\ClassificationBundle\Tests\App\Entity\Collection; use Sonata\ClassificationBundle\Tests\App\Entity\Context; @@ -20,9 +21,7 @@ final class CollectionAdminTest extends WebTestCase { - /** - * @dataProvider provideCrudUrlsCases - */ + #[DataProvider('provideCrudUrlsCases')] public function testCrudUrls(string $url): void { $client = self::createClient(); @@ -48,11 +47,11 @@ public static function provideCrudUrlsCases(): iterable } /** - * @dataProvider provideFormsUrlsCases * * @param array $parameters * @param array $fieldValues */ + #[DataProvider('provideFormsUrlsCases')] public function testFormsUrls(string $url, array $parameters, string $button, array $fieldValues = []): void { $client = self::createClient(); diff --git a/tests/Functional/Admin/ContextAdminTest.php b/tests/Functional/Admin/ContextAdminTest.php index 054b41e8..33469f63 100644 --- a/tests/Functional/Admin/ContextAdminTest.php +++ b/tests/Functional/Admin/ContextAdminTest.php @@ -13,15 +13,14 @@ namespace Sonata\ClassificationBundle\Tests\Functional\Admin; +use PHPUnit\Framework\Attributes\DataProvider; use Doctrine\ORM\EntityManagerInterface; use Sonata\ClassificationBundle\Tests\App\Entity\Context; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; final class ContextAdminTest extends WebTestCase { - /** - * @dataProvider provideCrudUrlsCases - */ + #[DataProvider('provideCrudUrlsCases')] public function testCrudUrls(string $url): void { $client = self::createClient(); @@ -47,11 +46,11 @@ public static function provideCrudUrlsCases(): iterable } /** - * @dataProvider provideFormsUrlsCases * * @param array $parameters * @param array $fieldValues */ + #[DataProvider('provideFormsUrlsCases')] public function testFormsUrls(string $url, array $parameters, string $button, array $fieldValues = []): void { $client = self::createClient(); diff --git a/tests/Functional/Admin/TagAdminTest.php b/tests/Functional/Admin/TagAdminTest.php index b427654e..fd385c13 100644 --- a/tests/Functional/Admin/TagAdminTest.php +++ b/tests/Functional/Admin/TagAdminTest.php @@ -13,6 +13,7 @@ namespace Sonata\ClassificationBundle\Tests\Functional\Admin; +use PHPUnit\Framework\Attributes\DataProvider; use Doctrine\ORM\EntityManagerInterface; use Sonata\ClassificationBundle\Tests\App\Entity\Context; use Sonata\ClassificationBundle\Tests\App\Entity\Tag; @@ -20,9 +21,7 @@ final class TagAdminTest extends WebTestCase { - /** - * @dataProvider provideCrudUrlsCases - */ + #[DataProvider('provideCrudUrlsCases')] public function testCrudUrls(string $url): void { $client = self::createClient(); @@ -48,11 +47,11 @@ public static function provideCrudUrlsCases(): iterable } /** - * @dataProvider provideFormsUrlsCases * * @param array $parameters * @param array $fieldValues */ + #[DataProvider('provideFormsUrlsCases')] public function testFormsUrls(string $url, array $parameters, string $button, array $fieldValues = []): void { $client = self::createClient(); From 3f47f9512d64ff5d3f81dc2e457944e76ff4b42d Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 14 Sep 2025 16:03:05 +0200 Subject: [PATCH 4/6] Fix --- tests/Admin/AdminTest.php | 13 ++-- .../AbstractCategoriesBlockServiceTest.php | 28 ++------ .../AbstractCollectionsBlockServiceTest.php | 28 ++------ .../Service/AbstractTagsBlockServiceTest.php | 28 ++------ .../CategoryAdminControllerTest.php | 7 +- tests/Functional/Admin/CategoryAdminTest.php | 3 +- .../Functional/Admin/CollectionAdminTest.php | 3 +- tests/Functional/Admin/ContextAdminTest.php | 3 +- tests/Functional/Admin/TagAdminTest.php | 3 +- tests/Model/CategoryTest.php | 65 ++++++++++++++++--- tests/Model/CollectionTest.php | 21 +++++- tests/Model/ContextTest.php | 17 +++-- tests/Model/TagTest.php | 14 +++- 13 files changed, 135 insertions(+), 98 deletions(-) diff --git a/tests/Admin/AdminTest.php b/tests/Admin/AdminTest.php index 071b1bb0..bc5e0594 100644 --- a/tests/Admin/AdminTest.php +++ b/tests/Admin/AdminTest.php @@ -44,18 +44,19 @@ public function testGetPersistentParametersWithNoExtension(): void 'hide_context' => 0, ]; - $admin = $this->getMockForAbstractClass(ContextAwareAdmin::class, [ - $this->contextManager, - ]); + $admin = new class($this->contextManager) extends ContextAwareAdmin {}; static::assertSame($expected, $admin->getPersistentParameters()); } public function testGetPersistentParametersWithValidExtension(): void { - $admin = $this->getMockForAbstractClass(ContextAwareAdmin::class, [ - $this->contextManager, - ]); + $admin = new class($this->contextManager) extends ContextAwareAdmin { + public function __construct(ContextManagerInterface $contextManager) + { + parent::__construct($contextManager); + } + }; $extension = $this->createMock(AdminExtensionInterface::class); $extension->expects(static::once())->method('configurePersistentParameters')->with( diff --git a/tests/Block/Service/AbstractCategoriesBlockServiceTest.php b/tests/Block/Service/AbstractCategoriesBlockServiceTest.php index 8a08bc6a..b1460cdb 100644 --- a/tests/Block/Service/AbstractCategoriesBlockServiceTest.php +++ b/tests/Block/Service/AbstractCategoriesBlockServiceTest.php @@ -52,9 +52,7 @@ protected function setUp(): void public function testDefaultSettings(): void { - $blockService = $this->getMockForAbstractClass(AbstractCategoriesBlockService::class, [ - $this->twig, $this->contextManager, $this->categoryManager, $this->categoryAdmin, - ]); + $blockService = new class($this->twig, $this->contextManager, $this->categoryManager, $this->categoryAdmin) extends AbstractCategoriesBlockService {}; $blockContext = $this->getBlockContext($blockService); $this->assertSettings([ @@ -71,9 +69,7 @@ public function testDefaultSettings(): void public function testLoad(): void { - $category = $this->getMockBuilder(CategoryInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); + $category = $this->createMock(CategoryInterface::class); $category->expects(static::any())->method('getId')->willReturn(23); $this->categoryManager->expects(static::any()) @@ -90,17 +86,13 @@ public function testLoad(): void ->method('setSetting') ->with(static::equalTo('categoryId'), static::equalTo($category)); - $blockService = $this->getMockForAbstractClass(AbstractCategoriesBlockService::class, [ - $this->twig, $this->contextManager, $this->categoryManager, $this->categoryAdmin, - ]); + $blockService = new class($this->twig, $this->contextManager, $this->categoryManager, $this->categoryAdmin) extends AbstractCategoriesBlockService {}; $blockService->load($block); } public function testPrePersist(): void { - $category = $this->getMockBuilder(CategoryInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); + $category = $this->createMock(CategoryInterface::class); $category->expects(static::any())->method('getId')->willReturn(23); $block = $this->createMock(BlockInterface::class); @@ -112,17 +104,13 @@ public function testPrePersist(): void ->method('setSetting') ->with(static::equalTo('categoryId'), static::equalTo(23)); - $blockService = $this->getMockForAbstractClass(AbstractCategoriesBlockService::class, [ - $this->twig, $this->contextManager, $this->categoryManager, $this->categoryAdmin, - ]); + $blockService = new class($this->twig, $this->contextManager, $this->categoryManager, $this->categoryAdmin) extends AbstractCategoriesBlockService {}; $blockService->prePersist($block); } public function testPreUpdate(): void { - $category = $this->getMockBuilder(CategoryInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); + $category = $this->createMock(CategoryInterface::class); $category->expects(static::any())->method('getId')->willReturn(23); $block = $this->createMock(BlockInterface::class); @@ -134,9 +122,7 @@ public function testPreUpdate(): void ->method('setSetting') ->with(static::equalTo('categoryId'), static::equalTo(23)); - $blockService = $this->getMockForAbstractClass(AbstractCategoriesBlockService::class, [ - $this->twig, $this->contextManager, $this->categoryManager, $this->categoryAdmin, - ]); + $blockService = new class($this->twig, $this->contextManager, $this->categoryManager, $this->categoryAdmin) extends AbstractCategoriesBlockService {}; $blockService->preUpdate($block); } } diff --git a/tests/Block/Service/AbstractCollectionsBlockServiceTest.php b/tests/Block/Service/AbstractCollectionsBlockServiceTest.php index e4ca9a00..e46179b0 100644 --- a/tests/Block/Service/AbstractCollectionsBlockServiceTest.php +++ b/tests/Block/Service/AbstractCollectionsBlockServiceTest.php @@ -52,9 +52,7 @@ protected function setUp(): void public function testDefaultSettings(): void { - $blockService = $this->getMockForAbstractClass(AbstractCollectionsBlockService::class, [ - $this->twig, $this->contextManager, $this->collectionManager, $this->collectionAdmin, - ]); + $blockService = new class($this->twig, $this->contextManager, $this->collectionManager, $this->collectionAdmin) extends AbstractCollectionsBlockService {}; $blockContext = $this->getBlockContext($blockService); $this->assertSettings([ @@ -71,9 +69,7 @@ public function testDefaultSettings(): void public function testLoad(): void { - $collection = $this->getMockBuilder(CollectionInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); + $collection = $this->createMock(CollectionInterface::class); $collection->expects(static::any())->method('getId')->willReturn(23); $this->collectionManager->expects(static::any()) @@ -90,17 +86,13 @@ public function testLoad(): void ->method('setSetting') ->with(static::equalTo('collectionId'), static::equalTo($collection)); - $blockService = $this->getMockForAbstractClass(AbstractCollectionsBlockService::class, [ - $this->twig, $this->contextManager, $this->collectionManager, $this->collectionAdmin, - ]); + $blockService = new class($this->twig, $this->contextManager, $this->collectionManager, $this->collectionAdmin) extends AbstractCollectionsBlockService {}; $blockService->load($block); } public function testPrePersist(): void { - $collection = $this->getMockBuilder(CollectionInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); + $collection = $this->createMock(CollectionInterface::class); $collection->expects(static::any())->method('getId')->willReturn(23); $block = $this->createMock(BlockInterface::class); @@ -112,17 +104,13 @@ public function testPrePersist(): void ->method('setSetting') ->with(static::equalTo('collectionId'), static::equalTo(23)); - $blockService = $this->getMockForAbstractClass(AbstractCollectionsBlockService::class, [ - $this->twig, $this->contextManager, $this->collectionManager, $this->collectionAdmin, - ]); + $blockService = new class($this->twig, $this->contextManager, $this->collectionManager, $this->collectionAdmin) extends AbstractCollectionsBlockService {}; $blockService->prePersist($block); } public function testPreUpdate(): void { - $collection = $this->getMockBuilder(CollectionInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); + $collection = $this->createMock(CollectionInterface::class); $collection->expects(static::any())->method('getId')->willReturn(23); $block = $this->createMock(BlockInterface::class); @@ -134,9 +122,7 @@ public function testPreUpdate(): void ->method('setSetting') ->with(static::equalTo('collectionId'), static::equalTo(23)); - $blockService = $this->getMockForAbstractClass(AbstractCollectionsBlockService::class, [ - $this->twig, $this->contextManager, $this->collectionManager, $this->collectionAdmin, - ]); + $blockService = new class($this->twig, $this->contextManager, $this->collectionManager, $this->collectionAdmin) extends AbstractCollectionsBlockService {}; $blockService->preUpdate($block); } } diff --git a/tests/Block/Service/AbstractTagsBlockServiceTest.php b/tests/Block/Service/AbstractTagsBlockServiceTest.php index 636d4405..9f3e7c79 100644 --- a/tests/Block/Service/AbstractTagsBlockServiceTest.php +++ b/tests/Block/Service/AbstractTagsBlockServiceTest.php @@ -52,9 +52,7 @@ protected function setUp(): void public function testDefaultSettings(): void { - $blockService = $this->getMockForAbstractClass(AbstractTagsBlockService::class, [ - $this->twig, $this->contextManager, $this->tagManager, $this->tagAdmin, - ]); + $blockService = new class($this->twig, $this->contextManager, $this->tagManager, $this->tagAdmin) extends AbstractTagsBlockService {}; $blockContext = $this->getBlockContext($blockService); $this->assertSettings([ @@ -71,9 +69,7 @@ public function testDefaultSettings(): void public function testLoad(): void { - $tag = $this->getMockBuilder(TagInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); + $tag = $this->createMock(TagInterface::class); $tag->expects(static::any())->method('getId')->willReturn(23); $this->tagManager->expects(static::any()) @@ -90,17 +86,13 @@ public function testLoad(): void ->method('setSetting') ->with(static::equalTo('tagId'), static::equalTo($tag)); - $blockService = $this->getMockForAbstractClass(AbstractTagsBlockService::class, [ - $this->twig, $this->contextManager, $this->tagManager, $this->tagAdmin, - ]); + $blockService = new class($this->twig, $this->contextManager, $this->tagManager, $this->tagAdmin) extends AbstractTagsBlockService {}; $blockService->load($block); } public function testPrePersist(): void { - $tag = $this->getMockBuilder(TagInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); + $tag = $this->createMock(TagInterface::class); $tag->expects(static::any())->method('getId')->willReturn(23); $block = $this->createMock(BlockInterface::class); @@ -112,17 +104,13 @@ public function testPrePersist(): void ->method('setSetting') ->with(static::equalTo('tagId'), static::equalTo(23)); - $blockService = $this->getMockForAbstractClass(AbstractTagsBlockService::class, [ - $this->twig, $this->contextManager, $this->tagManager, $this->tagAdmin, - ]); + $blockService = new class($this->twig, $this->contextManager, $this->tagManager, $this->tagAdmin) extends AbstractTagsBlockService {}; $blockService->prePersist($block); } public function testPreUpdate(): void { - $tag = $this->getMockBuilder(TagInterface::class) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); + $tag = $this->createMock(TagInterface::class); $tag->expects(static::any())->method('getId')->willReturn(23); $block = $this->createMock(BlockInterface::class); @@ -134,9 +122,7 @@ public function testPreUpdate(): void ->method('setSetting') ->with(static::equalTo('tagId'), static::equalTo(23)); - $blockService = $this->getMockForAbstractClass(AbstractTagsBlockService::class, [ - $this->twig, $this->contextManager, $this->tagManager, $this->tagAdmin, - ]); + $blockService = new class($this->twig, $this->contextManager, $this->tagManager, $this->tagAdmin) extends AbstractTagsBlockService {}; $blockService->preUpdate($block); } } diff --git a/tests/Controller/CategoryAdminControllerTest.php b/tests/Controller/CategoryAdminControllerTest.php index cc494519..958e39c1 100644 --- a/tests/Controller/CategoryAdminControllerTest.php +++ b/tests/Controller/CategoryAdminControllerTest.php @@ -265,7 +265,12 @@ public function testTreeAction(string|false $context, array $categories): void $categoriesMock = []; foreach ($categories as $category) { - $categoryMock = $this->getMockForAbstractClass(Category::class); + $categoryMock = new class extends Category { + public function getId() + { + return 42; + } + }; $categoryMock->setName($category[0]); $contextId = $category[1]; diff --git a/tests/Functional/Admin/CategoryAdminTest.php b/tests/Functional/Admin/CategoryAdminTest.php index 042d86b7..db50cdd3 100644 --- a/tests/Functional/Admin/CategoryAdminTest.php +++ b/tests/Functional/Admin/CategoryAdminTest.php @@ -13,8 +13,8 @@ namespace Sonata\ClassificationBundle\Tests\Functional\Admin; -use PHPUnit\Framework\Attributes\DataProvider; use Doctrine\ORM\EntityManagerInterface; +use PHPUnit\Framework\Attributes\DataProvider; use Sonata\ClassificationBundle\Tests\App\Entity\Category; use Sonata\ClassificationBundle\Tests\App\Entity\Context; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; @@ -57,7 +57,6 @@ public static function provideCrudUrlsCases(): iterable } /** - * * @param array $parameters * @param array $fieldValues */ diff --git a/tests/Functional/Admin/CollectionAdminTest.php b/tests/Functional/Admin/CollectionAdminTest.php index 60e1a8e9..808240eb 100644 --- a/tests/Functional/Admin/CollectionAdminTest.php +++ b/tests/Functional/Admin/CollectionAdminTest.php @@ -13,8 +13,8 @@ namespace Sonata\ClassificationBundle\Tests\Functional\Admin; -use PHPUnit\Framework\Attributes\DataProvider; use Doctrine\ORM\EntityManagerInterface; +use PHPUnit\Framework\Attributes\DataProvider; use Sonata\ClassificationBundle\Tests\App\Entity\Collection; use Sonata\ClassificationBundle\Tests\App\Entity\Context; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; @@ -47,7 +47,6 @@ public static function provideCrudUrlsCases(): iterable } /** - * * @param array $parameters * @param array $fieldValues */ diff --git a/tests/Functional/Admin/ContextAdminTest.php b/tests/Functional/Admin/ContextAdminTest.php index 33469f63..7c38d6ef 100644 --- a/tests/Functional/Admin/ContextAdminTest.php +++ b/tests/Functional/Admin/ContextAdminTest.php @@ -13,8 +13,8 @@ namespace Sonata\ClassificationBundle\Tests\Functional\Admin; -use PHPUnit\Framework\Attributes\DataProvider; use Doctrine\ORM\EntityManagerInterface; +use PHPUnit\Framework\Attributes\DataProvider; use Sonata\ClassificationBundle\Tests\App\Entity\Context; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; @@ -46,7 +46,6 @@ public static function provideCrudUrlsCases(): iterable } /** - * * @param array $parameters * @param array $fieldValues */ diff --git a/tests/Functional/Admin/TagAdminTest.php b/tests/Functional/Admin/TagAdminTest.php index fd385c13..928e4e24 100644 --- a/tests/Functional/Admin/TagAdminTest.php +++ b/tests/Functional/Admin/TagAdminTest.php @@ -13,8 +13,8 @@ namespace Sonata\ClassificationBundle\Tests\Functional\Admin; -use PHPUnit\Framework\Attributes\DataProvider; use Doctrine\ORM\EntityManagerInterface; +use PHPUnit\Framework\Attributes\DataProvider; use Sonata\ClassificationBundle\Tests\App\Entity\Context; use Sonata\ClassificationBundle\Tests\App\Entity\Tag; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; @@ -47,7 +47,6 @@ public static function provideCrudUrlsCases(): iterable } /** - * * @param array $parameters * @param array $fieldValues */ diff --git a/tests/Model/CategoryTest.php b/tests/Model/CategoryTest.php index 65432726..ebf48485 100644 --- a/tests/Model/CategoryTest.php +++ b/tests/Model/CategoryTest.php @@ -28,7 +28,12 @@ public function testSetterGetter(): void $context = $this->createMock(ContextInterface::class); - $category = $this->getMockForAbstractClass(Category::class); + $category = new class extends Category { + public function getId() + { + return 42; + } + }; $category->setName('Hello World'); $category->setEnabled(true); $category->setDescription('My description'); @@ -61,9 +66,19 @@ public function testSetterGetter(): void public function testParent(): void { - $parent = $this->getMockForAbstractClass(Category::class); - - $category = $this->getMockForAbstractClass(Category::class); + $parent = new class extends Category { + public function getId() + { + return 33; + } + }; + + $category = new class extends Category { + public function getId() + { + return 42; + } + }; $category->setParent($parent); static::assertSame($parent, $category->getParent()); static::assertCount(1, $parent->getChildren()); @@ -71,13 +86,33 @@ public function testParent(): void public function testChildren(): void { - $cat1 = $this->getMockForAbstractClass(Category::class); - $cat2 = $this->getMockForAbstractClass(Category::class); - $cat3 = $this->getMockForAbstractClass(Category::class); + $cat1 = new class extends Category { + public function getId() + { + return 1; + } + }; + $cat2 = new class extends Category { + public function getId() + { + return 2; + } + }; + $cat3 = new class extends Category { + public function getId() + { + return 3; + } + }; $context = $this->createMock(ContextInterface::class); - $category = $this->getMockForAbstractClass(Category::class); + $category = new class extends Category { + public function getId() + { + return 42; + } + }; $category->setContext($context); static::assertFalse($category->hasChildren()); @@ -100,7 +135,12 @@ public function testChildren(): void public function testPrePersist(): void { - $category = $this->getMockForAbstractClass(Category::class); + $category = new class extends Category { + public function getId() + { + return 42; + } + }; $category->prePersist(); static::assertInstanceOf(\DateTime::class, $category->getCreatedAt()); @@ -109,7 +149,12 @@ public function testPrePersist(): void public function testPreUpdate(): void { - $category = $this->getMockForAbstractClass(Category::class); + $category = new class extends Category { + public function getId() + { + return 42; + } + }; $category->preUpdate(); static::assertInstanceOf(\DateTime::class, $category->getUpdatedAt()); diff --git a/tests/Model/CollectionTest.php b/tests/Model/CollectionTest.php index 74e1f2df..a29cf0d1 100644 --- a/tests/Model/CollectionTest.php +++ b/tests/Model/CollectionTest.php @@ -28,7 +28,12 @@ public function testSetterGetter(): void $context = $this->createMock(ContextInterface::class); - $collection = $this->getMockForAbstractClass(Collection::class); + $collection = new class extends Collection { + public function getId() + { + return 42; + } + }; $collection->setName('Hello World'); $collection->setCreatedAt($time); $collection->setUpdatedAt($time); @@ -59,7 +64,12 @@ public function testSetterGetter(): void public function testPrePersist(): void { - $collection = $this->getMockForAbstractClass(Collection::class); + $collection = new class extends Collection { + public function getId() + { + return 42; + } + }; $collection->prePersist(); static::assertInstanceOf(\DateTime::class, $collection->getCreatedAt()); @@ -68,7 +78,12 @@ public function testPrePersist(): void public function testPreUpdate(): void { - $collection = $this->getMockForAbstractClass(Collection::class); + $collection = new class extends Collection { + public function getId() + { + return 42; + } + }; $collection->preUpdate(); static::assertInstanceOf(\DateTime::class, $collection->getUpdatedAt()); diff --git a/tests/Model/ContextTest.php b/tests/Model/ContextTest.php index 61870372..796019c6 100644 --- a/tests/Model/ContextTest.php +++ b/tests/Model/ContextTest.php @@ -25,10 +25,12 @@ public function testSetterGetter(): void { $time = new \DateTime(); - $context = $this->getMockForAbstractClass(Context::class); - // id is an int in ContextInterface and Context but used as string in implementation - // see ContextInterface::DEFAULT_CONTEXT - $context->setId('2'); + $context = new class extends Context { + public function getId(): ?string + { + return '2'; + } + }; $context->setName('Hello World'); $context->setCreatedAt($time); $context->setUpdatedAt($time); @@ -46,7 +48,12 @@ public function testSetterGetter(): void public function testPreUpdate(): void { - $context = $this->getMockForAbstractClass(Context::class); + $context = new class extends Context { + public function getId(): ?string + { + return '42'; + } + }; $context->preUpdate(); static::assertInstanceOf(\DateTime::class, $context->getUpdatedAt()); diff --git a/tests/Model/TagTest.php b/tests/Model/TagTest.php index b36a99fb..f09aa42c 100644 --- a/tests/Model/TagTest.php +++ b/tests/Model/TagTest.php @@ -28,7 +28,12 @@ public function testSetterGetter(): void $context = $this->createMock(ContextInterface::class); - $tag = $this->getMockForAbstractClass(Tag::class); + $tag = new class extends Tag { + public function getId() + { + return 42; + } + }; $tag->setName('Hello World'); $tag->setCreatedAt($time); $tag->setUpdatedAt($time); @@ -57,7 +62,12 @@ public function testSetterGetter(): void public function testPreUpdate(): void { - $tag = $this->getMockForAbstractClass(Tag::class); + $tag = new class extends Tag { + public function getId() + { + return 42; + } + }; $tag->preUpdate(); static::assertInstanceOf(\DateTime::class, $tag->getUpdatedAt()); From 118803031e59895d3b05e4e678768f2bd20a8613 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 14 Sep 2025 16:08:30 +0200 Subject: [PATCH 5/6] Fix --- tests/Admin/AdminTest.php | 4 ++ .../CategoryAdminControllerTest.php | 2 +- tests/Entity/CategoryTest.php | 40 ------------------- tests/Model/CategoryTest.php | 18 ++++----- tests/Model/CollectionTest.php | 6 +-- tests/Model/TagTest.php | 4 +- 6 files changed, 19 insertions(+), 55 deletions(-) delete mode 100644 tests/Entity/CategoryTest.php diff --git a/tests/Admin/AdminTest.php b/tests/Admin/AdminTest.php index bc5e0594..b132e59d 100644 --- a/tests/Admin/AdminTest.php +++ b/tests/Admin/AdminTest.php @@ -13,11 +13,13 @@ namespace Sonata\ClassificationBundle\Tests\Admin; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Sonata\AdminBundle\Admin\AbstractAdmin; use Sonata\AdminBundle\Admin\AdminExtensionInterface; use Sonata\ClassificationBundle\Admin\ContextAdmin; use Sonata\ClassificationBundle\Admin\ContextAwareAdmin; +use Sonata\ClassificationBundle\Model\ContextAwareInterface; use Sonata\ClassificationBundle\Model\ContextManagerInterface; final class AdminTest extends TestCase @@ -44,6 +46,7 @@ public function testGetPersistentParametersWithNoExtension(): void 'hide_context' => 0, ]; + /** @phpstan-extends ContextAwareAdmin */ $admin = new class($this->contextManager) extends ContextAwareAdmin {}; static::assertSame($expected, $admin->getPersistentParameters()); @@ -51,6 +54,7 @@ public function testGetPersistentParametersWithNoExtension(): void public function testGetPersistentParametersWithValidExtension(): void { + /** @phpstan-extends ContextAwareAdmin */ $admin = new class($this->contextManager) extends ContextAwareAdmin { public function __construct(ContextManagerInterface $contextManager) { diff --git a/tests/Controller/CategoryAdminControllerTest.php b/tests/Controller/CategoryAdminControllerTest.php index 958e39c1..8f4d8ddc 100644 --- a/tests/Controller/CategoryAdminControllerTest.php +++ b/tests/Controller/CategoryAdminControllerTest.php @@ -266,7 +266,7 @@ public function testTreeAction(string|false $context, array $categories): void $categoriesMock = []; foreach ($categories as $category) { $categoryMock = new class extends Category { - public function getId() + public function getId(): int { return 42; } diff --git a/tests/Entity/CategoryTest.php b/tests/Entity/CategoryTest.php deleted file mode 100644 index bee56729..00000000 --- a/tests/Entity/CategoryTest.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Sonata\ClassificationBundle\Tests\Entity; - -use Sonata\ClassificationBundle\Entity\BaseCategory; - -abstract class CategoryTest extends BaseCategory -{ - /** - * @var int|string|null - */ - private $id; - - /** - * @param int|string|null $id - */ - public function setId($id): void - { - $this->id = $id; - } - - /** - * @return int|string|null - */ - public function getId() - { - return $this->id; - } -} diff --git a/tests/Model/CategoryTest.php b/tests/Model/CategoryTest.php index ebf48485..b7f0d31a 100644 --- a/tests/Model/CategoryTest.php +++ b/tests/Model/CategoryTest.php @@ -29,7 +29,7 @@ public function testSetterGetter(): void $context = $this->createMock(ContextInterface::class); $category = new class extends Category { - public function getId() + public function getId(): int { return 42; } @@ -67,14 +67,14 @@ public function getId() public function testParent(): void { $parent = new class extends Category { - public function getId() + public function getId(): int { return 33; } }; $category = new class extends Category { - public function getId() + public function getId(): int { return 42; } @@ -87,19 +87,19 @@ public function getId() public function testChildren(): void { $cat1 = new class extends Category { - public function getId() + public function getId(): int { return 1; } }; $cat2 = new class extends Category { - public function getId() + public function getId(): int { return 2; } }; $cat3 = new class extends Category { - public function getId() + public function getId(): int { return 3; } @@ -108,7 +108,7 @@ public function getId() $context = $this->createMock(ContextInterface::class); $category = new class extends Category { - public function getId() + public function getId(): int { return 42; } @@ -136,7 +136,7 @@ public function getId() public function testPrePersist(): void { $category = new class extends Category { - public function getId() + public function getId(): int { return 42; } @@ -150,7 +150,7 @@ public function getId() public function testPreUpdate(): void { $category = new class extends Category { - public function getId() + public function getId(): int { return 42; } diff --git a/tests/Model/CollectionTest.php b/tests/Model/CollectionTest.php index a29cf0d1..2cfb3258 100644 --- a/tests/Model/CollectionTest.php +++ b/tests/Model/CollectionTest.php @@ -29,7 +29,7 @@ public function testSetterGetter(): void $context = $this->createMock(ContextInterface::class); $collection = new class extends Collection { - public function getId() + public function getId(): int { return 42; } @@ -65,7 +65,7 @@ public function getId() public function testPrePersist(): void { $collection = new class extends Collection { - public function getId() + public function getId(): int { return 42; } @@ -79,7 +79,7 @@ public function getId() public function testPreUpdate(): void { $collection = new class extends Collection { - public function getId() + public function getId(): int { return 42; } diff --git a/tests/Model/TagTest.php b/tests/Model/TagTest.php index f09aa42c..008cd40d 100644 --- a/tests/Model/TagTest.php +++ b/tests/Model/TagTest.php @@ -29,7 +29,7 @@ public function testSetterGetter(): void $context = $this->createMock(ContextInterface::class); $tag = new class extends Tag { - public function getId() + public function getId(): int { return 42; } @@ -63,7 +63,7 @@ public function getId() public function testPreUpdate(): void { $tag = new class extends Tag { - public function getId() + public function getId(): int { return 42; } From 17d802597be3ed747e5dd42b3afc784880959290 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 14 Sep 2025 16:12:32 +0200 Subject: [PATCH 6/6] Fix --- tests/Admin/AdminTest.php | 19 ++++++++++--------- tests/Entity/ContextTest.php | 20 -------------------- tests/Model/ContextTest.php | 4 ++-- 3 files changed, 12 insertions(+), 31 deletions(-) delete mode 100644 tests/Entity/ContextTest.php diff --git a/tests/Admin/AdminTest.php b/tests/Admin/AdminTest.php index b132e59d..52ab5b97 100644 --- a/tests/Admin/AdminTest.php +++ b/tests/Admin/AdminTest.php @@ -13,7 +13,6 @@ namespace Sonata\ClassificationBundle\Tests\Admin; -use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Sonata\AdminBundle\Admin\AbstractAdmin; use Sonata\AdminBundle\Admin\AdminExtensionInterface; @@ -46,21 +45,23 @@ public function testGetPersistentParametersWithNoExtension(): void 'hide_context' => 0, ]; + $admin = new /** @phpstan-extends ContextAwareAdmin */ - $admin = new class($this->contextManager) extends ContextAwareAdmin {}; + class($this->contextManager) extends ContextAwareAdmin {}; static::assertSame($expected, $admin->getPersistentParameters()); } public function testGetPersistentParametersWithValidExtension(): void { - /** @phpstan-extends ContextAwareAdmin */ - $admin = new class($this->contextManager) extends ContextAwareAdmin { - public function __construct(ContextManagerInterface $contextManager) - { - parent::__construct($contextManager); - } - }; + $admin = new + /** @phpstan-extends ContextAwareAdmin */ + class($this->contextManager) extends ContextAwareAdmin { + public function __construct(ContextManagerInterface $contextManager) + { + parent::__construct($contextManager); + } + }; $extension = $this->createMock(AdminExtensionInterface::class); $extension->expects(static::once())->method('configurePersistentParameters')->with( diff --git a/tests/Entity/ContextTest.php b/tests/Entity/ContextTest.php deleted file mode 100644 index 9b6eadaf..00000000 --- a/tests/Entity/ContextTest.php +++ /dev/null @@ -1,20 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Sonata\ClassificationBundle\Tests\Entity; - -use Sonata\ClassificationBundle\Entity\BaseContext; - -abstract class ContextTest extends BaseContext -{ -} diff --git a/tests/Model/ContextTest.php b/tests/Model/ContextTest.php index 796019c6..e301972a 100644 --- a/tests/Model/ContextTest.php +++ b/tests/Model/ContextTest.php @@ -26,7 +26,7 @@ public function testSetterGetter(): void $time = new \DateTime(); $context = new class extends Context { - public function getId(): ?string + public function getId(): string { return '2'; } @@ -49,7 +49,7 @@ public function getId(): ?string public function testPreUpdate(): void { $context = new class extends Context { - public function getId(): ?string + public function getId(): string { return '42'; }