Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"doctrine/coding-standard": "^9.0.2 || ^14.0",
"phpbench/phpbench": "^0.16.10 || ^1.0",
"phpstan/extension-installer": "~1.1.0 || ^1.4",
"phpstan/phpstan": "~1.4.10 || 2.1.22",
"phpstan/phpstan": "~1.4.10 || 2.1.23",
"phpstan/phpstan-deprecation-rules": "^1 || ^2",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.6",
"psr/log": "^1 || ^2 || ^3",
Expand Down
32 changes: 7 additions & 25 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,12 @@ parameters:
count: 1
path: src/Internal/HydrationCompleteHandler.php

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's that coming from? Maybe you need to rebase to make it go away?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's come from the update of phpstan to 2.1.23

-
message: '#^Offset int\|null might not exist on array\<int, object\>\.$#'
identifier: offsetAccess.notFound
count: 1
path: src/Internal/StronglyConnectedComponents.php

-
message: '#^Property Doctrine\\ORM\\Internal\\StronglyConnectedComponents\:\:\$representingNodes \(array\<int, object\>\) does not accept array\<int\|string, object\>\.$#'
identifier: assign.propertyType
Expand Down Expand Up @@ -3594,7 +3600,7 @@ parameters:
-
message: '#^Property Doctrine\\ORM\\Query\\Filter\\SQLFilter\:\:\$parameters \(array\<string, array\{type\: string, value\: mixed, is_list\: bool\}\>\) does not accept non\-empty\-array\<string, array\{value\: mixed, type\: int\|string, is_list\: bool\}\>\.$#'
identifier: assign.propertyType
count: 1
count: 2
path: src/Query/Filter/SQLFilter.php

-
Expand Down Expand Up @@ -4173,12 +4179,6 @@ parameters:
count: 1
path: src/Tools/Console/Command/ConvertMappingCommand.php

-
message: '#^Parameter \#2 \$destPath of method Doctrine\\ORM\\Tools\\Console\\Command\\ConvertMappingCommand\:\:getExporter\(\) expects string, string\|false given\.$#'
identifier: argument.type
count: 1
path: src/Tools/Console/Command/ConvertMappingCommand.php

-
message: '#^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$name\.$#'
identifier: property.notFound
Expand All @@ -4203,12 +4203,6 @@ parameters:
count: 1
path: src/Tools/Console/Command/GenerateEntitiesCommand.php

-
message: '#^Parameter \#2 \$outputDirectory of method Doctrine\\ORM\\Tools\\EntityGenerator\:\:generate\(\) expects string, string\|false given\.$#'
identifier: argument.type
count: 1
path: src/Tools/Console/Command/GenerateEntitiesCommand.php

-
message: '#^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$name\.$#'
identifier: property.notFound
Expand All @@ -4227,12 +4221,6 @@ parameters:
count: 1
path: src/Tools/Console/Command/GenerateProxiesCommand.php

-
message: '#^Parameter \#2 \$proxyDir of method Doctrine\\ORM\\Proxy\\ProxyFactory\:\:generateProxyClasses\(\) expects string\|null, string\|false given\.$#'
identifier: argument.type
count: 1
path: src/Tools/Console/Command/GenerateProxiesCommand.php

-
message: '#^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$customRepositoryClassName\.$#'
identifier: property.notFound
Expand All @@ -4251,12 +4239,6 @@ parameters:
count: 1
path: src/Tools/Console/Command/GenerateRepositoriesCommand.php

-
message: '#^Parameter \#2 \$outputDirectory of method Doctrine\\ORM\\Tools\\EntityRepositoryGenerator\:\:writeEntityRepositoryClass\(\) expects string, string\|false given\.$#'
identifier: argument.type
count: 1
path: src/Tools/Console/Command/GenerateRepositoriesCommand.php

-
message: '#^Method Doctrine\\ORM\\Tools\\Console\\Command\\MappingDescribeCommand\:\:formatMappings\(\) has parameter \$propertyMappings with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand Down
5 changes: 5 additions & 0 deletions src/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,11 @@ public function getSelectConditionStatementSQL($field, $value, $assoc = null, $c
$value = [$value];
}

if ($value === []) {
$selectedColumns[] = $column . ' IN (NULL)';
continue;
}

$nullKeys = array_keys($value, null, true);
$nonNullValues = array_diff_key($value, array_flip($nullKeys));

Expand Down
62 changes: 62 additions & 0 deletions tests/Tests/ORM/Functional/Ticket/GH12254Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\Tests\OrmFunctionalTestCase;

class GH12254Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->setUpEntitySchema([
GH12254EntityA::class,
]);

$this->_em->persist(new GH12254EntityA());
$this->_em->flush();
$this->_em->clear();
}

public function testFindByEmptyArrayShouldReturnEmptyArray(): void
{
// pretend we are starting afresh
$this->_em = $this->getEntityManager();
$result = $this->_em->getRepository(GH12254EntityA::class)->findBy(['id' => []]);
$this->assertEmpty($result);
}

public function testFindByInNullableField(): void
{
$this->_em = $this->getEntityManager();
$result = $this->_em->getRepository(GH12254EntityA::class)->findBy(['name' => []]);
$this->assertEmpty($result);
}
}

/**
* @Entity()
*/
class GH12254EntityA
{
/**
* @Column(type="integer")
* @Id()
* @GeneratedValue(strategy="AUTO")
* @var int
*/
public $id;

/**
* @Column(type="string", nullable=true)
* @var string|null
*/
public $name = null;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should probably be a functional test for this. That way we'll be sure it works with all database platforms.

Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ public function testSelectConditionStatementWithMultipleValuesContainingNull():
);
}

/** @group GH12254 */
public function testSelectConditionStatementWithValuesIsEmptyArray(): void
{
self::assertEquals(
't0.id IN (NULL)',
$this->persister->getSelectConditionStatementSQL('id', [])
);
}

public function testCountCondition(): void
{
$persister = new BasicEntityPersister($this->entityManager, $this->entityManager->getClassMetadata(NonAlphaColumnsEntity::class));
Expand Down