Skip to content

Commit

Permalink
Merge branch '3.0.x' into 3.1.x
Browse files Browse the repository at this point in the history
* 3.0.x:
  Remove broken assertion from DateAddFunction and DateSubFunction (#11243)
  Remove unused trait
  [Documentation] Adding link to Postgres upgrade article (#11257)
  fix: support array-type arg in QB variadic calls (#11242)
  • Loading branch information
derrabus committed Feb 21, 2024
2 parents 78dc63d + bc5efd4 commit fcf1116
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
include:
- dbal-version: default
config: phpstan.neon
- dbal-version: 3.7
- dbal-version: 3.8.2
config: phpstan-dbal3.neon

steps:
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
matrix:
dbal-version:
- default
- 3.7
- 3.8.2

steps:
- name: "Checkout code"
Expand Down
6 changes: 3 additions & 3 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ so `$targetEntity` is a first argument now. This change affects only non-named a

When using the `AUTO` strategy to let Doctrine determine the identity generation mechanism for
an entity, and when using `doctrine/dbal` 4, PostgreSQL now uses `IDENTITY`
instead of `SEQUENCE`. When upgrading from ORM 2.x and preference is on keeping
the `SEQUENCE` based identity generation, then configure the ORM this way:

instead of `SEQUENCE` or `SERIAL`.
* If you want to upgrade your existing tables to identity columns, you will need to follow [migration to identity columns on PostgreSQL](https://www.doctrine-project.org/projects/doctrine-dbal/en/4.0/how-to/postgresql-identity-migration.html)
* If you want to keep using SQL sequences, you need to configure the ORM this way:
```php
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\ORM\Configuration;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"composer-runtime-api": "^2",
"ext-ctype": "*",
"doctrine/collections": "^2.1",
"doctrine/dbal": "^3.6 || ^4",
"doctrine/dbal": "^3.8.2 || ^4",
"doctrine/deprecations": "^0.5.3 || ^1",
"doctrine/event-manager": "^1.2 || ^2",
"doctrine/inflector": "^1.4 || ^2.0",
Expand Down
13 changes: 2 additions & 11 deletions src/Query/AST/Functions/DateAddFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;

use function assert;
use function is_numeric;
use function strtolower;

/**
Expand Down Expand Up @@ -63,17 +61,10 @@ public function getSql(SqlWalker $sqlWalker): string
};
}

/**
* @return numeric-string
*
* @throws ASTException
*/
/** @throws ASTException */
private function dispatchIntervalExpression(SqlWalker $sqlWalker): string
{
$sql = $this->intervalExpression->dispatch($sqlWalker);
assert(is_numeric($sql));

return $sql;
return $this->intervalExpression->dispatch($sqlWalker);
}

public function parse(Parser $parser): void
Expand Down
13 changes: 2 additions & 11 deletions src/Query/AST/Functions/DateSubFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\Query\SqlWalker;

use function assert;
use function is_numeric;
use function strtolower;

/**
Expand Down Expand Up @@ -56,16 +54,9 @@ public function getSql(SqlWalker $sqlWalker): string
};
}

/**
* @return numeric-string
*
* @throws ASTException
*/
/** @throws ASTException */
private function dispatchIntervalExpression(SqlWalker $sqlWalker): string
{
$sql = $this->intervalExpression->dispatch($sqlWalker);
assert(is_numeric($sql));

return $sql;
return $this->intervalExpression->dispatch($sqlWalker);
}
}
6 changes: 6 additions & 0 deletions src/Query/Expr/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
use InvalidArgumentException;
use Stringable;

use function array_key_exists;
use function count;
use function get_debug_type;
use function implode;
use function in_array;
use function is_array;
use function is_string;
use function sprintf;

Expand All @@ -33,6 +35,10 @@ abstract class Base implements Stringable

public function __construct(mixed $args = [])
{
if (is_array($args) && array_key_exists(0, $args) && is_array($args[0])) {
$args = $args[0];
}

$this->addMultiple($args);
}

Expand Down
3 changes: 0 additions & 3 deletions tests/Tests/ORM/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\Tests\ORM;

use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\Cache\CacheConfiguration;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityRepository;
Expand All @@ -26,8 +25,6 @@
*/
class ConfigurationTest extends TestCase
{
use VerifyDeprecations;

private Configuration $configuration;

protected function setUp(): void
Expand Down
3 changes: 0 additions & 3 deletions tests/Tests/ORM/EntityManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Doctrine\Common\EventManager;
use Doctrine\DBAL\Connection;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Exception\EntityManagerClosed;
Expand All @@ -27,8 +26,6 @@

class EntityManagerTest extends OrmTestCase
{
use VerifyDeprecations;

private EntityManagerMock $entityManager;

protected function setUp(): void
Expand Down
2 changes: 0 additions & 2 deletions tests/Tests/ORM/Functional/NativeQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\Internal\Hydration\HydrationException;
use Doctrine\ORM\Internal\SQLResultCasing;
use Doctrine\ORM\PersistentCollection;
Expand All @@ -33,7 +32,6 @@
class NativeQueryTest extends OrmFunctionalTestCase
{
use SQLResultCasing;
use VerifyDeprecations;

private AbstractPlatform|null $platform = null;

Expand Down
31 changes: 31 additions & 0 deletions tests/Tests/ORM/Functional/QueryDqlFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DateTimeImmutable;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\ORM\AbstractQuery;
use Doctrine\Tests\Models\Company\CompanyEmployee;
use Doctrine\Tests\Models\Company\CompanyManager;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
Expand Down Expand Up @@ -487,4 +488,34 @@ protected function generateFixture(): void
$this->_em->flush();
$this->_em->clear();
}

#[Group('GH-11240')]
public function testDateAddWithColumnInterval(): void
{
$query = sprintf(
'SELECT DATE_ADD(CURRENT_TIMESTAMP(), m.salary, \'day\') AS add FROM %s m',
CompanyEmployee::class,
);

$result = $this->_em->createQuery($query)
->setMaxResults(1)
->getSingleResult(AbstractQuery::HYDRATE_ARRAY);

self::assertArrayHasKey('add', $result);
}

#[Group('GH-11240')]
public function testDateSubWithColumnInterval(): void
{
$query = sprintf(
'SELECT DATE_SUB(CURRENT_TIMESTAMP(), m.salary, \'day\') AS add FROM %s m',
CompanyEmployee::class,
);

$result = $this->_em->createQuery($query)
->setMaxResults(1)
->getSingleResult(AbstractQuery::HYDRATE_ARRAY);

self::assertArrayHasKey('add', $result);
}
}
3 changes: 0 additions & 3 deletions tests/Tests/ORM/Functional/Ticket/DDC117Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\UnitOfWork;
use Doctrine\Tests\Models\DDC117\DDC117ApproveChanges;
use Doctrine\Tests\Models\DDC117\DDC117Article;
Expand All @@ -23,8 +22,6 @@
#[Group('DDC-117')]
class DDC117Test extends OrmFunctionalTestCase
{
use VerifyDeprecations;

private DDC117Article|null $article1;

private DDC117Article|null $article2;
Expand Down
3 changes: 0 additions & 3 deletions tests/Tests/ORM/Mapping/BasicInheritanceMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\Tests\ORM\Mapping;

use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Id\SequenceGenerator as IdSequenceGenerator;
use Doctrine\ORM\Mapping\ClassMetadata;
Expand Down Expand Up @@ -42,8 +41,6 @@

class BasicInheritanceMappingTest extends OrmTestCase
{
use VerifyDeprecations;

private ClassMetadataFactory $cmf;

protected function setUp(): void
Expand Down
3 changes: 0 additions & 3 deletions tests/Tests/ORM/Mapping/ClassMetadataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs;
Expand Down Expand Up @@ -55,8 +54,6 @@

class ClassMetadataFactoryTest extends OrmTestCase
{
use VerifyDeprecations;

public function testGetMetadataForSingleClass(): void
{
$platform = $this->createMock(AbstractPlatform::class);
Expand Down
3 changes: 0 additions & 3 deletions tests/Tests/ORM/Query/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Types;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\Query\Parameter;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\UnitOfWork;
Expand All @@ -40,8 +39,6 @@

class QueryTest extends OrmTestCase
{
use VerifyDeprecations;

/** @var EntityManagerMock */
protected $entityManager;

Expand Down
9 changes: 9 additions & 0 deletions tests/Tests/ORM/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ public function testSimpleSelect(): void
$this->assertValidQueryBuilder($qb, 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u');
}

public function testSimpleSelectArray(): void
{
$qb = $this->entityManager->createQueryBuilder()
->from(CmsUser::class, 'u')
->select(['u.id', 'u.username']);

$this->assertValidQueryBuilder($qb, 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u');
}

public function testSimpleDelete(): void
{
$qb = $this->entityManager->createQueryBuilder()
Expand Down
3 changes: 0 additions & 3 deletions tests/Tests/ORM/UnitOfWorkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\EntityNotFoundException;
use Doctrine\ORM\Exception\EntityIdentityCollisionException;
use Doctrine\ORM\Mapping\ClassMetadata;
Expand Down Expand Up @@ -46,8 +45,6 @@
*/
class UnitOfWorkTest extends OrmTestCase
{
use VerifyDeprecations;

/**
* SUT
*/
Expand Down

0 comments on commit fcf1116

Please sign in to comment.