Skip to content

Commit

Permalink
Merge branch '2.13.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.13.x:
  Deprecate omitting the alias in QueryBuilder (doctrine#9765)
  Run tests on PHP 8.2 (doctrine#9840)
  PHPStan 1.7.13 (doctrine#9844)
  Flip conditional extension of legacy AnnotationDriver class (doctrine#9843)
  PHP CodeSniffer 3.7 (doctrine#9842)
  Make Reflection available to ConvertMappingCommand (doctrine#9619)
  Add missing property declaration
  Use proper API for introspection of tables
  • Loading branch information
derrabus committed Jun 17, 2022
2 parents af1303e + b931a59 commit 318e6ec
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 38 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
include:
- php-version: "8.1"
dbal-version: "3@dev"
- php-version: "8.2"
dbal-version: "3@dev"
- php-version: "8.1"
dbal-version: "4@dev"

Expand All @@ -49,6 +51,8 @@ jobs:

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

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --coverage-clover=coverage-no-cache.xml"
Expand Down Expand Up @@ -85,6 +89,9 @@ jobs:
- php-version: "8.1"
dbal-version: "4@dev"
postgres-version: "14"
- php-version: "8.2"
dbal-version: "3@dev"
postgres-version: "14"

services:
postgres:
Expand Down Expand Up @@ -117,6 +124,8 @@ jobs:

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

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/pdo_pgsql.xml --coverage-clover=coverage.xml"
Expand Down Expand Up @@ -145,6 +154,15 @@ jobs:
extension:
- "mysqli"
- "pdo_mysql"
include:
- php-version: "8.2"
dbal-version: "3@dev"
mariadb-version: "10.6"
extension: "pdo_mysql"
- php-version: "8.2"
dbal-version: "3@dev"
mariadb-version: "10.6"
extension: "mysqli"

services:
mariadb:
Expand Down Expand Up @@ -179,6 +197,8 @@ jobs:

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

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml"
Expand Down Expand Up @@ -216,6 +236,14 @@ jobs:
dbal-version: "4@dev"
mysql-version: "8.0"
extension: "pdo_mysql"
- php-version: "8.2"
dbal-version: "3@dev"
mysql-version: "8.0"
extension: "mysqli"
- php-version: "8.2"
dbal-version: "3@dev"
mysql-version: "8.0"
extension: "pdo_mysql"

services:
mysql:
Expand Down Expand Up @@ -249,6 +277,8 @@ jobs:

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

- name: "Run PHPUnit"
run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage-no-cache.xml"
Expand Down
22 changes: 22 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,28 @@ Use `toIterable()` instead.

# Upgrade to 2.13

## Deprecated omitting only the alias argument for `QueryBuilder::update` and `QueryBuilder::delete`

When building an UPDATE or DELETE query and when passing a class/type to the function, the alias argument must not be omitted.

### Before

```php
$qb = $em->createQueryBuilder()
->delete('User u')
->where('u.id = :user_id')
->setParameter('user_id', 1);
```

### After

```php
$qb = $em->createQueryBuilder()
->delete('User', 'u')
->where('u.id = :user_id')
->setParameter('user_id', 1);
```

## Deprecated using the `IDENTITY` identifier strategy on platform that do not support identity columns

If identity columns are emulated with sequences on the platform you are using,
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
"doctrine/annotations": "^1.13",
"doctrine/coding-standard": "^9.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "1.7.9",
"phpstan/phpstan": "1.7.13",
"phpunit/phpunit": "^9.5",
"psr/log": "^1 || ^2 || ^3",
"squizlabs/php_codesniffer": "3.6.2",
"squizlabs/php_codesniffer": "3.7.0",
"symfony/cache": "^4.4 || ^5.4 || ^6.0",
"vimeo/psalm": "4.23.0"
},
Expand Down
5 changes: 4 additions & 1 deletion lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ public function isTransient($className)
*/
public function loadMetadataForClass($className, PersistenceClassMetadata $metadata): void
{
$reflectionClass = $metadata->getReflectionClass();
$reflectionClass = $metadata->getReflectionClass()
// this happens when running annotation driver in combination with
// static reflection services. This is not the nicest fix
?? new ReflectionClass($metadata->name);

$classAttributes = $this->reader->getClassAnnotations($reflectionClass);

Expand Down
11 changes: 3 additions & 8 deletions lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,10 @@ private function reverseEngineerMappingFromDatabase(): void
return;
}

$tables = [];

foreach ($this->_sm->listTableNames() as $tableName) {
$tables[$tableName] = $this->_sm->listTableDetails($tableName);
}

$this->tables = $this->manyToManyTables = $this->classToTableNames = [];

foreach ($tables as $tableName => $table) {
foreach ($this->_sm->listTables() as $table) {
$tableName = $table->getName();
$foreignKeys = $table->getForeignKeys();

$allForeignKeyColumns = [];
Expand All @@ -291,7 +286,7 @@ private function reverseEngineerMappingFromDatabase(): void

if (! $table->hasPrimaryKey()) {
throw new MappingException(
'Table ' . $table->getName() . ' has no primary key. Doctrine does not ' .
'Table ' . $tableName . ' has no primary key. Doctrine does not ' .
"support reverse engineering from tables that don't have a primary key."
);
}
Expand Down
17 changes: 17 additions & 0 deletions lib/Doctrine/ORM/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Parameter;
use Doctrine\ORM\Query\QueryExpressionVisitor;
Expand Down Expand Up @@ -742,6 +743,14 @@ public function delete(?string $delete = null, ?string $alias = null): static
return $this;
}

if (! $alias) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9733',
'Omitting the alias is deprecated and will throw an exception in Doctrine 3.0.'
);
}

return $this->add('from', new Expr\From($delete, $alias));
}

Expand Down Expand Up @@ -769,6 +778,14 @@ public function update(?string $update = null, ?string $alias = null): static
return $this;
}

if (! $alias) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9733',
'Omitting the alias is deprecated and will throw an exception in Doctrine 3.0.'
);
}

return $this->add('from', new Expr\From($update, $alias));
}

Expand Down
17 changes: 0 additions & 17 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,4 @@
<!-- https://github.com/doctrine/orm/issues/8537 -->
<exclude-pattern>lib/Doctrine/ORM/QueryBuilder.php</exclude-pattern>
</rule>

<rule ref="Generic.WhiteSpace.ScopeIndent.Incorrect">
<!-- see https://github.com/squizlabs/PHP_CodeSniffer/issues/3474 -->
<exclude-pattern>tests/Doctrine/Tests/Models/Enums/AccessLevel.php</exclude-pattern>
<exclude-pattern>tests/Doctrine/Tests/Models/Enums/City.php</exclude-pattern>
<exclude-pattern>tests/Doctrine/Tests/Models/Enums/Suit.php</exclude-pattern>
<exclude-pattern>tests/Doctrine/Tests/Models/Enums/Unit.php</exclude-pattern>
<exclude-pattern>tests/Doctrine/Tests/Models/Enums/UserStatus.php</exclude-pattern>
</rule>
<rule ref="Generic.WhiteSpace.ScopeIndent.IncorrectExact">
<!-- see https://github.com/squizlabs/PHP_CodeSniffer/issues/3474 -->
<exclude-pattern>tests/Doctrine/Tests/Models/Enums/AccessLevel.php</exclude-pattern>
<exclude-pattern>tests/Doctrine/Tests/Models/Enums/City.php</exclude-pattern>
<exclude-pattern>tests/Doctrine/Tests/Models/Enums/Suit.php</exclude-pattern>
<exclude-pattern>tests/Doctrine/Tests/Models/Enums/Unit.php</exclude-pattern>
<exclude-pattern>tests/Doctrine/Tests/Models/Enums/UserStatus.php</exclude-pattern>
</rule>
</ruleset>
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php

-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 1
path: lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php

-
message: "#^Empty array passed to foreach\\.$#"
count: 1
Expand Down
6 changes: 5 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,9 @@
</UndefinedInterfaceMethod>
</file>
<file src="lib/Doctrine/ORM/Mapping/Driver/AttributeDriver.php">
<DocblockTypeContradiction occurrences="1">
<code>new ReflectionClass($metadata-&gt;name)</code>
</DocblockTypeContradiction>
<InvalidArrayAccess occurrences="4">
<code>$value[0]</code>
<code>$value[0]</code>
Expand All @@ -602,7 +605,8 @@
<code>assert($method instanceof ReflectionMethod)</code>
<code>assert($property instanceof ReflectionProperty)</code>
</RedundantCondition>
<RedundantConditionGivenDocblockType occurrences="1">
<RedundantConditionGivenDocblockType occurrences="2">
<code>$metadata-&gt;getReflectionClass()</code>
<code>assert($cacheAttribute instanceof Mapping\Cache)</code>
</RedundantConditionGivenDocblockType>
</file>
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/Models/Enums/AccessLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

enum AccessLevel: int
{
case Admin = 1;
case User = 2;
case Admin = 1;
case User = 2;
case Guests = 3;
}
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/Models/Enums/City.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

enum City: string
{
case Paris = 'Paris';
case Cannes = 'Cannes';
case Paris = 'Paris';
case Cannes = 'Cannes';
case StJulien = 'St Julien';
}
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/Models/Enums/Suit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

enum Suit: string
{
case Hearts = 'H';
case Hearts = 'H';
case Diamonds = 'D';
case Clubs = 'C';
case Spades = 'S';
case Clubs = 'C';
case Spades = 'S';
}
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Models/Enums/Unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

enum Unit: string
{
case Gram = 'g';
case Gram = 'g';
case Meter = 'm';
}
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Models/Enums/UserStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

enum UserStatus: string
{
case Active = 'active';
case Active = 'active';
case Inactive = 'inactive';
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase
/** @var CmsPhonenumber */
private $phonenumber;

/** @var array<string, mixed> */
private $previousCacheConfig = [];

protected function setUp(): void
{
$this->useModelSet('tweet');
Expand Down
24 changes: 24 additions & 0 deletions tests/Doctrine/Tests/ORM/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\Cache;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Expr\Join;
Expand All @@ -28,6 +29,8 @@
*/
class QueryBuilderTest extends OrmTestCase
{
use VerifyDeprecations;

private EntityManagerMock $entityManager;

protected function setUp(): void
Expand Down Expand Up @@ -1277,4 +1280,25 @@ public function testJoin(): void

self::assertSame('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN Doctrine\Tests\Models\CMS\CmsArticle a0 INNER JOIN Doctrine\Tests\Models\CMS\CmsArticle a1', $builder->getDQL());
}

public function testUpdateDeprecationMessage(): void
{
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/9733');

$qb = $this->entityManager->createQueryBuilder()
->update(CmsUser::class . ' u')
->set('u.username', ':username');

$this->assertValidQueryBuilder($qb, 'UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.username = :username');
}

public function testDeleteDeprecationMessage(): void
{
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/9733');

$qb = $this->entityManager->createQueryBuilder()
->delete(CmsUser::class . ' u');

$this->assertValidQueryBuilder($qb, 'DELETE Doctrine\Tests\Models\CMS\CmsUser u ');
}
}

0 comments on commit 318e6ec

Please sign in to comment.