Skip to content

Commit

Permalink
Merge branch '3.2.x' into 4.0.x
Browse files Browse the repository at this point in the history
* 3.2.x:
  Using an integer as discriminator value with ORM v3
  Using an integer as discriminator value with ORM v3
  Bump ramsey/composer-install from 2 to 3 (doctrine#11442)
  Use ramsey/composer-install in PHPBench workflow (doctrine#11444)
  Bump doctrine/.github from 3.0.0 to 5.0.1
  Upgrade codecov/codecov-action
  Setup Dependabot
  Make test compatible with PHP 7.1
  Fix deprecation layer
  Remove unused test group
  Keep entities in identity map until the scheduled deletions are executed.
  Update association-mapping.rst
  fix: always cleanup in `AbstractHydrator::toIterable()` (doctrine#11101)
  Respect orderBy for EAGER fetch mode
  fix(docs): typo
  • Loading branch information
derrabus committed May 21, 2024
2 parents 9674168 + a14ef7c commit 3695d57
Show file tree
Hide file tree
Showing 18 changed files with 444 additions and 48 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "CI"
target-branch: "2.19.x"
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ on:

jobs:
coding-standards:
uses: "doctrine/.github/.github/workflows/coding-standards.yml@3.0.0"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@5.0.1"
12 changes: 7 additions & 5 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
if: "${{ matrix.dbal-version != 'default' }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
composer-options: "--ignore-platform-req=php+"
dependency-versions: "${{ matrix.deps }}"
Expand Down Expand Up @@ -156,7 +156,7 @@ jobs:
if: "${{ matrix.dbal-version != 'default' }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
composer-options: "--ignore-platform-req=php+"

Expand Down Expand Up @@ -222,7 +222,7 @@ jobs:
extensions: "${{ matrix.extension }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
composer-options: "--ignore-platform-req=php+"

Expand Down Expand Up @@ -296,7 +296,7 @@ jobs:
if: "${{ matrix.dbal-version != 'default' }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
composer-options: "--ignore-platform-req=php+"

Expand Down Expand Up @@ -337,6 +337,8 @@ jobs:
path: "reports"

- name: "Upload to Codecov"
uses: "codecov/codecov-action@v3"
uses: "codecov/codecov-action@v4"
with:
directory: reports
env:
CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}"
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: "composer require --dev phpdocumentor/guides-cli --no-update"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "highest"

Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/phpbench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,8 @@ jobs:
coverage: "pcov"
ini-values: "zend.assertions=1, apc.enable_cli=1"

- name: "Cache dependencies installed with composer"
uses: "actions/cache@v3"
with:
path: "~/.composer/cache"
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"

- name: "Install dependencies with composer"
run: "composer update --no-interaction --no-progress"
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v3"

- name: "Run PHPBench"
run: "vendor/bin/phpbench run --report=default"
2 changes: 1 addition & 1 deletion .github/workflows/release-on-milestone-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
release:
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@4.0.0"
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@5.0.1"
secrets:
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
if: "${{ matrix.dbal-version != 'default' }}"

- name: Install dependencies with Composer
uses: ramsey/composer-install@v2
uses: ramsey/composer-install@v3

- name: Run static analysis with Vimeo Psalm
run: vendor/bin/psalm --shepherd
2 changes: 1 addition & 1 deletion docs/en/cookbook/validation-of-entities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ What we offer are hooks to execute any kind of validation.
.. note::

You don't need to validate your entities in the lifecycle
events. Its only one of many options. Of course you can also
events. It is only one of many options. Of course you can also
perform validations in value setters or any other method of your
entities that are used in your code.

Expand Down
8 changes: 4 additions & 4 deletions docs/en/reference/association-mapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,8 @@ This is essentially the same as the following, more verbose, mapping:
* @var Collection<int, Group>
*/
#[JoinTable(name: 'User_Group')]
#[JoinColumn(name: 'User_id', referencedColumnName: 'id')]
#[InverseJoinColumn(name: 'Group_id', referencedColumnName: 'id')]
#[JoinColumn(name: 'user_id', referencedColumnName: 'id')]
#[InverseJoinColumn(name: 'group_id', referencedColumnName: 'id')]
#[ManyToMany(targetEntity: Group::class)]
private Collection $groups;
// ...
Expand All @@ -884,10 +884,10 @@ This is essentially the same as the following, more verbose, mapping:
<many-to-many field="groups" target-entity="Group">
<join-table name="User_Group">
<join-columns>
<join-column id="User_id" referenced-column-name="id" />
<join-column id="user_id" referenced-column-name="id" />
</join-columns>
<inverse-join-columns>
<join-column id="Group_id" referenced-column-name="id" />
<join-column id="group_id" referenced-column-name="id" />
</inverse-join-columns>
</join-table>
</many-to-many>
Expand Down
34 changes: 18 additions & 16 deletions src/Internal/Hydration/AbstractHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,31 @@ final public function toIterable(Result $stmt, ResultSetMapping $resultSetMappin

$this->prepare();

while (true) {
$row = $this->statement()->fetchAssociative();

if ($row === false) {
$this->cleanup();
try {
while (true) {
$row = $this->statement()->fetchAssociative();

break;
}
if ($row === false) {
break;
}

$result = [];
$result = [];

$this->hydrateRowData($row, $result);
$this->hydrateRowData($row, $result);

$this->cleanupAfterRowIteration();
if (count($result) === 1) {
if (count($resultSetMapping->indexByMap) === 0) {
yield end($result);
$this->cleanupAfterRowIteration();
if (count($result) === 1) {
if (count($resultSetMapping->indexByMap) === 0) {
yield end($result);
} else {
yield from $result;
}
} else {
yield from $result;
yield $result;
}
} else {
yield $result;
}
} finally {
$this->cleanup();
}
}

Expand Down
15 changes: 11 additions & 4 deletions src/Query/SqlWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use function implode;
use function is_array;
use function is_float;
use function is_int;
use function is_numeric;
use function is_string;
use function preg_match;
Expand Down Expand Up @@ -384,7 +385,9 @@ private function generateDiscriminatorColumnConditionSQL(array $dqlAliases): str
$values = [];

if ($class->discriminatorValue !== null) { // discriminators can be 0
$values[] = $conn->quote($class->discriminatorValue);
$values[] = $class->getDiscriminatorColumn()->type === 'integer' && is_int($class->discriminatorValue)
? $class->discriminatorValue
: $conn->quote((string) $class->discriminatorValue);
}

foreach ($class->subClasses as $subclassName) {
Expand All @@ -396,7 +399,9 @@ private function generateDiscriminatorColumnConditionSQL(array $dqlAliases): str
continue;
}

$values[] = $conn->quote((string) $subclassMetadata->discriminatorValue);
$values[] = $subclassMetadata->getDiscriminatorColumn()->type === 'integer' && is_int($subclassMetadata->discriminatorValue)
? $subclassMetadata->discriminatorValue
: $conn->quote((string) $subclassMetadata->discriminatorValue);
}

if ($values !== []) {
Expand Down Expand Up @@ -2246,8 +2251,10 @@ private function getChildDiscriminatorsFromClassMetadata(
$discriminators += HierarchyDiscriminatorResolver::resolveDiscriminatorsForClass($metadata, $this->em);
}

foreach (array_keys($discriminators) as $dis) {
$sqlParameterList[] = $this->conn->quote($dis);
foreach (array_keys($discriminators) as $discriminatorValue) {
$sqlParameterList[] = $rootClass->getDiscriminatorColumn()->type === 'integer' && is_int($discriminatorValue)
? $discriminatorValue
: $this->conn->quote((string) $discriminatorValue);
}

return '(' . implode(', ', $sqlParameterList) . ')';
Expand Down
6 changes: 3 additions & 3 deletions src/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,8 @@ private function executeDeletions(): void
$eventsToDispatch = [];

foreach ($entities as $entity) {
$this->removeFromIdentityMap($entity);

$oid = spl_object_id($entity);
$class = $this->em->getClassMetadata($entity::class);
$persister = $this->getEntityPersister($class->name);
Expand Down Expand Up @@ -1484,8 +1486,6 @@ public function scheduleForDelete(object $entity): void
return;
}

$this->removeFromIdentityMap($entity);

unset($this->entityUpdates[$oid]);

if (! isset($this->entityDeletions[$oid])) {
Expand Down Expand Up @@ -2653,7 +2653,7 @@ private function eagerLoadCollections(array $collections, ToManyInverseSideMappi
$entities[] = $collection->getOwner();
}

$found = $this->getEntityPersister($targetEntity)->loadAll([$mappedBy => $entities]);
$found = $this->getEntityPersister($targetEntity)->loadAll([$mappedBy => $entities], $mapping['orderBy'] ?? null);

$targetClass = $this->em->getClassMetadata($targetEntity);
$targetProperty = $targetClass->getReflectionProperty($mappedBy);
Expand Down
1 change: 0 additions & 1 deletion tests/Tests/ORM/Functional/QueryDqlFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ public function testOperatorMultiply(): void
self::assertEquals(1_600_000, $result[3]['op']);
}

#[Group('test')]
public function testOperatorDiv(): void
{
$result = $this->_em->createQuery('SELECT m, (m.salary/0.5) AS op FROM Doctrine\Tests\Models\Company\CompanyManager m ORDER BY m.salary ASC')
Expand Down
112 changes: 112 additions & 0 deletions tests/Tests/ORM/Functional/Ticket/GH11163Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection;
use Doctrine\Tests\OrmFunctionalTestCase;

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

$this->setUpEntitySchema([
GH11163Bucket::class,
GH11163BucketItem::class,
]);
}

public function tearDown(): void
{
parent::tearDown();

$conn = static::$sharedConn;
$conn->executeStatement('DELETE FROM GH11163BucketItem');
$conn->executeStatement('DELETE FROM GH11163Bucket');
}

public function testFetchEagerModeWithOrderBy(): void
{
// Load entities into database
$this->_em->persist($bucket = new GH11163Bucket(11163));
$this->_em->persist(new GH11163BucketItem(1, $bucket, 2));
$this->_em->persist(new GH11163BucketItem(2, $bucket, 3));
$this->_em->persist(new GH11163BucketItem(3, $bucket, 1));
$this->_em->flush();
$this->_em->clear();

// Fetch entity from database
$dql = 'SELECT bucket FROM ' . GH11163Bucket::class . ' bucket WHERE bucket.id = :id';
$bucket = $this->_em->createQuery($dql)
->setParameter('id', 11163)
->getSingleResult();

// Assert associated entity is loaded eagerly
static::assertInstanceOf(GH11163Bucket::class, $bucket);
static::assertInstanceOf(PersistentCollection::class, $bucket->items);
static::assertTrue($bucket->items->isInitialized());

static::assertCount(3, $bucket->items);

// Assert order of entities
static::assertSame(1, $bucket->items[0]->position);
static::assertSame(3, $bucket->items[0]->id);

static::assertSame(2, $bucket->items[1]->position);
static::assertSame(1, $bucket->items[1]->id);

static::assertSame(3, $bucket->items[2]->position);
static::assertSame(2, $bucket->items[2]->id);
}
}

#[ORM\Entity]
class GH11163Bucket
{
#[ORM\Id]
#[ORM\Column(type: 'integer')]
private int $id;

/** @var Collection<int, GH11163BucketItem> */
#[ORM\OneToMany(
targetEntity: GH11163BucketItem::class,
mappedBy: 'bucket',
fetch: 'EAGER',
)]
#[ORM\OrderBy(['position' => 'ASC'])]
public Collection $items;

public function __construct(int $id)
{
$this->id = $id;
$this->items = new ArrayCollection();
}
}

#[ORM\Entity]
class GH11163BucketItem
{
#[ORM\ManyToOne(targetEntity: GH11163Bucket::class, inversedBy: 'items')]
#[ORM\JoinColumn(nullable: false)]
private GH11163Bucket $bucket;

#[ORM\Id]
#[ORM\Column(type: 'integer')]
public int $id;

#[ORM\Column(type: 'integer')]
public int $position;

public function __construct(int $id, GH11163Bucket $bucket, int $position)
{
$this->id = $id;
$this->bucket = $bucket;
$this->position = $position;
}
}
Loading

0 comments on commit 3695d57

Please sign in to comment.