From cb578983285234bc3f4784d33020c95f9b87b4d6 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Thu, 1 Apr 2021 23:19:22 +0200 Subject: [PATCH 1/3] Raise phpstan to max level --- phpstan-baseline.neon | 3 ++ phpstan.neon.dist | 2 +- src/Block/AuditBlockService.php | 9 ++++-- src/Builder/DatagridBuilder.php | 6 ++++ src/Builder/ListBuilder.php | 27 ++++++++++------ src/Builder/ShowBuilder.php | 12 +++++-- src/Datagrid/Pager.php | 31 ++++++++----------- src/Datagrid/ProxyQuery.php | 4 +-- .../Compiler/AddAuditEntityCompilerPass.php | 7 ++++- .../Compiler/AddTemplatesCompilerPass.php | 2 ++ .../SonataDoctrineORMAdminExtension.php | 1 + .../FieldDescriptionFactory.php | 2 ++ src/Filter/ChoiceFilter.php | 8 ++--- src/Filter/Filter.php | 2 +- src/Model/ModelManager.php | 16 ++++------ tests/App/DataFixtures/BookFixtures.php | 22 +++++++++---- tests/App/DataFixtures/ItemFixtures.php | 6 ++++ tests/App/Entity/Author.php | 4 +-- tests/Block/AuditBlockServiceTest.php | 2 +- tests/Filter/ClassFilterTest.php | 2 +- tests/Filter/CountFilterTest.php | 2 +- tests/Filter/NumberFilterTest.php | 2 +- tests/Functional/CRUDTest.php | 5 ++- tests/Functional/EmbeddedMappingTest.php | 3 ++ tests/Functional/ManyToOneMappingTest.php | 5 +++ 25 files changed, 121 insertions(+), 64 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 20365cdd2..262923370 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6,3 +6,6 @@ parameters: - # https://github.com/phpstan/phpstan/issues/4650 & https://github.com/phpstan/phpstan-src/pull/476 message: '#^Strict comparison using === between array\(\) and array\&nonEmpty will always evaluate to false.$#' path: src/Model/ModelManager.php + - # https://github.com/doctrine/persistence/pull/163 + message: '#Parameter \#1 \$class of method Sonata\\DoctrineORMAdminBundle\\FieldDescription\\FieldDescriptionFactory\:\:getMetadata\(\) expects class-string, string given.$#' + path: src/FieldDescription/FieldDescriptionFactory.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 16fd2cfdd..9dbb491ab 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,7 +2,7 @@ includes: - phpstan-baseline.neon parameters: - level: 6 + level: max bootstrapFiles: - vendor/bin/.phpunit/phpunit/vendor/autoload.php paths: diff --git a/src/Block/AuditBlockService.php b/src/Block/AuditBlockService.php index 14fb4f8b5..c4367ce30 100644 --- a/src/Block/AuditBlockService.php +++ b/src/Block/AuditBlockService.php @@ -39,16 +39,21 @@ public function __construct(Environment $twig, AuditReader $auditReader) public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response { + $template = $blockContext->getTemplate(); + \assert(null !== $template); + $limit = $blockContext->getSetting('limit'); + \assert(\is_int($limit)); + $revisions = []; - foreach ($this->auditReader->findRevisionHistory($blockContext->getSetting('limit'), 0) as $revision) { + foreach ($this->auditReader->findRevisionHistory($limit, 0) as $revision) { $revisions[] = [ 'revision' => $revision, 'entities' => $this->auditReader->findEntitiesChangedAtRevision($revision->getRev()), ]; } - return $this->renderResponse($blockContext->getTemplate(), [ + return $this->renderResponse($template, [ 'block' => $blockContext->getBlock(), 'settings' => $blockContext->getSettings(), 'revisions' => $revisions, diff --git a/src/Builder/DatagridBuilder.php b/src/Builder/DatagridBuilder.php index 369a66dc3..2f9193828 100644 --- a/src/Builder/DatagridBuilder.php +++ b/src/Builder/DatagridBuilder.php @@ -108,6 +108,12 @@ public function addFilter(DatagridInterface $datagrid, ?string $type, FieldDescr { if (null === $type) { $guessType = $this->guesser->guess($fieldDescription); + if (null === $guessType) { + throw new \InvalidArgumentException(sprintf( + 'Cannot guess a type for the field description "%s", You MUST provide a type.', + $fieldDescription->getName() + )); + } $type = $guessType->getType(); $fieldDescription->setType($type); diff --git a/src/Builder/ListBuilder.php b/src/Builder/ListBuilder.php index cd6df6250..5b840f681 100644 --- a/src/Builder/ListBuilder.php +++ b/src/Builder/ListBuilder.php @@ -50,6 +50,12 @@ public function buildField(?string $type, FieldDescriptionInterface $fieldDescri { if (null === $type) { $guessType = $this->guesser->guess($fieldDescription); + if (null === $guessType) { + throw new \InvalidArgumentException(sprintf( + 'Cannot guess a type for the field description "%s", You MUST provide a type.', + $fieldDescription->getName() + )); + } $fieldDescription->setType($guessType->getType()); } else { @@ -69,7 +75,16 @@ public function addField(FieldDescriptionCollection $list, ?string $type, FieldD public function fixFieldDescription(FieldDescriptionInterface $fieldDescription): void { - if (ListMapper::TYPE_ACTIONS === $fieldDescription->getType()) { + $type = $fieldDescription->getType(); + if (!$type) { + throw new \RuntimeException(sprintf( + 'Please define a type for field `%s` in `%s`', + $fieldDescription->getName(), + \get_class($fieldDescription->getAdmin()) + )); + } + + if (ListMapper::TYPE_ACTIONS === $type) { $this->buildActionFieldDescription($fieldDescription); } @@ -83,16 +98,8 @@ public function fixFieldDescription(FieldDescriptionInterface $fieldDescription) $fieldDescription->setOption('_sort_order', $fieldDescription->getOption('_sort_order', 'ASC')); } - if (!$fieldDescription->getType()) { - throw new \RuntimeException(sprintf( - 'Please define a type for field `%s` in `%s`', - $fieldDescription->getName(), - \get_class($fieldDescription->getAdmin()) - )); - } - if (!$fieldDescription->getTemplate()) { - $fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType())); + $fieldDescription->setTemplate($this->getTemplate($type)); if (!$fieldDescription->getTemplate()) { switch ($fieldDescription->getMappingType()) { diff --git a/src/Builder/ShowBuilder.php b/src/Builder/ShowBuilder.php index 9b90f5515..5969b1d33 100644 --- a/src/Builder/ShowBuilder.php +++ b/src/Builder/ShowBuilder.php @@ -49,6 +49,13 @@ public function addField(FieldDescriptionCollection $list, ?string $type, FieldD { if (null === $type) { $guessType = $this->guesser->guess($fieldDescription); + if (null === $guessType) { + throw new \InvalidArgumentException(sprintf( + 'Cannot guess a type for the field description "%s", You MUST provide a type.', + $fieldDescription->getName() + )); + } + $fieldDescription->setType($guessType->getType()); } else { $fieldDescription->setType($type); @@ -62,7 +69,8 @@ public function addField(FieldDescriptionCollection $list, ?string $type, FieldD public function fixFieldDescription(FieldDescriptionInterface $fieldDescription): void { - if (!$fieldDescription->getType()) { + $type = $fieldDescription->getType(); + if (!$type) { throw new \RuntimeException(sprintf( 'Please define a type for field `%s` in `%s`', $fieldDescription->getName(), @@ -71,7 +79,7 @@ public function fixFieldDescription(FieldDescriptionInterface $fieldDescription) } if (!$fieldDescription->getTemplate()) { - $fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType())); + $fieldDescription->setTemplate($this->getTemplate($type)); } switch ($fieldDescription->getMappingType()) { diff --git a/src/Datagrid/Pager.php b/src/Datagrid/Pager.php index a5102cc82..e0e5e9e2c 100644 --- a/src/Datagrid/Pager.php +++ b/src/Datagrid/Pager.php @@ -47,14 +47,9 @@ public function getCurrentPageResults(): iterable ->getMetadataFor(current($query->getQueryBuilder()->getRootEntities())) ->getIdentifierFieldNames(); - // NEXT_MAJOR: Remove the check and the else part. - if (method_exists($query, 'getDoctrineQuery')) { - // Paginator with fetchJoinCollection doesn't work with composite primary keys - // https://github.com/doctrine/orm/issues/2910 - $paginator = new Paginator($query->getDoctrineQuery(), 1 === \count($identifierFieldNames)); - } else { - $paginator = new Paginator($query->getQueryBuilder(), 1 === \count($identifierFieldNames)); - } + // Paginator with fetchJoinCollection doesn't work with composite primary keys + // https://github.com/doctrine/orm/issues/2910 + $paginator = new Paginator($query->getDoctrineQuery(), 1 === \count($identifierFieldNames)); return $paginator->getIterator(); } @@ -68,8 +63,13 @@ public function init(): void { $this->resultsCount = $this->computeResultsCount(); - $this->getQuery()->setFirstResult(null); - $this->getQuery()->setMaxResults(null); + $query = $this->getQuery(); + if (null === $query) { + throw new \LogicException('The pager need a query to be initialised'); + } + + $query->setFirstResult(null); + $query->setMaxResults(null); if (0 === $this->getPage() || 0 === $this->getMaxPerPage() || 0 === $this->countResults()) { $this->setLastPage(0); @@ -78,8 +78,8 @@ public function init(): void $this->setLastPage((int) ceil($this->countResults() / $this->getMaxPerPage())); - $this->getQuery()->setFirstResult($offset); - $this->getQuery()->setMaxResults($this->getMaxPerPage()); + $query->setFirstResult($offset); + $query->setMaxResults($this->getMaxPerPage()); } } @@ -91,12 +91,7 @@ private function computeResultsCount(): int throw new \TypeError(sprintf('The pager query MUST implement %s.', ProxyQueryInterface::class)); } - // NEXT_MAJOR: Remove the check and the else part. - if (method_exists($query, 'getDoctrineQuery')) { - $paginator = new Paginator($query->getDoctrineQuery()); - } else { - $paginator = new Paginator($query->getQueryBuilder()); - } + $paginator = new Paginator($query->getDoctrineQuery()); return \count($paginator); } diff --git a/src/Datagrid/ProxyQuery.php b/src/Datagrid/ProxyQuery.php index 4fb2227d8..c263e6795 100644 --- a/src/Datagrid/ProxyQuery.php +++ b/src/Datagrid/ProxyQuery.php @@ -163,11 +163,11 @@ public function getDoctrineQuery(): Query $rootAlias = current($queryBuilder->getRootAliases()); - if ($this->getSortBy()) { + $sortBy = $this->getSortBy(); + if (null !== $sortBy) { $orderByDQLPart = $queryBuilder->getDQLPart('orderBy'); $queryBuilder->resetDQLPart('orderBy'); - $sortBy = $this->getSortBy(); if (false === strpos($sortBy, '.')) { $sortBy = $rootAlias.'.'.$sortBy; } diff --git a/src/DependencyInjection/Compiler/AddAuditEntityCompilerPass.php b/src/DependencyInjection/Compiler/AddAuditEntityCompilerPass.php index 41ea17684..803310142 100755 --- a/src/DependencyInjection/Compiler/AddAuditEntityCompilerPass.php +++ b/src/DependencyInjection/Compiler/AddAuditEntityCompilerPass.php @@ -58,7 +58,12 @@ public function process(ContainerBuilder $container): void private function getModelName(ContainerBuilder $container, string $name): string { if ('%' === $name[0]) { - return $container->getParameter(substr($name, 1, -1)); + $parameter = $container->getParameter(substr($name, 1, -1)); + if (!\is_string($parameter)) { + throw new \InvalidArgumentException(sprintf('Cannot find the model name "%s"', $name)); + } + + return $parameter; } return $name; diff --git a/src/DependencyInjection/Compiler/AddTemplatesCompilerPass.php b/src/DependencyInjection/Compiler/AddTemplatesCompilerPass.php index 92aebf08b..d3a4398c2 100644 --- a/src/DependencyInjection/Compiler/AddTemplatesCompilerPass.php +++ b/src/DependencyInjection/Compiler/AddTemplatesCompilerPass.php @@ -25,7 +25,9 @@ final class AddTemplatesCompilerPass implements CompilerPassInterface public function process(ContainerBuilder $container): void { $overwrite = $container->getParameter('sonata.admin.configuration.admin_services'); + \assert(\is_array($overwrite)); $templates = $container->getParameter('sonata_doctrine_orm_admin.templates'); + \assert(\is_array($templates)); foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $attributes) { if (!isset($attributes[0]['manager_type']) || 'orm' !== $attributes[0]['manager_type']) { diff --git a/src/DependencyInjection/SonataDoctrineORMAdminExtension.php b/src/DependencyInjection/SonataDoctrineORMAdminExtension.php index 166c3afe4..686fa97a1 100644 --- a/src/DependencyInjection/SonataDoctrineORMAdminExtension.php +++ b/src/DependencyInjection/SonataDoctrineORMAdminExtension.php @@ -38,6 +38,7 @@ public function load(array $configs, ContainerBuilder $container): void $loader->load('doctrine_orm_filter_types.xml'); $bundles = $container->getParameter('kernel.bundles'); + \assert(\is_array($bundles)); if (isset($bundles['SimpleThingsEntityAuditBundle'])) { $loader->load('audit.xml'); diff --git a/src/FieldDescription/FieldDescriptionFactory.php b/src/FieldDescription/FieldDescriptionFactory.php index 23b913d96..ffec96fb8 100644 --- a/src/FieldDescription/FieldDescriptionFactory.php +++ b/src/FieldDescription/FieldDescriptionFactory.php @@ -54,6 +54,8 @@ public function create(string $class, string $name, array $options = []): FieldD } /** + * @phpstan-param class-string $baseClass + * * @phpstan-return array{ClassMetadata, string, mixed[]} */ private function getParentMetadataForProperty(string $baseClass, string $propertyFullName): array diff --git a/src/Filter/ChoiceFilter.php b/src/Filter/ChoiceFilter.php index 049db2bf2..34e5f6573 100644 --- a/src/Filter/ChoiceFilter.php +++ b/src/Filter/ChoiceFilter.php @@ -54,9 +54,9 @@ public function getRenderSettings(): array /** * @param mixed[] $data * - * @phpstan-param array{type?: string|int|null, value?: mixed} $data + * @phpstan-param array{type: string|int|null, value: mixed} $data */ - private function filterWithMultipleValues(ProxyQueryInterface $query, string $alias, string $field, array $data = []): void + private function filterWithMultipleValues(ProxyQueryInterface $query, string $alias, string $field, array $data): void { if (0 === \count($data['value'])) { return; @@ -88,9 +88,9 @@ private function filterWithMultipleValues(ProxyQueryInterface $query, string $al /** * @param mixed[] $data * - * @phpstan-param array{type?: string|int|null, value?: mixed} $data + * @phpstan-param array{type: string|int|null, value: mixed} $data */ - private function filterWithSingleValue(ProxyQueryInterface $query, string $alias, string $field, array $data = []): void + private function filterWithSingleValue(ProxyQueryInterface $query, string $alias, string $field, array $data): void { if ('' === $data['value'] || false === $data['value']) { return; diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index 721d9050a..c447fe397 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -38,7 +38,7 @@ abstract class Filter extends BaseFilter * * @param mixed[] $data * - * @phpstan-param array{type?: string|int|null, value?: mixed} $data + * @phpstan-param array{type?: int|null, value?: mixed} $data */ abstract public function filter(ProxyQueryInterface $query, string $alias, string $field, array $data): void; diff --git a/src/Model/ModelManager.php b/src/Model/ModelManager.php index c766375fd..402379fb5 100644 --- a/src/Model/ModelManager.php +++ b/src/Model/ModelManager.php @@ -126,7 +126,7 @@ public function getLockVersion(object $object) { $metadata = $this->getMetadata(ClassUtils::getClass($object)); - if (!$metadata->isVersioned) { + if (!$metadata->isVersioned || !isset($metadata->reflFields[$metadata->versionField])) { return null; } @@ -243,17 +243,16 @@ public function getIdentifierValues(object $entity): array } $fieldType = $metadata->getTypeOfField($name); - $type = $fieldType && Type::hasType($fieldType) ? Type::getType($fieldType) : null; - if ($type) { - $identifiers[] = $this->getValueFromType($value, $type, $fieldType, $platform); + if (null !== $fieldType && Type::hasType($fieldType)) { + $identifiers[] = $this->getValueFromType($value, Type::getType($fieldType), $fieldType, $platform); continue; } $identifierMetadata = $this->getMetadata(ClassUtils::getClass($value)); - foreach ($identifierMetadata->getIdentifierValues($value) as $value) { - $identifiers[] = $value; + foreach ($identifierMetadata->getIdentifierValues($value) as $identifierValue) { + $identifiers[] = $identifierValue; } } @@ -396,10 +395,7 @@ private function getFieldName(ClassMetadata $metadata, string $name): string return $name; } - /** - * @param mixed $value - */ - private function getValueFromType($value, Type $type, string $fieldType, AbstractPlatform $platform): string + private function getValueFromType(object $value, Type $type, string $fieldType, AbstractPlatform $platform): string { if ($platform->hasDoctrineTypeMappingFor($fieldType) && 'binary' === $platform->getDoctrineTypeMapping($fieldType) diff --git a/tests/App/DataFixtures/BookFixtures.php b/tests/App/DataFixtures/BookFixtures.php index 2bb9fc9ef..b3f5a647a 100644 --- a/tests/App/DataFixtures/BookFixtures.php +++ b/tests/App/DataFixtures/BookFixtures.php @@ -16,7 +16,9 @@ use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Common\DataFixtures\DependentFixtureInterface; use Doctrine\Persistence\ObjectManager; +use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Author; use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Book; +use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Category; use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Reader; final class BookFixtures extends Fixture implements DependentFixtureInterface @@ -25,18 +27,26 @@ final class BookFixtures extends Fixture implements DependentFixtureInterface public function load(ObjectManager $manager): void { - $book = new Book('book_id', 'Don Quixote', $this->getReference(AuthorFixtures::AUTHOR)); - $book->addCategory($this->getReference(CategoryFixtures::CATEGORY)); + $author = $this->getReference(AuthorFixtures::AUTHOR); + \assert($author instanceof Author); + $category = $this->getReference(CategoryFixtures::CATEGORY); + \assert($category instanceof Category); + + $book = new Book('book_id', 'Don Quixote', $author); + $book->addCategory($category); $manager->persist($book); - $book1 = new Book('book_1', 'Book 1', $this->getReference(AuthorFixtures::AUTHOR_WITH_TWO_BOOKS)); - $book1->addCategory($this->getReference(CategoryFixtures::CATEGORY)); + $authorWithTwoBooks = $this->getReference(AuthorFixtures::AUTHOR_WITH_TWO_BOOKS); + \assert($authorWithTwoBooks instanceof Author); + + $book1 = new Book('book_1', 'Book 1', $authorWithTwoBooks); + $book1->addCategory($category); $this->addReaders($book1, 100); - $book2 = new Book('book_2', 'Book 2', $this->getReference(AuthorFixtures::AUTHOR_WITH_TWO_BOOKS)); - $book2->addCategory($this->getReference(CategoryFixtures::CATEGORY)); + $book2 = new Book('book_2', 'Book 2', $authorWithTwoBooks); + $book2->addCategory($category); $this->addReaders($book2, 100); diff --git a/tests/App/DataFixtures/ItemFixtures.php b/tests/App/DataFixtures/ItemFixtures.php index eea87a5ee..752022d22 100644 --- a/tests/App/DataFixtures/ItemFixtures.php +++ b/tests/App/DataFixtures/ItemFixtures.php @@ -16,16 +16,22 @@ use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Common\DataFixtures\DependentFixtureInterface; use Doctrine\Persistence\ObjectManager; +use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Command; use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Item; +use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Product; final class ItemFixtures extends Fixture implements DependentFixtureInterface { public function load(ObjectManager $manager): void { $command1 = $this->getReference(CommandFixtures::COMMAND_1); + \assert($command1 instanceof Command); $command2 = $this->getReference(CommandFixtures::COMMAND_2); + \assert($command2 instanceof Command); $product1 = $this->getReference(ProductFixtures::PRODUCT_1); + \assert($product1 instanceof Product); $product2 = $this->getReference(ProductFixtures::PRODUCT_2); + \assert($product2 instanceof Product); $item1 = new Item($command1, $product1); $item2 = new Item($command1, $product2); diff --git a/tests/App/Entity/Author.php b/tests/App/Entity/Author.php index 4ad437423..f7e9f9acf 100644 --- a/tests/App/Entity/Author.php +++ b/tests/App/Entity/Author.php @@ -83,12 +83,12 @@ public function setName(string $name): void $this->name = $name; } - public function getAddress(): ?Address + public function getAddress(): Address { return $this->address; } - public function setAddress(?Address $address): void + public function setAddress(Address $address): void { $this->address = $address; } diff --git a/tests/Block/AuditBlockServiceTest.php b/tests/Block/AuditBlockServiceTest.php index 0e97958f9..fa032561b 100644 --- a/tests/Block/AuditBlockServiceTest.php +++ b/tests/Block/AuditBlockServiceTest.php @@ -58,7 +58,7 @@ public function testExecute(): void ->expects($this->once()) ->method('findRevisionHistory') ->with($limit, 0) - ->willReturn([$revision = new Revision('test', '123', 'test')]); + ->willReturn([$revision = new Revision('test', new \DateTime(), 'test')]); $this->simpleThingsAuditReader ->expects($this->once()) diff --git a/tests/Filter/ClassFilterTest.php b/tests/Filter/ClassFilterTest.php index d97934644..96b93be50 100644 --- a/tests/Filter/ClassFilterTest.php +++ b/tests/Filter/ClassFilterTest.php @@ -49,7 +49,7 @@ public function testFilterInvalidOperator(): void $proxyQuery = new ProxyQuery($this->createQueryBuilderStub()); - $filter->filter($proxyQuery, 'alias', 'field', ['type' => 'foo']); + $filter->filter($proxyQuery, 'alias', 'field', ['type' => 42]); $this->assertSameQuery([], $proxyQuery); $this->assertFalse($filter->isActive()); diff --git a/tests/Filter/CountFilterTest.php b/tests/Filter/CountFilterTest.php index dba18f55d..1d5ced91d 100644 --- a/tests/Filter/CountFilterTest.php +++ b/tests/Filter/CountFilterTest.php @@ -39,7 +39,7 @@ public function testFilterInvalidOperator(): void $proxyQuery = new ProxyQuery($this->createQueryBuilderStub()); - $filter->filter($proxyQuery, 'alias', 'field', ['type' => 'foo']); + $filter->filter($proxyQuery, 'alias', 'field', ['type' => 42]); $this->assertSameQuery([], $proxyQuery); $this->assertFalse($filter->isActive()); diff --git a/tests/Filter/NumberFilterTest.php b/tests/Filter/NumberFilterTest.php index f14173d56..3681ffa26 100644 --- a/tests/Filter/NumberFilterTest.php +++ b/tests/Filter/NumberFilterTest.php @@ -39,7 +39,7 @@ public function testFilterInvalidOperator(): void $proxyQuery = new ProxyQuery($this->createQueryBuilderStub()); - $filter->filter($proxyQuery, 'alias', 'field', ['type' => 'foo']); + $filter->filter($proxyQuery, 'alias', 'field', ['type' => 42]); $this->assertSameQuery([], $proxyQuery); $this->assertFalse($filter->isActive()); diff --git a/tests/Functional/CRUDTest.php b/tests/Functional/CRUDTest.php index e0c7690af..15c1d7ff2 100644 --- a/tests/Functional/CRUDTest.php +++ b/tests/Functional/CRUDTest.php @@ -13,6 +13,7 @@ namespace Sonata\DoctrineORMAdminBundle\Tests\Functional; +use Doctrine\Bundle\DoctrineBundle\Registry; use Sonata\DoctrineORMAdminBundle\Tests\App\Entity\Category; use Symfony\Component\HttpFoundation\Request; @@ -65,7 +66,9 @@ public function testEdit(): void public function testDelete(): void { - $entityManager = static::bootKernel()->getContainer()->get('doctrine')->getManager(); + $doctrine = static::bootKernel()->getContainer()->get('doctrine'); + \assert($doctrine instanceof Registry); + $entityManager = $doctrine->getManager(); $entityManager->persist(new Category('category_to_remove', 'name')); $entityManager->flush(); diff --git a/tests/Functional/EmbeddedMappingTest.php b/tests/Functional/EmbeddedMappingTest.php index 103bca960..3d4baffd2 100644 --- a/tests/Functional/EmbeddedMappingTest.php +++ b/tests/Functional/EmbeddedMappingTest.php @@ -36,8 +36,11 @@ public function testCreateEntityWithEmbedded(): void $crawler = $this->client->request(Request::METHOD_GET, '/admin/tests/app/author/create'); $attributeId = $crawler->filter('.author_id')->attr('name'); + $this->assertNotNull($attributeId); $attributeName = $crawler->filter('.author_name')->attr('name'); + $this->assertNotNull($attributeName); $attributeAddressStreet = $crawler->filter('.author_address')->attr('name'); + $this->assertNotNull($attributeAddressStreet); $form = $crawler->selectButton('Create and return to list')->form(); $form[$attributeId] = 'new_id'; diff --git a/tests/Functional/ManyToOneMappingTest.php b/tests/Functional/ManyToOneMappingTest.php index e1d44d08c..385b3b02d 100644 --- a/tests/Functional/ManyToOneMappingTest.php +++ b/tests/Functional/ManyToOneMappingTest.php @@ -24,7 +24,9 @@ public function testCreateEntityWithReferences(): void $crawler = $this->client->request(Request::METHOD_GET, '/admin/tests/app/book/create'); $attributeId = $crawler->filter('.book_id')->attr('name'); + $this->assertNotNull($attributeId); $attributeName = $crawler->filter('.book_name')->attr('name'); + $this->assertNotNull($attributeName); $form = $crawler->selectButton('Create and return to list')->form(); $form[$attributeId] = 'book_new_id'; @@ -49,8 +51,11 @@ public function testCreateEntityWithReferences(): void private function createAuthorForm(Crawler $crawler): Form { $authorAttributeId = $crawler->filter('.author_id')->attr('name'); + $this->assertNotNull($authorAttributeId); $authorAttributeName = $crawler->filter('.author_name')->attr('name'); + $this->assertNotNull($authorAttributeName); $addressAttributeName = $crawler->filter('.author_address')->attr('name'); + $this->assertNotNull($addressAttributeName); $authorForm = $crawler->filter('.modal-content button[name="btn_create"]')->form(); $authorForm[$authorAttributeId] = 'Wonderful Id'; From 0ef688baa1cf0dd04d95f06063c87354ab9ce5f2 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Fri, 9 Apr 2021 15:40:26 +0200 Subject: [PATCH 2/3] Bump doctrine --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 844332e9a..c28f7f953 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ ], "require": { "php": "^7.3 || ^8.0", - "doctrine/doctrine-bundle": "^1.8 || ^2.0", + "doctrine/doctrine-bundle": "^1.8 || ^2.3", "doctrine/orm": "^2.5", "doctrine/persistence": "^1.3.4 || ^2.0", "sonata-project/admin-bundle": "4.x-dev", From 5ed40e641a9c5fd5f7f9a09f33be70a81ced7a73 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 10 Apr 2021 11:51:39 +0200 Subject: [PATCH 3/3] Update type phpdoc --- src/Filter/ChoiceFilter.php | 4 ++-- src/Filter/Filter.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Filter/ChoiceFilter.php b/src/Filter/ChoiceFilter.php index 34e5f6573..244b45227 100644 --- a/src/Filter/ChoiceFilter.php +++ b/src/Filter/ChoiceFilter.php @@ -54,7 +54,7 @@ public function getRenderSettings(): array /** * @param mixed[] $data * - * @phpstan-param array{type: string|int|null, value: mixed} $data + * @phpstan-param array{type: int|null, value: mixed} $data */ private function filterWithMultipleValues(ProxyQueryInterface $query, string $alias, string $field, array $data): void { @@ -88,7 +88,7 @@ private function filterWithMultipleValues(ProxyQueryInterface $query, string $al /** * @param mixed[] $data * - * @phpstan-param array{type: string|int|null, value: mixed} $data + * @phpstan-param array{type: int|null, value: mixed} $data */ private function filterWithSingleValue(ProxyQueryInterface $query, string $alias, string $field, array $data): void { diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index c447fe397..cdbc0209c 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -65,7 +65,7 @@ public function isActive(): bool * * @return string[] * - * @phpstan-param array{type?: string|int|null, value?: mixed} $data + * @phpstan-param array{type?: int|null, value?: mixed} $data */ protected function association(ProxyQueryInterface $query, array $data): array {