Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Jul 15, 2024
1 parent 91bf665 commit eb7fbb1
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 33 deletions.
3 changes: 0 additions & 3 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ parameters:
- # https://github.com/phpstan/phpstan-strict-rules/issues/130
message: '#^Call to static method PHPUnit\\Framework\\Assert::.* will always evaluate to true\.$#'
path: tests/
- # https://github.com/doctrine/orm/pull/9778
message: '#Parameter \#1 \$className of method Doctrine\\Persistence\\Mapping\\AbstractClassMetadataFactory<Doctrine\\ORM\\Mapping\\ClassMetadata>::getMetadataFor\(\) expects class-string, string given.#'
path: src/Datagrid/ProxyQuery.php
16 changes: 0 additions & 16 deletions psalm-baseline.xml

This file was deleted.

2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="2" findUnusedPsalmSuppress="true" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" errorBaseline="psalm-baseline.xml" findUnusedBaselineEntry="true" findUnusedCode="false">
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="2" findUnusedPsalmSuppress="true" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" findUnusedBaselineEntry="true" findUnusedCode="false">
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
Expand Down
6 changes: 5 additions & 1 deletion src/Datagrid/ProxyQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface as BaseProxyQueryInterface;
Expand Down Expand Up @@ -245,6 +246,9 @@ public function setFirstResult(?int $firstResult): BaseProxyQueryInterface
return $this;
}

/**
* @phpstan-ignore-next-line for ORM 2 compatibility
*/
public function getFirstResult(): ?int
{
return $this->queryBuilder->getFirstResult();
Expand Down Expand Up @@ -277,7 +281,7 @@ public function entityJoin(array $associationMappings): string

$newAlias = 's';

/** @var Query\Expr\Join[][] $joinedEntities */
/** @var Join[][] $joinedEntities */
$joinedEntities = $this->queryBuilder->getDQLPart('join');

foreach ($associationMappings as $associationMapping) {
Expand Down
6 changes: 0 additions & 6 deletions src/FieldDescription/FieldDescriptionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ private function getEntityManager(string $class): EntityManagerInterface
}

/**
* @psalm-suppress UndefinedClass
* @phpstan-ignore-next-line
*/
private function mappingToArray(array|FieldMapping|AssociationMapping $mapping): array
Expand All @@ -111,12 +110,7 @@ private function mappingToArray(array|FieldMapping|AssociationMapping $mapping):
return $mapping;
}

/**
* @psalm-suppress UndefinedClass
* @phpstan-ignore-next-line
*/
if ($mapping instanceof AssociationMapping) {
/* @phpstan-ignore-next-line */
return $mapping->toArray();
}

Expand Down
10 changes: 7 additions & 3 deletions tests/Filter/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testOrExpression(string $expected, array $filterOptionsCollectio
$entityManager->method('getExpressionBuilder')->willReturn(new Expr());
$queryBuilder = new TestQueryBuilder($entityManager);

$queryBuilder->select('e')->from('MyEntity', 'e');
$queryBuilder->select('e')->from(MyEntity::class, 'e');

// Some custom conditions set previous to the filters.
$queryBuilder
Expand All @@ -46,7 +46,7 @@ public function testOrExpression(string $expected, array $filterOptionsCollectio
)
->setParameter('parameter_1', 3);

static::assertSame('SELECT e FROM MyEntity e WHERE 1 = 2 AND (:parameter_1 = 4 OR 5 = 6)', $queryBuilder->getDQL());
static::assertSame('SELECT e FROM Sonata\DoctrineORMAdminBundle\Tests\Filter\MyEntity e WHERE 1 = 2 AND (:parameter_1 = 4 OR 5 = 6)', $queryBuilder->getDQL());

$proxyQuery = new ProxyQuery($queryBuilder);

Expand All @@ -73,7 +73,7 @@ public function testOrExpression(string $expected, array $filterOptionsCollectio
public function provideOrExpressionCases(): iterable
{
yield 'Default behavior' => [
'SELECT e FROM MyEntity e WHERE 1 = 2 AND (:parameter_1 = 4 OR 5 = 6)'
'SELECT e FROM Sonata\DoctrineORMAdminBundle\Tests\Filter\MyEntity e WHERE 1 = 2 AND (:parameter_1 = 4 OR 5 = 6)'
.' AND e.project LIKE :project_0 AND e.version LIKE :version_1 AND 7 = 8',
[
[
Expand Down Expand Up @@ -102,3 +102,7 @@ public function provideOrExpressionCases(): iterable
];
}
}

class MyEntity
{
}
4 changes: 4 additions & 0 deletions tests/Fixtures/Query/FooWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@

namespace Sonata\DoctrineORMAdminBundle\Tests\Fixtures\Query;

use Doctrine\ORM\Query\AST\OrderByClause;
use Doctrine\ORM\Query\SqlWalker;

final class FooWalker extends SqlWalker
{
/**
* @param OrderByClause $orderByClause
*/
public function walkOrderByClause($orderByClause): string
{
return str_replace(' ASC', ' DESC', parent::walkOrderByClause($orderByClause));
Expand Down
10 changes: 7 additions & 3 deletions tests/Fixtures/TestEntityManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@

use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMSetup;
use PHPUnit\Framework\TestCase;

final class TestEntityManagerFactory
{
/**
* @psalm-suppress DeprecatedMethod
*/
public static function create(): EntityManagerInterface
{
if (!\extension_loaded('pdo_sqlite')) {
Expand All @@ -34,6 +32,12 @@ public static function create(): EntityManagerInterface
if (version_compare(\PHP_VERSION, '8.0.0', '>=')) {
$config = ORMSetup::createAttributeMetadataConfiguration([], true);
} else {
/**
* @var Configuration $config
*
* @psalm-suppress UndefinedMethod
* @phpstan-ignore-next-line
*/
$config = ORMSetup::createAnnotationMetadataConfiguration([], true);
}

Expand Down

0 comments on commit eb7fbb1

Please sign in to comment.