mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 15:02:22 +01:00
Compare commits
47 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c322c71cd4 | ||
|
|
3c733a2fee | ||
|
|
5984ad586a | ||
|
|
ee2c3a506b | ||
|
|
04694a9f7b | ||
|
|
5b2060e25f | ||
|
|
39e35fc06c | ||
|
|
7f061c3870 | ||
|
|
74495711fb | ||
|
|
97a7cb8d2f | ||
|
|
e0052390e1 | ||
|
|
8c6419e0e0 | ||
|
|
6f5ce1aca2 | ||
|
|
98e7a53b42 | ||
|
|
3aaaf37dfb | ||
|
|
154a4652ee | ||
|
|
ae7489ff19 | ||
|
|
1ee01f4473 | ||
|
|
8a9ed138a8 | ||
|
|
41ea59ac66 | ||
|
|
e605e6d569 | ||
|
|
6307b4fa7d | ||
|
|
5d21bb158b | ||
|
|
528b8837e1 | ||
|
|
067ad51b3f | ||
|
|
00c77213fb | ||
|
|
c68b8f90b3 | ||
|
|
aa4f9ce9e9 | ||
|
|
d96fc23327 | ||
|
|
4fb044d5f6 | ||
|
|
2a953c5e2b | ||
|
|
abc6a40ccb | ||
|
|
73e68f3c7d | ||
|
|
73777d0bd4 | ||
|
|
ec6d1b9f72 | ||
|
|
d809fed52a | ||
|
|
0e4786dfa8 | ||
|
|
c429262f02 | ||
|
|
f4fdcbcdcb | ||
|
|
b0806469d5 | ||
|
|
e89b58a13f | ||
|
|
2b94ec18b9 | ||
|
|
2a662149f4 | ||
|
|
37051d57ce | ||
|
|
4563f2f9a7 | ||
|
|
91201c094a | ||
|
|
a4a15ad243 |
2
.github/workflows/continuous-integration.yml
vendored
2
.github/workflows/continuous-integration.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: "Continuous Integration"
|
||||
name: "CI"
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
27
README.md
27
README.md
@@ -1,7 +1,7 @@
|
||||
| [4.0.x][4.0] | [3.4.x][3.4] | [3.3.x][3.3] | [2.21.x][2.21] | [2.20.x][2.20] |
|
||||
| [4.0.x][4.0] | [3.6.x][3.6] | [3.5.x][3.5] | [2.21.x][2.21] | [2.20.x][2.20] |
|
||||
|:------------------------------------------------------:|:------------------------------------------------------:|:------------------------------------------------------:|:--------------------------------------------------------:|:--------------------------------------------------------:|
|
||||
| [![Build status][4.0 image]][4.0] | [![Build status][3.4 image]][3.4] | [![Build status][3.3 image]][3.3] | [![Build status][2.21 image]][2.21] | [![Build status][2.20 image]][2.20] |
|
||||
| [![Coverage Status][4.0 coverage image]][4.0 coverage] | [![Coverage Status][3.4 coverage image]][3.4 coverage] | [![Coverage Status][3.3 coverage image]][3.3 coverage] | [![Coverage Status][2.21 coverage image]][2.21 coverage] | [![Coverage Status][2.20 coverage image]][2.20 coverage] |
|
||||
| [![Build status][4.0 image]][4.0 workflow] | [![Build status][3.6 image]][3.6 workflow] | [![Build status][3.5 image]][3.5 workflow] | [![Build status][2.21 image]][2.21 workflow] | [![Build status][2.20 image]][2.20 workflow] |
|
||||
| [![Coverage Status][4.0 coverage image]][4.0 coverage] | [![Coverage Status][3.6 coverage image]][3.6 coverage] | [![Coverage Status][3.5 coverage image]][3.5 coverage] | [![Coverage Status][2.21 coverage image]][2.21 coverage] | [![Coverage Status][2.20 coverage image]][2.20 coverage] |
|
||||
|
||||
[<h1 align="center">🇺🇦 UKRAINE NEEDS YOUR HELP NOW!</h1>](https://www.doctrine-project.org/stop-war.html)
|
||||
|
||||
@@ -20,21 +20,26 @@ without requiring unnecessary code duplication.
|
||||
|
||||
[4.0 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0.x
|
||||
[4.0]: https://github.com/doctrine/orm/tree/4.0.x
|
||||
[4.0 workflow]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml?query=branch%3A4.0.x
|
||||
[4.0 coverage image]: https://codecov.io/gh/doctrine/orm/branch/4.0.x/graph/badge.svg
|
||||
[4.0 coverage]: https://codecov.io/gh/doctrine/orm/branch/4.0.x
|
||||
[3.4 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.4.x
|
||||
[3.4]: https://github.com/doctrine/orm/tree/3.4.x
|
||||
[3.4 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.4.x/graph/badge.svg
|
||||
[3.4 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.4.x
|
||||
[3.3 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.3.x
|
||||
[3.3]: https://github.com/doctrine/orm/tree/3.3.x
|
||||
[3.3 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.3.x/graph/badge.svg
|
||||
[3.3 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.3.x
|
||||
[3.6 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.6.x
|
||||
[3.6]: https://github.com/doctrine/orm/tree/3.6.x
|
||||
[3.6 workflow]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml?query=branch%3A3.6.x
|
||||
[3.6 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.6.x/graph/badge.svg
|
||||
[3.6 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.6.x
|
||||
[3.5 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=3.5.x
|
||||
[3.5]: https://github.com/doctrine/orm/tree/3.5.x
|
||||
[3.5 workflow]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml?query=branch%3A3.5.x
|
||||
[3.5 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.5.x/graph/badge.svg
|
||||
[3.5 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.5.x
|
||||
[2.21 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=2.21.x
|
||||
[2.21]: https://github.com/doctrine/orm/tree/2.21.x
|
||||
[2.21 workflow]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml?query=branch%3A2.21.x
|
||||
[2.21 coverage image]: https://codecov.io/gh/doctrine/orm/branch/2.21.x/graph/badge.svg
|
||||
[2.21 coverage]: https://codecov.io/gh/doctrine/orm/branch/2.21.x
|
||||
[2.20 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=2.20.x
|
||||
[2.20]: https://github.com/doctrine/orm/tree/2.20.x
|
||||
[2.20 workflow]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml?query=branch%3A2.20.x
|
||||
[2.20 coverage image]: https://codecov.io/gh/doctrine/orm/branch/2.20.x/graph/badge.svg
|
||||
[2.20 coverage]: https://codecov.io/gh/doctrine/orm/branch/2.20.x
|
||||
|
||||
@@ -11,7 +11,7 @@ parameters:
|
||||
|
||||
# Fallback logic for DBAL 2
|
||||
-
|
||||
message: '/Application::add\(\) expects Symfony\\Component\\Console\\Command\\Command/'
|
||||
message: '/Parameter #2 \$command of static method Doctrine\\ORM\\Tools\\Console\\ConsoleRunner\:\:addCommandToApplication\(\) expects Symfony\\Component\\Console\\Command\\Command/'
|
||||
path: src/Tools/Console/ConsoleRunner.php
|
||||
|
||||
- '/^Class Doctrine\\DBAL\\Platforms\\SQLAnywherePlatform not found\.$/'
|
||||
|
||||
@@ -9,7 +9,7 @@ parameters:
|
||||
|
||||
# Fallback logic for DBAL 2
|
||||
-
|
||||
message: '/Application::add\(\) expects Symfony\\Component\\Console\\Command\\Command/'
|
||||
message: '/Parameter #2 \$command of static method Doctrine\\ORM\\Tools\\Console\\ConsoleRunner\:\:addCommandToApplication\(\) expects Symfony\\Component\\Console\\Command\\Command/'
|
||||
path: src/Tools/Console/ConsoleRunner.php
|
||||
|
||||
- '/^Class Doctrine\\DBAL\\Platforms\\SQLAnywherePlatform not found\.$/'
|
||||
|
||||
@@ -168,14 +168,6 @@ class BasicEntityPersister implements EntityPersister
|
||||
*/
|
||||
protected $quotedColumns = [];
|
||||
|
||||
/**
|
||||
* The INSERT SQL statement used for entities handled by this persister.
|
||||
* This SQL is only generated once per request, if at all.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
private $insertSql;
|
||||
|
||||
/**
|
||||
* The quote strategy.
|
||||
*
|
||||
@@ -310,8 +302,8 @@ class BasicEntityPersister implements EntityPersister
|
||||
$this->assignDefaultVersionAndUpsertableValues($entity, $id);
|
||||
}
|
||||
|
||||
// Unset this queued insert, so that the prepareUpdateData() method knows right away
|
||||
// (for the next entity already) that the current entity has been written to the database
|
||||
// Unset this queued insert, so that the prepareUpdateData() method (called via prepareInsertData() method)
|
||||
// knows right away (for the next entity already) that the current entity has been written to the database
|
||||
// and no extra updates need to be scheduled to refer to it.
|
||||
//
|
||||
// In \Doctrine\ORM\UnitOfWork::executeInserts(), the UoW already removed entities
|
||||
@@ -1473,22 +1465,17 @@ class BasicEntityPersister implements EntityPersister
|
||||
*/
|
||||
public function getInsertSQL()
|
||||
{
|
||||
if ($this->insertSql !== null) {
|
||||
return $this->insertSql;
|
||||
}
|
||||
|
||||
$columns = $this->getInsertColumnList();
|
||||
$tableName = $this->quoteStrategy->getTableName($this->class, $this->platform);
|
||||
|
||||
if (empty($columns)) {
|
||||
$identityColumn = $this->quoteStrategy->getColumnName($this->class->identifier[0], $this->class, $this->platform);
|
||||
$this->insertSql = $this->platform->getEmptyIdentityInsertSQL($tableName, $identityColumn);
|
||||
if ($columns === []) {
|
||||
$identityColumn = $this->quoteStrategy->getColumnName($this->class->identifier[0], $this->class, $this->platform);
|
||||
|
||||
return $this->insertSql;
|
||||
return $this->platform->getEmptyIdentityInsertSQL($tableName, $identityColumn);
|
||||
}
|
||||
|
||||
$values = [];
|
||||
$columns = array_unique($columns);
|
||||
$placeholders = [];
|
||||
$columns = array_unique($columns);
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$placeholder = '?';
|
||||
@@ -1502,15 +1489,13 @@ class BasicEntityPersister implements EntityPersister
|
||||
$placeholder = $type->convertToDatabaseValueSQL('?', $this->platform);
|
||||
}
|
||||
|
||||
$values[] = $placeholder;
|
||||
$placeholders[] = $placeholder;
|
||||
}
|
||||
|
||||
$columns = implode(', ', $columns);
|
||||
$values = implode(', ', $values);
|
||||
$columns = implode(', ', $columns);
|
||||
$placeholders = implode(', ', $placeholders);
|
||||
|
||||
$this->insertSql = sprintf('INSERT INTO %s (%s) VALUES (%s)', $tableName, $columns, $values);
|
||||
|
||||
return $this->insertSql;
|
||||
return sprintf('INSERT INTO %s (%s) VALUES (%s)', $tableName, $columns, $placeholders);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -149,7 +149,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
// Execute all inserts. For each entity:
|
||||
// 1) Insert on root table
|
||||
// 2) Insert on sub tables
|
||||
foreach ($this->queuedInserts as $entity) {
|
||||
foreach ($this->queuedInserts as $key => $entity) {
|
||||
$insertData = $this->prepareInsertData($entity);
|
||||
|
||||
// Execute insert on root table
|
||||
@@ -194,9 +194,16 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
if ($this->class->requiresFetchAfterChange) {
|
||||
$this->assignDefaultVersionAndUpsertableValues($entity, $id);
|
||||
}
|
||||
}
|
||||
|
||||
$this->queuedInserts = [];
|
||||
// Unset this queued insert, so that the prepareUpdateData() method (called via prepareInsertData() method)
|
||||
// knows right away (for the next entity already) that the current entity has been written to the database
|
||||
// and no extra updates need to be scheduled to refer to it.
|
||||
//
|
||||
// In \Doctrine\ORM\UnitOfWork::executeInserts(), the UoW already removed entities
|
||||
// from its own list (\Doctrine\ORM\UnitOfWork::$entityInsertions) right after they
|
||||
// were given to our addInsert() method.
|
||||
unset($this->queuedInserts[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1554,7 +1554,7 @@ class Parser
|
||||
|
||||
assert($this->lexer->lookahead !== null);
|
||||
switch (true) {
|
||||
case $this->isMathOperator($peek):
|
||||
case $this->isMathOperator($peek) || $this->isMathOperator($glimpse):
|
||||
$expr = $this->SimpleArithmeticExpression();
|
||||
break;
|
||||
|
||||
|
||||
28
src/Tools/Console/ApplicationCompatibility.php
Normal file
28
src/Tools/Console/ApplicationCompatibility.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
use function method_exists;
|
||||
|
||||
/**
|
||||
* Forward compatibility with Symfony Console 7.4
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
trait ApplicationCompatibility
|
||||
{
|
||||
private static function addCommandToApplication(Application $application, Command $command): ?Command
|
||||
{
|
||||
if (method_exists(Application::class, 'addCommand')) {
|
||||
// @phpstan-ignore method.notFound (This method will be added in Symfony 7.4)
|
||||
return $application->addCommand($command);
|
||||
}
|
||||
|
||||
return $application->add($command);
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,7 @@ EOT
|
||||
$this->formatField('Embedded class?', $metadata->isEmbeddedClass),
|
||||
$this->formatField('Parent classes', $metadata->parentClasses),
|
||||
$this->formatField('Sub classes', $metadata->subClasses),
|
||||
$this->formatField('Embedded classes', $metadata->subClasses),
|
||||
$this->formatField('Embedded classes', $metadata->embeddedClasses),
|
||||
$this->formatField('Named queries', $metadata->namedQueries),
|
||||
$this->formatField('Named native queries', $metadata->namedNativeQueries),
|
||||
$this->formatField('SQL result set mappings', $metadata->sqlResultSetMappings),
|
||||
|
||||
@@ -23,6 +23,8 @@ use function class_exists;
|
||||
*/
|
||||
final class ConsoleRunner
|
||||
{
|
||||
use ApplicationCompatibility;
|
||||
|
||||
/**
|
||||
* Create a Symfony Console HelperSet
|
||||
*
|
||||
@@ -91,7 +93,7 @@ final class ConsoleRunner
|
||||
$connectionProvider = new ConnectionFromManagerProvider($entityManagerProvider);
|
||||
|
||||
if (class_exists(DBALConsole\Command\ImportCommand::class)) {
|
||||
$cli->add(new DBALConsole\Command\ImportCommand());
|
||||
self::addCommandToApplication($cli, new DBALConsole\Command\ImportCommand());
|
||||
}
|
||||
|
||||
$cli->addCommands(
|
||||
|
||||
@@ -1060,7 +1060,9 @@ class UnitOfWork implements PropertyChangedListener
|
||||
|
||||
$this->entityStates[$oid] = self::STATE_MANAGED;
|
||||
|
||||
$this->scheduleForInsert($entity);
|
||||
if (! isset($this->entityInsertions[$oid])) {
|
||||
$this->scheduleForInsert($entity);
|
||||
}
|
||||
}
|
||||
|
||||
/** @param mixed[] $idValue */
|
||||
|
||||
238
tests/Doctrine/Tests/ORM/Functional/GH8011Test.php
Normal file
238
tests/Doctrine/Tests/ORM/Functional/GH8011Test.php
Normal file
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
||||
use Doctrine\Tests\Models\Company\CompanyEmployee;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* Functional tests for ordering with arithmetic expression.
|
||||
*
|
||||
* @group GH8011
|
||||
*/
|
||||
class GH8011Test extends OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->useModelSet('company');
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$this->generateFixture();
|
||||
}
|
||||
|
||||
private function skipIfPostgres(string $test): void
|
||||
{
|
||||
$platform = $this->_em->getConnection()->getDatabasePlatform();
|
||||
if ($platform instanceof PostgreSQLPlatform) {
|
||||
self::markTestSkipped(
|
||||
'The ' . $test . ' test does not work on postgresql (see https://github.com/doctrine/orm/pull/8012).'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testOrderWithArithmeticExpressionWithSingleValuedPathExpression(): void
|
||||
{
|
||||
$dql = 'SELECT p ' .
|
||||
'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
|
||||
'ORDER BY p.id + p.id ASC';
|
||||
|
||||
/** @var CompanyEmployee[] $result */
|
||||
$result = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertEquals('Benjamin E.', $result[0]->getName());
|
||||
$this->assertEquals('Guilherme B.', $result[1]->getName());
|
||||
}
|
||||
|
||||
public function testOrderWithArithmeticExpressionWithLiteralAndSingleValuedPathExpression(): void
|
||||
{
|
||||
$dql = 'SELECT p ' .
|
||||
'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
|
||||
'ORDER BY 1 + p.id ASC';
|
||||
|
||||
/** @var CompanyEmployee[] $result */
|
||||
$result = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertEquals('Benjamin E.', $result[0]->getName());
|
||||
$this->assertEquals('Guilherme B.', $result[1]->getName());
|
||||
}
|
||||
|
||||
public function testOrderWithArithmeticExpressionWithLiteralAndSingleValuedPathExpression2(): void
|
||||
{
|
||||
$dql = 'SELECT p ' .
|
||||
'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
|
||||
'ORDER BY ((1 + p.id)) ASC';
|
||||
|
||||
/** @var CompanyEmployee[] $result */
|
||||
$result = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertEquals('Benjamin E.', $result[0]->getName());
|
||||
$this->assertEquals('Guilherme B.', $result[1]->getName());
|
||||
}
|
||||
|
||||
public function testOrderWithArithmeticExpressionWithSingleValuedPathExpressionAndLiteral(): void
|
||||
{
|
||||
$dql = 'SELECT p ' .
|
||||
'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
|
||||
'ORDER BY p.id + 1 ASC';
|
||||
|
||||
/** @var CompanyEmployee[] $result */
|
||||
$result = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertEquals('Benjamin E.', $result[0]->getName());
|
||||
$this->assertEquals('Guilherme B.', $result[1]->getName());
|
||||
}
|
||||
|
||||
public function testOrderWithArithmeticExpressionWithResultVariableAndLiteral(): void
|
||||
{
|
||||
$this->skipIfPostgres(__FUNCTION__);
|
||||
|
||||
$dql = 'SELECT p, p.salary AS HIDDEN s ' .
|
||||
'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
|
||||
'ORDER BY s + 1 DESC';
|
||||
|
||||
/** @var CompanyEmployee[] $result */
|
||||
$result = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertEquals('Guilherme B.', $result[0]->getName());
|
||||
$this->assertEquals('Benjamin E.', $result[1]->getName());
|
||||
}
|
||||
|
||||
public function testOrderWithArithmeticExpressionWithResultVariableAndLiteral2(): void
|
||||
{
|
||||
$this->skipIfPostgres(__FUNCTION__);
|
||||
|
||||
$dql = 'SELECT p, p.salary AS HIDDEN s ' .
|
||||
'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
|
||||
'ORDER BY ((s + 1)) DESC';
|
||||
|
||||
/** @var CompanyEmployee[] $result */
|
||||
$result = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertEquals('Guilherme B.', $result[0]->getName());
|
||||
$this->assertEquals('Benjamin E.', $result[1]->getName());
|
||||
}
|
||||
|
||||
public function testOrderWithArithmeticExpressionWithLiteralAndResultVariable(): void
|
||||
{
|
||||
$this->skipIfPostgres(__FUNCTION__);
|
||||
|
||||
$dql = 'SELECT p, p.salary AS HIDDEN s ' .
|
||||
'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
|
||||
'ORDER BY 1 + s DESC';
|
||||
|
||||
/** @var CompanyEmployee[] $result */
|
||||
$result = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertEquals('Guilherme B.', $result[0]->getName());
|
||||
$this->assertEquals('Benjamin E.', $result[1]->getName());
|
||||
}
|
||||
|
||||
public function testOrderWithArithmeticExpressionWithLiteralAndResultVariable2(): void
|
||||
{
|
||||
$this->skipIfPostgres(__FUNCTION__);
|
||||
|
||||
$dql = 'SELECT p, p.salary AS HIDDEN s ' .
|
||||
'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
|
||||
'ORDER BY ((1 + s)) DESC';
|
||||
|
||||
/** @var CompanyEmployee[] $result */
|
||||
$result = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertEquals('Guilherme B.', $result[0]->getName());
|
||||
$this->assertEquals('Benjamin E.', $result[1]->getName());
|
||||
}
|
||||
|
||||
public function testOrderWithArithmeticExpressionWithResultVariableAndSingleValuedPathExpression(): void
|
||||
{
|
||||
$this->skipIfPostgres(__FUNCTION__);
|
||||
|
||||
$dql = 'SELECT p, p.salary AS HIDDEN s ' .
|
||||
'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
|
||||
'ORDER BY s + p.id DESC';
|
||||
|
||||
/** @var CompanyEmployee[] $result */
|
||||
$result = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertEquals('Guilherme B.', $result[0]->getName());
|
||||
$this->assertEquals('Benjamin E.', $result[1]->getName());
|
||||
}
|
||||
|
||||
public function testOrderWithArithmeticExpressionWithResultVariableAndSingleValuedPathExpression2(): void
|
||||
{
|
||||
$this->skipIfPostgres(__FUNCTION__);
|
||||
|
||||
$dql = 'SELECT p, p.salary AS HIDDEN s ' .
|
||||
'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
|
||||
'ORDER BY ((s + p.id)) DESC';
|
||||
|
||||
/** @var CompanyEmployee[] $result */
|
||||
$result = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertEquals('Guilherme B.', $result[0]->getName());
|
||||
$this->assertEquals('Benjamin E.', $result[1]->getName());
|
||||
}
|
||||
|
||||
public function testOrderWithArithmeticExpressionWithSingleValuedPathExpressionAndResultVariable(): void
|
||||
{
|
||||
$this->skipIfPostgres(__FUNCTION__);
|
||||
|
||||
$dql = 'SELECT p, p.salary AS HIDDEN s ' .
|
||||
'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
|
||||
'ORDER BY p.id + s DESC';
|
||||
|
||||
/** @var CompanyEmployee[] $result */
|
||||
$result = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertEquals('Guilherme B.', $result[0]->getName());
|
||||
$this->assertEquals('Benjamin E.', $result[1]->getName());
|
||||
}
|
||||
|
||||
public function testOrderWithArithmeticExpressionWithLiteralAndResultVariableUsingHiddenResultVariable(): void
|
||||
{
|
||||
$dql = 'SELECT p, 1 + p.salary AS HIDDEN _order ' .
|
||||
'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
|
||||
'ORDER BY _order DESC';
|
||||
|
||||
/** @var CompanyEmployee[] $result */
|
||||
$result = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertEquals('Guilherme B.', $result[0]->getName());
|
||||
$this->assertEquals('Benjamin E.', $result[1]->getName());
|
||||
}
|
||||
|
||||
public function generateFixture(): void
|
||||
{
|
||||
$person1 = new CompanyEmployee();
|
||||
$person1->setName('Benjamin E.');
|
||||
$person1->setDepartment('IT');
|
||||
$person1->setSalary(200000);
|
||||
|
||||
$person2 = new CompanyEmployee();
|
||||
$person2->setName('Guilherme B.');
|
||||
$person2->setDepartment('IT2');
|
||||
$person2->setSalary(400000);
|
||||
|
||||
$this->_em->persist($person1);
|
||||
$this->_em->persist($person2);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
}
|
||||
}
|
||||
112
tests/Tests/ORM/Functional/PrePersistEventTest.php
Normal file
112
tests/Tests/ORM/Functional/PrePersistEventTest.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\ORM\Event\PrePersistEventArgs;
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\ORM\Mapping\Column;
|
||||
use Doctrine\ORM\Mapping\Entity;
|
||||
use Doctrine\ORM\Mapping\GeneratedValue;
|
||||
use Doctrine\ORM\Mapping\Id;
|
||||
use Doctrine\ORM\Mapping\ManyToOne;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
|
||||
use function uniqid;
|
||||
|
||||
class PrePersistEventTest extends OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->createSchemaForModels(
|
||||
EntityWithUnmappedEntity::class,
|
||||
EntityWithCascadeAssociation::class
|
||||
);
|
||||
}
|
||||
|
||||
public function testCallingPersistInPrePersistHook(): void
|
||||
{
|
||||
$entityWithUnmapped = new EntityWithUnmappedEntity();
|
||||
$entityWithCascade = new EntityWithCascadeAssociation();
|
||||
|
||||
$entityWithUnmapped->unmapped = $entityWithCascade;
|
||||
$entityWithCascade->cascaded = $entityWithUnmapped;
|
||||
|
||||
$this->_em->getEventManager()->addEventListener(Events::prePersist, new PrePersistUnmappedPersistListener());
|
||||
$this->_em->persist($entityWithUnmapped);
|
||||
|
||||
$this->assertTrue($this->_em->getUnitOfWork()->isScheduledForInsert($entityWithCascade));
|
||||
$this->assertTrue($this->_em->getUnitOfWork()->isScheduledForInsert($entityWithUnmapped));
|
||||
}
|
||||
}
|
||||
|
||||
class PrePersistUnmappedPersistListener
|
||||
{
|
||||
public function prePersist(PrePersistEventArgs $args): void
|
||||
{
|
||||
$object = $args->getObject();
|
||||
|
||||
if ($object instanceof EntityWithUnmappedEntity) {
|
||||
$uow = $args->getObjectManager()->getUnitOfWork();
|
||||
|
||||
if ($object->unmapped && ! $uow->isInIdentityMap($object->unmapped) && ! $uow->isScheduledForInsert($object->unmapped)) {
|
||||
$args->getObjectManager()->persist($object->unmapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
#[Entity]
|
||||
class EntityWithUnmappedEntity
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @Id
|
||||
* @Column(type="string", length=255)
|
||||
* @GeneratedValue(strategy="NONE")
|
||||
*/
|
||||
#[Id]
|
||||
#[Column(type: 'string', length: 255)]
|
||||
#[GeneratedValue(strategy: 'NONE')]
|
||||
public $id;
|
||||
|
||||
/** @var ?EntityWithCascadeAssociation */
|
||||
public $unmapped = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->id = uniqid(self::class, true);
|
||||
}
|
||||
}
|
||||
|
||||
/** @Entity */
|
||||
#[Entity]
|
||||
class EntityWithCascadeAssociation
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
* @Id
|
||||
* @Column(type="string", length=255)
|
||||
* @GeneratedValue(strategy="NONE")
|
||||
*/
|
||||
#[Id]
|
||||
#[Column(type: 'string', length: 255)]
|
||||
#[GeneratedValue(strategy: 'NONE')]
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @var ?EntityWithUnmappedEntity
|
||||
* @ManyToOne(targetEntity=EntityWithUnmappedEntity::class, cascade={"persist"})
|
||||
*/
|
||||
#[ManyToOne(targetEntity: EntityWithUnmappedEntity::class, cascade: ['persist'])]
|
||||
public $cascaded = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->id = uniqid(self::class, true);
|
||||
}
|
||||
}
|
||||
180
tests/Tests/ORM/Functional/SecondLevelCacheCountQueriesTest.php
Normal file
180
tests/Tests/ORM/Functional/SecondLevelCacheCountQueriesTest.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
use Doctrine\Tests\Models\Cache\Country;
|
||||
use ReflectionProperty;
|
||||
|
||||
use function array_diff;
|
||||
use function array_filter;
|
||||
use function file_exists;
|
||||
use function rmdir;
|
||||
use function scandir;
|
||||
use function strpos;
|
||||
use function sys_get_temp_dir;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* @group DDC-2183
|
||||
* @phpstan-type SupportedCacheUsage 0|ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE|ClassMetadata::CACHE_USAGE_READ_WRITE
|
||||
*/
|
||||
class SecondLevelCacheCountQueriesTest extends SecondLevelCacheFunctionalTestCase
|
||||
{
|
||||
/** @var string */
|
||||
private $tmpDir;
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if ($this->tmpDir !== null && file_exists($this->tmpDir)) {
|
||||
foreach (array_diff(scandir($this->tmpDir), ['.', '..']) as $f) {
|
||||
rmdir($this->tmpDir . DIRECTORY_SEPARATOR . $f);
|
||||
}
|
||||
|
||||
rmdir($this->tmpDir);
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/** @param SupportedCacheUsage $cacheUsage */
|
||||
private function setupCountryModel(int $cacheUsage): void
|
||||
{
|
||||
$metadata = $this->_em->getClassMetaData(Country::class);
|
||||
|
||||
if ($cacheUsage === 0) {
|
||||
$metadataCacheReflection = new ReflectionProperty(ClassMetadataInfo::class, 'cache');
|
||||
$metadataCacheReflection->setAccessible(true);
|
||||
$metadataCacheReflection->setValue($metadata, null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($cacheUsage === ClassMetadata::CACHE_USAGE_READ_WRITE) {
|
||||
$this->tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . self::class;
|
||||
$this->secondLevelCacheFactory->setFileLockRegionDirectory($this->tmpDir);
|
||||
}
|
||||
|
||||
$metadata->enableCache(['usage' => $cacheUsage]);
|
||||
}
|
||||
|
||||
private function loadFixturesCountriesWithoutPostInsertIdentifier(): void
|
||||
{
|
||||
$metadata = $this->_em->getClassMetaData(Country::class);
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
|
||||
$c1 = new Country('Brazil');
|
||||
$c1->setId(10);
|
||||
$c2 = new Country('Germany');
|
||||
$c2->setId(20);
|
||||
|
||||
$this->countries[] = $c1;
|
||||
$this->countries[] = $c2;
|
||||
|
||||
$this->_em->persist($c1);
|
||||
$this->_em->persist($c2);
|
||||
$this->_em->flush();
|
||||
}
|
||||
|
||||
/** @param 'INSERT'|'UPDATE'|'DELETE' $type */
|
||||
private function assertQueryCountByType(string $type, int $expectedCount): void
|
||||
{
|
||||
$queries = array_filter($this->getQueryLog()->queries, static function (array $entry) use ($type): bool {
|
||||
return strpos($entry['sql'], $type) === 0;
|
||||
});
|
||||
|
||||
self::assertCount($expectedCount, $queries);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SupportedCacheUsage $cacheUsage
|
||||
*
|
||||
* @dataProvider cacheUsageProvider
|
||||
*/
|
||||
public function testInsertWithPostInsertIdentifier(int $cacheUsage): void
|
||||
{
|
||||
$this->setupCountryModel($cacheUsage);
|
||||
|
||||
self::assertQueryCountByType('INSERT', 0);
|
||||
|
||||
$this->loadFixturesCountries();
|
||||
|
||||
self::assertCount(2, $this->countries);
|
||||
self::assertQueryCountByType('INSERT', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SupportedCacheUsage $cacheUsage
|
||||
*
|
||||
* @dataProvider cacheUsageProvider
|
||||
*/
|
||||
public function testInsertWithoutPostInsertIdentifier(int $cacheUsage): void
|
||||
{
|
||||
$this->setupCountryModel($cacheUsage);
|
||||
|
||||
self::assertQueryCountByType('INSERT', 0);
|
||||
|
||||
$this->loadFixturesCountriesWithoutPostInsertIdentifier();
|
||||
|
||||
self::assertCount(2, $this->countries);
|
||||
self::assertQueryCountByType('INSERT', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
/* @param SupportedCacheUsage $cacheUsage
|
||||
*
|
||||
* @dataProvider cacheUsageProvider
|
||||
*/
|
||||
public function testDelete(int $cacheUsage): void
|
||||
{
|
||||
$this->setupCountryModel($cacheUsage);
|
||||
$this->loadFixturesCountries();
|
||||
|
||||
$c1 = $this->_em->find(Country::class, $this->countries[0]->getId());
|
||||
$c2 = $this->_em->find(Country::class, $this->countries[1]->getId());
|
||||
|
||||
$this->_em->remove($c1);
|
||||
$this->_em->remove($c2);
|
||||
$this->_em->flush();
|
||||
|
||||
self::assertQueryCountByType('DELETE', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SupportedCacheUsage $cacheUsage
|
||||
*
|
||||
* @dataProvider cacheUsageProvider
|
||||
*/
|
||||
public function testUpdate(int $cacheUsage): void
|
||||
{
|
||||
$this->setupCountryModel($cacheUsage);
|
||||
$this->loadFixturesCountries();
|
||||
|
||||
$c1 = $this->_em->find(Country::class, $this->countries[0]->getId());
|
||||
$c2 = $this->_em->find(Country::class, $this->countries[1]->getId());
|
||||
|
||||
$c1->setName('Czech Republic');
|
||||
$c2->setName('Hungary');
|
||||
|
||||
$this->_em->persist($c1);
|
||||
$this->_em->persist($c2);
|
||||
$this->_em->flush();
|
||||
|
||||
self::assertQueryCountByType('UPDATE', 2);
|
||||
}
|
||||
|
||||
/** @return list<array{SupportedCacheUsage}> */
|
||||
public static function cacheUsageProvider(): array
|
||||
{
|
||||
return [
|
||||
[0],
|
||||
[ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE],
|
||||
[ClassMetadata::CACHE_USAGE_READ_WRITE],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools\Console\Command;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
|
||||
use Doctrine\ORM\Tools\Console\Command\ClearCache\CollectionRegionCommand;
|
||||
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
|
||||
use Doctrine\Tests\Models\Cache\State;
|
||||
@@ -14,6 +15,8 @@ use Symfony\Component\Console\Tester\CommandTester;
|
||||
/** @group DDC-2183 */
|
||||
class ClearCacheCollectionRegionCommandTest extends OrmFunctionalTestCase
|
||||
{
|
||||
use ApplicationCompatibility;
|
||||
|
||||
/** @var Application */
|
||||
private $application;
|
||||
|
||||
@@ -29,7 +32,7 @@ class ClearCacheCollectionRegionCommandTest extends OrmFunctionalTestCase
|
||||
$this->command = new CollectionRegionCommand(new SingleManagerProvider($this->_em));
|
||||
|
||||
$this->application = new Application();
|
||||
$this->application->add($this->command);
|
||||
self::addCommandToApplication($this->application, $this->command);
|
||||
}
|
||||
|
||||
public function testClearAllRegion(): void
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools\Console\Command;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
|
||||
use Doctrine\ORM\Tools\Console\Command\ClearCache\EntityRegionCommand;
|
||||
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
|
||||
use Doctrine\Tests\Models\Cache\Country;
|
||||
@@ -17,6 +18,8 @@ use function trim;
|
||||
/** @group DDC-2183 */
|
||||
class ClearCacheEntityRegionCommandTest extends OrmFunctionalTestCase
|
||||
{
|
||||
use ApplicationCompatibility;
|
||||
|
||||
/** @var Application */
|
||||
private $application;
|
||||
|
||||
@@ -32,7 +35,7 @@ class ClearCacheEntityRegionCommandTest extends OrmFunctionalTestCase
|
||||
$this->command = new EntityRegionCommand(new SingleManagerProvider($this->_em));
|
||||
|
||||
$this->application = new Application();
|
||||
$this->application->add($this->command);
|
||||
self::addCommandToApplication($this->application, $this->command);
|
||||
}
|
||||
|
||||
public function testClearAllRegion(): void
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools\Console\Command;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
|
||||
use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryRegionCommand;
|
||||
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
@@ -13,6 +14,8 @@ use Symfony\Component\Console\Tester\CommandTester;
|
||||
/** @group DDC-2183 */
|
||||
class ClearCacheQueryRegionCommandTest extends OrmFunctionalTestCase
|
||||
{
|
||||
use ApplicationCompatibility;
|
||||
|
||||
/** @var Application */
|
||||
private $application;
|
||||
|
||||
@@ -28,7 +31,7 @@ class ClearCacheQueryRegionCommandTest extends OrmFunctionalTestCase
|
||||
$this->command = new QueryRegionCommand(new SingleManagerProvider($this->_em));
|
||||
|
||||
$this->application = new Application();
|
||||
$this->application->add($this->command);
|
||||
self::addCommandToApplication($this->application, $this->command);
|
||||
}
|
||||
|
||||
public function testClearAllRegion(): void
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Doctrine\Tests\ORM\Tools\Console\Command;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\ORM\Configuration;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
|
||||
use Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand;
|
||||
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
|
||||
use Doctrine\Tests\DoctrineTestCase;
|
||||
@@ -18,6 +19,8 @@ use function array_merge;
|
||||
|
||||
class EnsureProductionSettingsCommandTest extends DoctrineTestCase
|
||||
{
|
||||
use ApplicationCompatibility;
|
||||
|
||||
public function testExecute(): void
|
||||
{
|
||||
$em = $this->createMock(EntityManagerInterface::class);
|
||||
@@ -103,7 +106,7 @@ class EnsureProductionSettingsCommandTest extends DoctrineTestCase
|
||||
array $input = []
|
||||
): int {
|
||||
$application = new Application();
|
||||
$application->add(new EnsureProductionSettingsCommand(new SingleManagerProvider($em)));
|
||||
self::addCommandToApplication($application, new EnsureProductionSettingsCommand(new SingleManagerProvider($em)));
|
||||
|
||||
$command = $application->find('orm:ensure-production-settings');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Doctrine\Tests\ORM\Tools\Console\Command;
|
||||
use Doctrine\ORM\Configuration;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
|
||||
use Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand;
|
||||
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
|
||||
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
|
||||
@@ -35,6 +36,8 @@ use const DIRECTORY_SEPARATOR;
|
||||
|
||||
class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase
|
||||
{
|
||||
use ApplicationCompatibility;
|
||||
|
||||
/** @var Application */
|
||||
private $application;
|
||||
|
||||
@@ -53,7 +56,7 @@ class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase
|
||||
$metadataDriver->addPaths([__DIR__ . '/../../../../Models/DDC3231/']);
|
||||
|
||||
$this->application = new Application();
|
||||
$this->application->add(new GenerateRepositoriesCommand(new SingleManagerProvider($this->_em)));
|
||||
self::addCommandToApplication($this->application, new GenerateRepositoriesCommand(new SingleManagerProvider($this->_em)));
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
@@ -163,7 +166,7 @@ class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase
|
||||
|
||||
$application = new Application();
|
||||
$application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($em)]));
|
||||
$application->add(new GenerateRepositoriesCommand());
|
||||
self::addCommandToApplication($application, new GenerateRepositoriesCommand());
|
||||
|
||||
$command = $application->find('orm:generate-repositories');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Doctrine\Tests\ORM\Tools\Console\Command;
|
||||
use Doctrine\ORM\Configuration;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Mapping\MappingException;
|
||||
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
|
||||
use Doctrine\ORM\Tools\Console\Command\InfoCommand;
|
||||
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
|
||||
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
|
||||
@@ -20,6 +21,8 @@ use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class InfoCommandTest extends OrmFunctionalTestCase
|
||||
{
|
||||
use ApplicationCompatibility;
|
||||
|
||||
/** @var Application */
|
||||
private $application;
|
||||
|
||||
@@ -35,7 +38,7 @@ class InfoCommandTest extends OrmFunctionalTestCase
|
||||
|
||||
$this->application = new Application();
|
||||
|
||||
$this->application->add(new InfoCommand(new SingleManagerProvider($this->_em)));
|
||||
self::addCommandToApplication($this->application, new InfoCommand(new SingleManagerProvider($this->_em)));
|
||||
|
||||
$this->command = $this->application->find('orm:info');
|
||||
$this->tester = new CommandTester($this->command);
|
||||
@@ -66,7 +69,7 @@ class InfoCommandTest extends OrmFunctionalTestCase
|
||||
|
||||
$application = new Application();
|
||||
$application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($em)]));
|
||||
$application->add(new InfoCommand());
|
||||
self::addCommandToApplication($application, new InfoCommand());
|
||||
|
||||
$command = $application->find('orm:info');
|
||||
$tester = new CommandTester($command);
|
||||
@@ -105,7 +108,7 @@ class InfoCommandTest extends OrmFunctionalTestCase
|
||||
|
||||
$application = new Application();
|
||||
$application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($em)]));
|
||||
$application->add(new InfoCommand());
|
||||
self::addCommandToApplication($application, new InfoCommand());
|
||||
|
||||
$command = $application->find('orm:info');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools\Console\Command;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
|
||||
use Doctrine\ORM\Tools\Console\Command\MappingDescribeCommand;
|
||||
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
|
||||
use Doctrine\Tests\Models\Cache\AttractionInfo;
|
||||
@@ -18,6 +19,8 @@ use Symfony\Component\Console\Tester\CommandTester;
|
||||
*/
|
||||
class MappingDescribeCommandTest extends OrmFunctionalTestCase
|
||||
{
|
||||
use ApplicationCompatibility;
|
||||
|
||||
/** @var Application */
|
||||
private $application;
|
||||
|
||||
@@ -32,7 +35,7 @@ class MappingDescribeCommandTest extends OrmFunctionalTestCase
|
||||
parent::setUp();
|
||||
|
||||
$this->application = new Application();
|
||||
$this->application->add(new MappingDescribeCommand(new SingleManagerProvider($this->_em)));
|
||||
self::addCommandToApplication($this->application, new MappingDescribeCommand(new SingleManagerProvider($this->_em)));
|
||||
|
||||
$this->command = $this->application->find('orm:mapping:describe');
|
||||
$this->tester = new CommandTester($this->command);
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools\Console\Command;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
|
||||
use Doctrine\ORM\Tools\Console\Command\RunDqlCommand;
|
||||
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
|
||||
use Doctrine\Tests\Models\Generic\DateTimeModel;
|
||||
@@ -20,6 +21,8 @@ use function trim;
|
||||
*/
|
||||
class RunDqlCommandTest extends OrmFunctionalTestCase
|
||||
{
|
||||
use ApplicationCompatibility;
|
||||
|
||||
/** @var Application */
|
||||
private $application;
|
||||
|
||||
@@ -38,7 +41,7 @@ class RunDqlCommandTest extends OrmFunctionalTestCase
|
||||
$this->command = new RunDqlCommand(new SingleManagerProvider($this->_em));
|
||||
|
||||
$this->application = new Application();
|
||||
$this->application->add($this->command);
|
||||
self::addCommandToApplication($this->application, $this->command);
|
||||
|
||||
$this->tester = new CommandTester($this->command);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Doctrine\Tests\ORM\Tools\Console\Command;
|
||||
|
||||
use Doctrine\DBAL\Platforms\SqlitePlatform;
|
||||
use Doctrine\ORM\Tools\Console\ApplicationCompatibility;
|
||||
use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand;
|
||||
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
@@ -19,6 +20,8 @@ use Symfony\Component\Console\Tester\CommandTester;
|
||||
*/
|
||||
class ValidateSchemaCommandTest extends OrmFunctionalTestCase
|
||||
{
|
||||
use ApplicationCompatibility;
|
||||
|
||||
/** @var ValidateSchemaCommand */
|
||||
private $command;
|
||||
|
||||
@@ -34,7 +37,7 @@ class ValidateSchemaCommandTest extends OrmFunctionalTestCase
|
||||
}
|
||||
|
||||
$application = new Application();
|
||||
$application->add(new ValidateSchemaCommand(new SingleManagerProvider($this->_em)));
|
||||
self::addCommandToApplication($application, new ValidateSchemaCommand(new SingleManagerProvider($this->_em)));
|
||||
|
||||
$this->command = $application->find('orm:validate-schema');
|
||||
$this->tester = new CommandTester($this->command);
|
||||
|
||||
Reference in New Issue
Block a user