From cd9f5fcf91649e443057d00c5c7376fc08c51446 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 28 Mar 2021 12:55:52 +0200 Subject: [PATCH] Bump psalm --- psalm.xml | 2 +- src/Admin/AbstractAdmin.php | 14 +++++++++----- src/Admin/AdminInterface.php | 5 ++++- src/Builder/RouteBuilderInterface.php | 3 +++ .../Admin/AbstractTaggedAdmin.php | 1 + src/Mapper/BaseGroupedMapper.php | 1 + src/Model/AuditManager.php | 5 ++++- src/Route/PathInfoBuilder.php | 3 --- src/Route/RouteCollection.php | 2 ++ src/Twig/Extension/SonataAdminExtension.php | 4 ++-- .../Action/AppendFormFieldElementActionTest.php | 2 +- .../RetrieveAutocompleteItemsActionTest.php | 6 +++--- .../RetrieveFormFieldElementActionTest.php | 2 +- tests/Action/SetObjectFieldValueActionTest.php | 12 ++++++------ tests/Admin/AdminHelperTest.php | 6 +++--- tests/Admin/BreadcrumbsBuilderTest.php | 16 ++++++++-------- tests/Admin/PoolTest.php | 12 ++++-------- tests/Block/AdminSearchBlockServiceTest.php | 2 +- .../ModelToIdPropertyTransformerTest.php | 4 ++++ .../DataTransformer/ModelToIdTransformerTest.php | 15 ++++++++------- .../ModelsToArrayTransformerTest.php | 6 +++--- tests/Maker/AdminMakerTest.php | 2 +- tests/Menu/Integration/TabMenuTest.php | 4 ++-- tests/Twig/Extension/SecurityExtensionTest.php | 2 +- .../Extension/TemplateRegistryExtensionTest.php | 5 +++-- tests/Util/AdminObjectAclManipulatorTest.php | 2 +- 26 files changed, 77 insertions(+), 61 deletions(-) diff --git a/psalm.xml b/psalm.xml index 235e48dd75f..12d2090d114 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,5 +1,5 @@ - + diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index e319a925282..9815c2fa133 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -757,6 +757,7 @@ final public function getBatchActions(): array final public function getRoutes(): RouteCollectionInterface { $this->buildRoutes(); + \assert($this->routes !== null); return $this->routes; } @@ -906,8 +907,6 @@ final public function attachAdminClass(FieldDescriptionInterface $fieldDescripti } /** - * @param string|int|null $id - * * @phpstan-return T|null */ final public function getObject($id): ?object @@ -968,9 +967,6 @@ final public function getDatagrid(): DatagridInterface return $this->datagrid; } - /** - * @phpstan-param AdminInterface|null $childAdmin - */ final public function getSideMenu(string $action, ?AdminInterface $childAdmin = null): ItemInterface { if ($this->isChild()) { @@ -978,6 +974,7 @@ final public function getSideMenu(string $action, ?AdminInterface $childAdmin = } $this->buildTabMenu($action, $childAdmin); + \assert($this->menu !== null); return $this->menu; } @@ -1101,6 +1098,7 @@ final public function getParentFieldDescription(): FieldDescriptionInterface static::class )); } + \assert($this->parentFieldDescription !== null); return $this->parentFieldDescription; } @@ -1132,6 +1130,7 @@ final public function getSubject(): object static::class )); } + \assert($this->subject !== null); return $this->subject; } @@ -1598,6 +1597,7 @@ public function id(object $model): ?string final public function getShow(): FieldDescriptionCollection { $this->buildShow(); + \assert($this->show !== null); return $this->show; } @@ -1883,6 +1883,7 @@ final public function getTemplateRegistry(): MutableTemplateRegistryInterface if (false === $this->hasTemplateRegistry()) { throw new \LogicException(sprintf('Unable to find the template registry for admin `%s`.', static::class)); } + \assert($this->templateRegistry !== null); return $this->templateRegistry; } @@ -2408,6 +2409,9 @@ private function buildRoutes(): void } } + /** + * @phpstan-param AdminInterface|null $childAdmin + */ private function buildTabMenu(string $action, ?AdminInterface $childAdmin = null): void { if ($this->loaded['tab_menu']) { diff --git a/src/Admin/AdminInterface.php b/src/Admin/AdminInterface.php index a940446eecc..c9d688a081e 100644 --- a/src/Admin/AdminInterface.php +++ b/src/Admin/AdminInterface.php @@ -197,7 +197,7 @@ public function getUniqid(): string; public function getClassnameLabel(): string; /** - * @param mixed $id + * @param string|int|null $id * * @phpstan-return T|null */ @@ -483,6 +483,9 @@ public function getBaseRoutePattern(): string; */ public function getBaseRouteName(): string; + /** + * @param AdminInterface|null $childAdmin + */ public function getSideMenu(string $action, ?self $childAdmin = null): ItemInterface; public function addParentAssociationMapping(string $code, string $value): void; diff --git a/src/Builder/RouteBuilderInterface.php b/src/Builder/RouteBuilderInterface.php index e03ac1f8989..a103a9edeb3 100644 --- a/src/Builder/RouteBuilderInterface.php +++ b/src/Builder/RouteBuilderInterface.php @@ -21,5 +21,8 @@ */ interface RouteBuilderInterface { + /** + * @param AdminInterface $admin + */ public function build(AdminInterface $admin, RouteCollectionInterface $collection): void; } diff --git a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php index 210b914d6c1..91b240002de 100644 --- a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php +++ b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php @@ -270,6 +270,7 @@ final public function getFilterPersister(): FilterPersisterInterface if (!$this->hasFilterPersister()) { throw new \LogicException(sprintf('Admin "%s" has no filter persister.', static::class)); } + \assert($this->filterPersister !== null); return $this->filterPersister; } diff --git a/src/Mapper/BaseGroupedMapper.php b/src/Mapper/BaseGroupedMapper.php index a8963cd2a64..73e0d5065f7 100644 --- a/src/Mapper/BaseGroupedMapper.php +++ b/src/Mapper/BaseGroupedMapper.php @@ -372,6 +372,7 @@ protected function getCurrentGroupName(): string ]); } } + \assert($this->currentGroup !== null); return $this->currentGroup; } diff --git a/src/Model/AuditManager.php b/src/Model/AuditManager.php index e3668b3e288..11215e0aa11 100644 --- a/src/Model/AuditManager.php +++ b/src/Model/AuditManager.php @@ -56,7 +56,10 @@ public function getReader(string $class): AuditReaderInterface { foreach ($this->readers as $readerId => $classes) { if (\in_array($class, $classes, true)) { - return $this->container->get($readerId); + $reader = $this->container->get($readerId); + \assert($reader instanceof AuditReaderInterface); + + return $reader; } } diff --git a/src/Route/PathInfoBuilder.php b/src/Route/PathInfoBuilder.php index 18f6a56e671..d8283f211b1 100644 --- a/src/Route/PathInfoBuilder.php +++ b/src/Route/PathInfoBuilder.php @@ -32,9 +32,6 @@ public function __construct(AuditManagerInterface $manager) $this->manager = $manager; } - /** - * @param AdminInterface $admin - */ public function build(AdminInterface $admin, RouteCollectionInterface $collection): void { $collection->add('list'); diff --git a/src/Route/RouteCollection.php b/src/Route/RouteCollection.php index 3105609ac1d..80d8d9c8f4d 100644 --- a/src/Route/RouteCollection.php +++ b/src/Route/RouteCollection.php @@ -177,6 +177,8 @@ public function restore(string $name): RouteCollectionInterface /** * @param string|string[] $routeList + * + * @return static */ public function clearExcept($routeList): RouteCollectionInterface { diff --git a/src/Twig/Extension/SonataAdminExtension.php b/src/Twig/Extension/SonataAdminExtension.php index 8eb26ab01c3..fc3f607baf8 100644 --- a/src/Twig/Extension/SonataAdminExtension.php +++ b/src/Twig/Extension/SonataAdminExtension.php @@ -55,13 +55,13 @@ public function getName(): string /** * Get the identifiers as a string that is safe to use in a url. * - * @return string string representation of the id that is safe to use in a url + * @return string|null representation of the id that is safe to use in a url * * @phpstan-template T of object * @phpstan-param T $model * @phpstan-param AdminInterface|null $admin */ - public function getUrlSafeIdentifier(object $model, ?AdminInterface $admin = null): string + public function getUrlSafeIdentifier(object $model, ?AdminInterface $admin = null): ?string { if (null === $admin) { /** @phpstan-var class-string $class */ diff --git a/tests/Action/AppendFormFieldElementActionTest.php b/tests/Action/AppendFormFieldElementActionTest.php index eb9d745794d..13510676dd1 100644 --- a/tests/Action/AppendFormFieldElementActionTest.php +++ b/tests/Action/AppendFormFieldElementActionTest.php @@ -84,7 +84,7 @@ public function testAppendFormFieldElementAction(): void 'context' => 'list', ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST]); - $modelManager = $this->createStub(ModelManagerInterface::class); + $modelManager = $this->createMock(ModelManagerInterface::class); $formView = new FormView(); $form = $this->createStub(Form::class); $renderer = $this->configureFormRenderer(); diff --git a/tests/Action/RetrieveAutocompleteItemsActionTest.php b/tests/Action/RetrieveAutocompleteItemsActionTest.php index 565b77fbfc1..8991eb5e545 100644 --- a/tests/Action/RetrieveAutocompleteItemsActionTest.php +++ b/tests/Action/RetrieveAutocompleteItemsActionTest.php @@ -263,7 +263,7 @@ private function configureAutocompleteItemsDatagrid(): MockObject private function configureFormConfig(string $field, bool $disabled = false): void { - $form = $this->createStub(Form::class); + $form = $this->createMock(Form::class); $formType = $this->createStub(Form::class); $formConfig = $this->createStub(FormConfigInterface::class); @@ -285,7 +285,7 @@ private function configureFormConfig(string $field, bool $disabled = false): voi private function configureFormConfigComplexProperty(string $field): void { - $form = $this->createStub(Form::class); + $form = $this->createMock(Form::class); $formType = $this->createStub(Form::class); $formConfig = $this->createStub(FormConfigInterface::class); @@ -306,7 +306,7 @@ private function configureFormConfigComplexProperty(string $field): void private function configureFormConfigComplexPropertyArray(string $field): void { - $form = $this->createStub(Form::class); + $form = $this->createMock(Form::class); $formType = $this->createStub(Form::class); $formConfig = $this->createStub(FormConfigInterface::class); diff --git a/tests/Action/RetrieveFormFieldElementActionTest.php b/tests/Action/RetrieveFormFieldElementActionTest.php index 8591d41a6f1..535bd629af9 100644 --- a/tests/Action/RetrieveFormFieldElementActionTest.php +++ b/tests/Action/RetrieveFormFieldElementActionTest.php @@ -84,7 +84,7 @@ public function testRetrieveFormFieldElementAction(): void 'context' => 'list', ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST]); - $modelManager = $this->createStub(ModelManagerInterface::class); + $modelManager = $this->createMock(ModelManagerInterface::class); $formView = new FormView(); $form = $this->createMock(Form::class); $formBuilder = $this->createStub(FormBuilder::class); diff --git a/tests/Action/SetObjectFieldValueActionTest.php b/tests/Action/SetObjectFieldValueActionTest.php index 3d67bd6a037..b515ca39712 100644 --- a/tests/Action/SetObjectFieldValueActionTest.php +++ b/tests/Action/SetObjectFieldValueActionTest.php @@ -120,7 +120,7 @@ public function testSetObjectFieldValueAction(): void ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']); $fieldDescription = $this->createStub(FieldDescriptionInterface::class); - $templateRegistry = $this->createStub(TemplateRegistryInterface::class); + $templateRegistry = $this->createMock(TemplateRegistryInterface::class); $container = new Container(); $this->admin->method('getObject')->with(42)->willReturn($object); @@ -181,7 +181,7 @@ public function testSetObjectFieldValueActionWithDate($timezone, \DateTimeZone $ ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']); $fieldDescription = $this->createStub(FieldDescriptionInterface::class); - $templateRegistry = $this->createStub(TemplateRegistryInterface::class); + $templateRegistry = $this->createMock(TemplateRegistryInterface::class); $container = new Container(); $this->admin->method('getObject')->with(42)->willReturn($object); @@ -235,7 +235,7 @@ public function testSetObjectFieldValueActionOnARelationField(): void ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']); $fieldDescription = $this->createStub(FieldDescriptionInterface::class); - $templateRegistry = $this->createStub(TemplateRegistryInterface::class); + $templateRegistry = $this->createMock(TemplateRegistryInterface::class); $container = new Container(); $this->admin->method('getObject')->with(42)->willReturn($object); @@ -319,7 +319,7 @@ public function testSetObjectFieldEditableMultipleValue(): void ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']); $fieldDescription = $this->createStub(FieldDescriptionInterface::class); - $templateRegistry = $this->createStub(TemplateRegistryInterface::class); + $templateRegistry = $this->createMock(TemplateRegistryInterface::class); $container = new Container(); $this->admin->method('getObject')->with(42)->willReturn($object); @@ -371,7 +371,7 @@ public function testSetObjectFieldTransformed(): void }); $fieldDescription = $this->createStub(FieldDescriptionInterface::class); - $templateRegistry = $this->createStub(TemplateRegistryInterface::class); + $templateRegistry = $this->createMock(TemplateRegistryInterface::class); $container = new Container(); $this->admin->method('getObject')->with(42)->willReturn($object); @@ -425,7 +425,7 @@ public function testSetObjectFieldOverrideTransformer(): void }); $fieldDescription = $this->createStub(FieldDescriptionInterface::class); - $templateRegistry = $this->createStub(TemplateRegistryInterface::class); + $templateRegistry = $this->createMock(TemplateRegistryInterface::class); $container = new Container(); $this->admin->method('getObject')->with(42)->willReturn($object); diff --git a/tests/Admin/AdminHelperTest.php b/tests/Admin/AdminHelperTest.php index 0aced01ae8e..c507e9e5e2c 100644 --- a/tests/Admin/AdminHelperTest.php +++ b/tests/Admin/AdminHelperTest.php @@ -135,7 +135,7 @@ public function testItThrowsExceptionWhenDoesNotFindTheFullPath(): void public function testAppendFormFieldElement(): void { - $admin = $this->createStub(AdminInterface::class); + $admin = $this->createMock(AdminInterface::class); $admin ->method('getClass') ->willReturn(Foo::class); @@ -249,7 +249,7 @@ public function testAppendFormFieldElement(): void public function testAppendFormFieldElementWithoutFormFieldDescriptionInAdminAndNoCollectionClass(): void { - $admin = $this->createStub(AdminInterface::class); + $admin = $this->createMock(AdminInterface::class); $admin ->method('getClass') ->willReturn(Foo::class); @@ -341,7 +341,7 @@ public function testAppendFormFieldElementWithoutFormFieldDescriptionInAdminAndN public function testAppendFormFieldElementWithCollection(): void { - $admin = $this->createStub(AdminInterface::class); + $admin = $this->createMock(AdminInterface::class); $admin ->method('getClass') ->willReturn(Foo::class); diff --git a/tests/Admin/BreadcrumbsBuilderTest.php b/tests/Admin/BreadcrumbsBuilderTest.php index 81342f63166..c2232f16316 100644 --- a/tests/Admin/BreadcrumbsBuilderTest.php +++ b/tests/Admin/BreadcrumbsBuilderTest.php @@ -35,13 +35,13 @@ public function testChildGetBreadCrumbs(): void { $action = 'my_action'; $breadcrumbsBuilder = new BreadcrumbsBuilder(['child_admin_route' => 'show']); - $admin = $this->createStub(AdminInterface::class); + $admin = $this->createMock(AdminInterface::class); $admin->method('isChild')->willReturn(false); $admin->method('getMenuFactory')->willReturn(new MenuFactory()); $labelTranslatorStrategy = $this->createStub(LabelTranslatorStrategyInterface::class); - $routeGenerator = $this->createStub(RouteGeneratorInterface::class); + $routeGenerator = $this->createMock(RouteGeneratorInterface::class); $routeGenerator->method('generate')->with('sonata_admin_dashboard')->willReturn('/dashboard'); $admin->method('getRouteGenerator')->willReturn($routeGenerator); @@ -84,7 +84,7 @@ public function testChildGetBreadCrumbs(): void ]); $admin->method('getCurrentChildAdmin')->willReturn($childAdmin); - $request = $this->createStub(Request::class); + $request = $this->createMock(Request::class); $request->method('get')->with('slug')->willReturn('my-object'); $admin->method('getIdParameter')->willReturn('slug'); @@ -153,13 +153,13 @@ public function testBuildBreadcrumbs(string $action): void $breadcrumbsBuilder = new BreadcrumbsBuilder(); $menu = $this->createMock(ItemInterface::class); - $menuFactory = $this->createStub(MenuFactory::class); + $menuFactory = $this->createMock(MenuFactory::class); $menuFactory->method('createItem')->with('root')->willReturn($menu); - $admin = $this->createStub(AdminInterface::class); + $admin = $this->createMock(AdminInterface::class); $admin->method('getMenuFactory')->willReturn($menuFactory); $labelTranslatorStrategy = $this->createStub(LabelTranslatorStrategyInterface::class); - $routeGenerator = $this->createStub(RouteGeneratorInterface::class); + $routeGenerator = $this->createMock(RouteGeneratorInterface::class); $routeGenerator->method('generate')->with('sonata_admin_dashboard')->willReturn('/dashboard'); $admin->method('getRouteGenerator')->willReturn($routeGenerator); @@ -200,7 +200,7 @@ public function testBuildBreadcrumbs(string $action): void ['my_class_name_create', 'breadcrumb', 'link', 'create my object'], ]); - $childAdmin = $this->createStub(AdminInterface::class); + $childAdmin = $this->createMock(AdminInterface::class); $childAdmin->method('getTranslationDomain')->willReturn('ChildBundle'); $childAdmin->method('getLabelTranslatorStrategy')->willReturn($labelTranslatorStrategy); $childAdmin->method('getClassnameLabel')->willReturn('my_child_class_name'); @@ -223,7 +223,7 @@ public function testBuildBreadcrumbs(string $action): void $menu->expects($this->never())->method('setUri'); } - $request = $this->createStub(Request::class); + $request = $this->createMock(Request::class); $request->method('get')->with('slug')->willReturn('my-object'); $admin->method('getIdParameter')->willReturn('slug'); diff --git a/tests/Admin/PoolTest.php b/tests/Admin/PoolTest.php index 556a6aeefa7..f9d68392a7b 100644 --- a/tests/Admin/PoolTest.php +++ b/tests/Admin/PoolTest.php @@ -72,8 +72,7 @@ public function testGetDashboardGroups(): void public function testGetAdminForClassWithTooManyRegisteredAdmin(): void { - /** @var class-string $class */ - $class = 'someclass'; + $class = \stdClass::class; $pool = new Pool($this->container, ['sonata.user.admin.group1'], [], [ $class => ['sonata.user.admin.group1', 'sonata.user.admin.group2'], @@ -88,8 +87,7 @@ public function testGetAdminForClassWithTooManyRegisteredAdmin(): void public function testGetAdminForClassWithTooManyRegisteredAdminButOneDefaultAdmin(): void { - /** @var class-string $class */ - $class = 'someclass'; + $class = \stdClass::class; $this->container->set('sonata.user.admin.group1', $this->createMock(AdminInterface::class)); @@ -103,8 +101,7 @@ public function testGetAdminForClassWithTooManyRegisteredAdminButOneDefaultAdmin public function testGetAdminForClassWhenAdminClassIsSet(): void { - /** @var class-string $class */ - $class = 'someclass'; + $class = \stdClass::class; $this->container->set('sonata.user.admin.group1', $this->createMock(AdminInterface::class)); @@ -383,8 +380,7 @@ public function getInvalidChildAdminServiceNamesToCheck(): array public function testGetAdminClasses(): void { - /** @var class-string $class */ - $class = 'someclass'; + $class = \stdClass::class; $pool = new Pool($this->container, [], [], [$class => ['sonata.user.admin.group1']]); $this->assertSame([$class => ['sonata.user.admin.group1']], $pool->getAdminClasses()); diff --git a/tests/Block/AdminSearchBlockServiceTest.php b/tests/Block/AdminSearchBlockServiceTest.php index 31db7cde2fc..2b4c80a6b76 100644 --- a/tests/Block/AdminSearchBlockServiceTest.php +++ b/tests/Block/AdminSearchBlockServiceTest.php @@ -84,7 +84,7 @@ public function testGlobalSearchReturnsResponse(): void ->method('getDatagrid') ->willReturn($datagrid); - $filter = $this->createStub(FilterInterface::class); + $filter = $this->createMock(FilterInterface::class); $filter ->method('getOption') ->with('global_search') diff --git a/tests/Form/DataTransformer/ModelToIdPropertyTransformerTest.php b/tests/Form/DataTransformer/ModelToIdPropertyTransformerTest.php index 4779fcfc3d3..bd4459c1adc 100644 --- a/tests/Form/DataTransformer/ModelToIdPropertyTransformerTest.php +++ b/tests/Form/DataTransformer/ModelToIdPropertyTransformerTest.php @@ -15,6 +15,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; use Sonata\AdminBundle\Form\DataTransformer\ModelToIdPropertyTransformer; @@ -24,6 +25,9 @@ class ModelToIdPropertyTransformerTest extends TestCase { + /** + * @var ModelManagerInterface&MockObject + */ private $modelManager; protected function setUp(): void diff --git a/tests/Form/DataTransformer/ModelToIdTransformerTest.php b/tests/Form/DataTransformer/ModelToIdTransformerTest.php index f7f484a504c..0b6bd4dc8ab 100644 --- a/tests/Form/DataTransformer/ModelToIdTransformerTest.php +++ b/tests/Form/DataTransformer/ModelToIdTransformerTest.php @@ -13,12 +13,16 @@ namespace Sonata\AdminBundle\Tests\Form\DataTransformer; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Sonata\AdminBundle\Form\DataTransformer\ModelToIdTransformer; use Sonata\AdminBundle\Model\ModelManagerInterface; class ModelToIdTransformerTest extends TestCase { + /** + * @var ModelManagerInterface&MockObject + */ private $modelManager; protected function setUp(): void @@ -28,8 +32,7 @@ protected function setUp(): void public function testReverseTransformWhenPassing0AsId(): void { - /** @var class-string $className */ - $className = 'TEST'; + $className = \stdClass::class; $transformer = new ModelToIdTransformer($this->modelManager, $className); $this->modelManager @@ -55,11 +58,10 @@ public function testReverseTransformWhenPassing0AsId(): void */ public function testReverseTransform($value, $expected): void { - /** @var class-string $className */ - $className = 'TEST'; + $className = \stdClass::class; $transformer = new ModelToIdTransformer($this->modelManager, $className); - $this->modelManager->method('find'); + $this->modelManager->expects($this->never())->method('find'); $this->assertSame($expected, $transformer->reverseTransform($value)); } @@ -80,8 +82,7 @@ public function testTransform(): void ->method('getNormalizedIdentifier') ->willReturn('123'); - /** @var class-string $className */ - $className = 'TEST'; + $className = \stdClass::class; $transformer = new ModelToIdTransformer($this->modelManager, $className); $this->assertNull($transformer->transform(null)); diff --git a/tests/Form/DataTransformer/ModelsToArrayTransformerTest.php b/tests/Form/DataTransformer/ModelsToArrayTransformerTest.php index eaa7052fbc0..abf3a61fc7b 100644 --- a/tests/Form/DataTransformer/ModelsToArrayTransformerTest.php +++ b/tests/Form/DataTransformer/ModelsToArrayTransformerTest.php @@ -39,7 +39,7 @@ public function testConstructor(): void */ public function testReverseTransform(?array $value): void { - $modelManager = $this->createStub(ModelManagerInterface::class); + $modelManager = $this->createMock(ModelManagerInterface::class); if (null !== $value) { $proxyQuery = $this->createStub(ProxyQueryInterface::class); @@ -77,7 +77,7 @@ public function reverseTransformProvider(): iterable public function testReverseTransformWithEmptyArray(): void { - $modelManager = $this->createStub(ModelManagerInterface::class); + $modelManager = $this->createMock(ModelManagerInterface::class); $modelManager ->expects($this->never()) ->method('createQuery'); @@ -119,7 +119,7 @@ public function testReverseTransformFailed(): void { $value = ['a', 'b']; $reverseTransformCollection = ['a']; - $modelManager = $this->createStub(ModelManagerInterface::class); + $modelManager = $this->createMock(ModelManagerInterface::class); $proxyQuery = $this->createStub(ProxyQueryInterface::class); $modelManager ->method('createQuery') diff --git a/tests/Maker/AdminMakerTest.php b/tests/Maker/AdminMakerTest.php index 3db242c979a..8225df98c37 100644 --- a/tests/Maker/AdminMakerTest.php +++ b/tests/Maker/AdminMakerTest.php @@ -74,7 +74,7 @@ class AdminMakerTest extends TestCase protected function setup(): void { - $managerOrmProxy = $this->createStub(ModelManagerInterface::class); + $managerOrmProxy = $this->createMock(ModelManagerInterface::class); $managerOrmProxy->method('getExportFields')->with(Foo::class) ->willReturn(['bar', 'baz']); diff --git a/tests/Menu/Integration/TabMenuTest.php b/tests/Menu/Integration/TabMenuTest.php index b4e9c1c6a85..f09c2aff76b 100644 --- a/tests/Menu/Integration/TabMenuTest.php +++ b/tests/Menu/Integration/TabMenuTest.php @@ -32,7 +32,7 @@ public function getTranslator(): TranslatorInterface public function testLabelTranslationNominalCase(): void { - $this->translator = $this->createStub(TranslatorInterface::class); + $this->translator = $this->createMock(TranslatorInterface::class); $this->translator->method('trans') ->with( 'some-label', @@ -51,7 +51,7 @@ public function testLabelTranslationNominalCase(): void public function testLabelTranslationWithParameters(): void { $params = ['my' => 'param']; - $this->translator = $this->createStub(TranslatorInterface::class); + $this->translator = $this->createMock(TranslatorInterface::class); $this->translator->method('trans') ->with( 'some-label', diff --git a/tests/Twig/Extension/SecurityExtensionTest.php b/tests/Twig/Extension/SecurityExtensionTest.php index f983aecdbec..2750076af31 100644 --- a/tests/Twig/Extension/SecurityExtensionTest.php +++ b/tests/Twig/Extension/SecurityExtensionTest.php @@ -24,7 +24,7 @@ final class SecurityExtensionTest extends TestCase { public function testIsGrantedAffirmative(): void { - $securityChecker = $this->createStub(AuthorizationCheckerInterface::class); + $securityChecker = $this->createMock(AuthorizationCheckerInterface::class); $twigExtension = new SecurityExtension($securityChecker); $securityChecker diff --git a/tests/Twig/Extension/TemplateRegistryExtensionTest.php b/tests/Twig/Extension/TemplateRegistryExtensionTest.php index aaec00596e5..a1d8b4a8f60 100644 --- a/tests/Twig/Extension/TemplateRegistryExtensionTest.php +++ b/tests/Twig/Extension/TemplateRegistryExtensionTest.php @@ -13,6 +13,7 @@ namespace Sonata\AdminBundle\Tests\Twig\Extension; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Sonata\AdminBundle\Templating\TemplateRegistryInterface; use Sonata\AdminBundle\Twig\Extension\TemplateRegistryExtension; @@ -32,7 +33,7 @@ class TemplateRegistryExtensionTest extends TestCase private $extension; /** - * @var TemplateRegistryInterface + * @var TemplateRegistryInterface&MockObject */ private $templateRegistry; @@ -43,7 +44,7 @@ class TemplateRegistryExtensionTest extends TestCase protected function setUp(): void { - $this->templateRegistry = $this->createStub(TemplateRegistryInterface::class); + $this->templateRegistry = $this->createMock(TemplateRegistryInterface::class); $this->container = new Container(); $this->templateRegistry->method('getTemplate')->with('edit')->willReturn('@SonataAdmin/CRUD/edit.html.twig'); diff --git a/tests/Util/AdminObjectAclManipulatorTest.php b/tests/Util/AdminObjectAclManipulatorTest.php index 2996c6050b8..037c69d4e15 100644 --- a/tests/Util/AdminObjectAclManipulatorTest.php +++ b/tests/Util/AdminObjectAclManipulatorTest.php @@ -116,7 +116,7 @@ public function testCreateAclUsersForm(): void { $form = $this->createStub(Form::class); $formBuilder = $this->createStub(FormBuilder::class); - $securityHandler = $this->createStub(AclSecurityHandlerInterface::class); + $securityHandler = $this->createMock(AclSecurityHandlerInterface::class); $acl = $this->createStub(Acl::class); $securityHandler