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/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 - - - - - + - + - 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, ]); diff --git a/tests/Admin/AdminTest.php b/tests/Admin/AdminTest.php index 071b1bb0..52ab5b97 100644 --- a/tests/Admin/AdminTest.php +++ b/tests/Admin/AdminTest.php @@ -18,6 +18,7 @@ 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,18 +45,23 @@ public function testGetPersistentParametersWithNoExtension(): void 'hide_context' => 0, ]; - $admin = $this->getMockForAbstractClass(ContextAwareAdmin::class, [ - $this->contextManager, - ]); + $admin = new + /** @phpstan-extends ContextAwareAdmin */ + class($this->contextManager) extends ContextAwareAdmin {}; static::assertSame($expected, $admin->getPersistentParameters()); } public function testGetPersistentParametersWithValidExtension(): void { - $admin = $this->getMockForAbstractClass(ContextAwareAdmin::class, [ - $this->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/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 7e9138cd..8f4d8ddc 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); @@ -267,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(): int + { + return 42; + } + }; $categoryMock->setName($category[0]); $contextId = $category[1]; @@ -290,7 +293,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/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/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/Functional/Admin/CategoryAdminTest.php b/tests/Functional/Admin/CategoryAdminTest.php index 04d4f274..db50cdd3 100644 --- a/tests/Functional/Admin/CategoryAdminTest.php +++ b/tests/Functional/Admin/CategoryAdminTest.php @@ -14,6 +14,7 @@ namespace Sonata\ClassificationBundle\Tests\Functional\Admin; 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; @@ -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,10 @@ 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..808240eb 100644 --- a/tests/Functional/Admin/CollectionAdminTest.php +++ b/tests/Functional/Admin/CollectionAdminTest.php @@ -14,15 +14,14 @@ namespace Sonata\ClassificationBundle\Tests\Functional\Admin; 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; final class CollectionAdminTest extends WebTestCase { - /** - * @dataProvider provideCrudUrlsCases - */ + #[DataProvider('provideCrudUrlsCases')] public function testCrudUrls(string $url): void { $client = self::createClient(); @@ -48,11 +47,10 @@ 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..7c38d6ef 100644 --- a/tests/Functional/Admin/ContextAdminTest.php +++ b/tests/Functional/Admin/ContextAdminTest.php @@ -14,14 +14,13 @@ namespace Sonata\ClassificationBundle\Tests\Functional\Admin; use Doctrine\ORM\EntityManagerInterface; +use PHPUnit\Framework\Attributes\DataProvider; 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,10 @@ 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..928e4e24 100644 --- a/tests/Functional/Admin/TagAdminTest.php +++ b/tests/Functional/Admin/TagAdminTest.php @@ -14,15 +14,14 @@ namespace Sonata\ClassificationBundle\Tests\Functional\Admin; 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; final class TagAdminTest extends WebTestCase { - /** - * @dataProvider provideCrudUrlsCases - */ + #[DataProvider('provideCrudUrlsCases')] public function testCrudUrls(string $url): void { $client = self::createClient(); @@ -48,11 +47,10 @@ 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/Model/CategoryTest.php b/tests/Model/CategoryTest.php index 65432726..b7f0d31a 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(): int + { + 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(): int + { + return 33; + } + }; + + $category = new class extends Category { + public function getId(): int + { + 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(): int + { + return 1; + } + }; + $cat2 = new class extends Category { + public function getId(): int + { + return 2; + } + }; + $cat3 = new class extends Category { + public function getId(): int + { + return 3; + } + }; $context = $this->createMock(ContextInterface::class); - $category = $this->getMockForAbstractClass(Category::class); + $category = new class extends Category { + public function getId(): int + { + 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(): int + { + 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(): int + { + return 42; + } + }; $category->preUpdate(); static::assertInstanceOf(\DateTime::class, $category->getUpdatedAt()); diff --git a/tests/Model/CollectionTest.php b/tests/Model/CollectionTest.php index 74e1f2df..2cfb3258 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(): int + { + 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(): int + { + 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(): int + { + return 42; + } + }; $collection->preUpdate(); static::assertInstanceOf(\DateTime::class, $collection->getUpdatedAt()); diff --git a/tests/Model/ContextTest.php b/tests/Model/ContextTest.php index 61870372..e301972a 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..008cd40d 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(): int + { + 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(): int + { + return 42; + } + }; $tag->preUpdate(); static::assertInstanceOf(\DateTime::class, $tag->getUpdatedAt());