Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevKit updates for 4.x branch #1813

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 0 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

use Rector\Config\RectorConfig;
use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
Expand All @@ -40,7 +39,6 @@
$rectorConfig->importShortClasses(false);
$rectorConfig->skip([
ExceptionHandlerTypehintRector::class,
AddSeeTestAnnotationRector::class,
PreferPHPUnitThisCallRector::class,
]);
};
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
Loading