Merge commit '8b2854393' into 2.15.x

This commit is contained in:
Grégoire Paris
2023-01-23 19:20:22 +01:00
6 changed files with 83 additions and 36 deletions

View File

@@ -79,7 +79,10 @@ EOT
$saveMode = ! $input->getOption('complete');
if ($saveMode) {
$notificationUi->warning('Not passing the "--complete" option to "orm:schema-tool:update" is deprecated and will not be supported when using doctrine/dbal 4');
$notificationUi->warning(sprintf(
'Not passing the "--complete" option to "%s" is deprecated and will not be supported when using doctrine/dbal 4',
$this->getName() ?? $this->name
));
}
$sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode);

View File

@@ -162,7 +162,7 @@ class Paginator implements Countable, IteratorAggregate
$whereInQuery->setFirstResult(0)->setMaxResults(null);
$whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, $ids);
$whereInQuery->setCacheable($this->query->isCacheable());
$whereInQuery->expireQueryCache();
$whereInQuery->useQueryCache(false);
$result = $whereInQuery->getResult($this->query->getHydrationMode());
} else {

View File

@@ -77,8 +77,8 @@ class OneToOneBidirectionalAssociationTest extends OrmFunctionalTestCase
public function testLazyLoadsObjectsOnTheOwningSide(): void
{
$this->createFixture();
$metadata = $this->_em->getClassMetadata(ECommerceCart::class);
$metadata->associationMappings['customer']['fetchMode'] = ClassMetadata::FETCH_LAZY;
$metadata = $this->_em->getClassMetadata(ECommerceCart::class);
$metadata->associationMappings['customer']['fetch'] = ClassMetadata::FETCH_LAZY;
$query = $this->_em->createQuery('select c from Doctrine\Tests\Models\ECommerce\ECommerceCart c');
$result = $query->getResult();

View File

@@ -13,6 +13,9 @@ use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Assert;
use Psr\Cache\CacheItemInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use function array_map;
use function is_string;
@@ -69,48 +72,56 @@ class GH7820Test extends OrmFunctionalTestCase
public function testWillFindSongsInPaginator(): void
{
$query = $this->_em->getRepository(GH7820Line::class)
->createQueryBuilder('l')
->orderBy('l.lineNumber', Criteria::ASC);
$lines = $this->fetchSongLinesWithPaginator();
self::assertSame(
self::SONG,
array_map(static function (GH7820Line $line): string {
return $line->toString();
}, iterator_to_array(new Paginator($query)))
);
self::assertSame(self::SONG, $lines);
}
/** @group GH7837 */
public function testWillFindSongsInPaginatorEvenWithCachedQueryParsing(): void
{
// Enable the query cache
$this->_em->getConfiguration()
->getQueryCache()
->clear();
// Fetch song lines with the paginator, also priming the query cache
$lines = $this->fetchSongLinesWithPaginator();
self::assertSame(self::SONG, $lines, 'Expected to return expected data before query cache is populated with DQL -> SQL translation. Were SQL parameters translated?');
// Fetch song lines again
$lines = $this->fetchSongLinesWithPaginator();
self::assertSame(self::SONG, $lines, 'Expected to return expected data even when DQL -> SQL translation is present in cache. Were SQL parameters translated again?');
}
public function testPaginatorDoesNotForceCacheToUpdateEntries(): void
{
$this->_em->getConfiguration()->setQueryCache(new class extends ArrayAdapter {
public function save(CacheItemInterface $item): bool
{
Assert::assertFalse($this->hasItem($item->getKey()), 'The cache should not have to overwrite the entry');
return parent::save($item);
}
});
// "Prime" the cache (in fact, that should not even happen)
$this->fetchSongLinesWithPaginator();
// Make sure we can query again without overwriting the cache
$this->fetchSongLinesWithPaginator();
}
private function fetchSongLinesWithPaginator(): array
{
$query = $this->_em->getRepository(GH7820Line::class)
->createQueryBuilder('l')
->orderBy('l.lineNumber', Criteria::ASC);
->orderBy('l.lineNumber', Criteria::ASC)
->setMaxResults(100);
self::assertSame(
self::SONG,
array_map(static function (GH7820Line $line): string {
return $line->toString();
}, iterator_to_array(new Paginator($query))),
'Expected to return expected data before query cache is populated with DQL -> SQL translation. Were SQL parameters translated?'
);
$query = $this->_em->getRepository(GH7820Line::class)
->createQueryBuilder('l')
->orderBy('l.lineNumber', Criteria::ASC);
self::assertSame(
self::SONG,
array_map(static function (GH7820Line $line): string {
return $line->toString();
}, iterator_to_array(new Paginator($query))),
'Expected to return expected data even when DQL -> SQL translation is present in cache. Were SQL parameters translated again?'
);
return array_map(static function (GH7820Line $line): string {
return $line->toString();
}, iterator_to_array(new Paginator($query)));
}
}

View File

@@ -14,7 +14,7 @@ use Symfony\Component\Console\Tester\CommandTester;
abstract class CommandTestCase extends OrmFunctionalTestCase
{
/** @param class-string<AbstractCommand> $commandClass */
protected function getCommandTester(string $commandClass): CommandTester
protected function getCommandTester(string $commandClass, ?string $commandName = null): CommandTester
{
$entityManager = $this->getEntityManager(null, ORMSetup::createDefaultAnnotationDriver([
__DIR__ . '/Models',
@@ -24,8 +24,14 @@ abstract class CommandTestCase extends OrmFunctionalTestCase
self::markTestSkipped('We are testing the symfony/console integration');
}
return new CommandTester(new $commandClass(
$command = new $commandClass(
new SingleManagerProvider($entityManager)
));
);
if ($commandName !== null) {
$command->setName($commandName);
}
return new CommandTester($command);
}
}

View File

@@ -19,4 +19,31 @@ class UpdateCommandTest extends CommandTestCase
self::$sharedConn->executeStatement($tester->getDisplay());
}
/**
* @dataProvider getCasesForWarningMessageFromCompleteOption
*/
public function testWarningMessageFromCompleteOption(?string $name, string $expectedMessage): void
{
$tester = $this->getCommandTester(UpdateCommand::class, $name);
$tester->execute(
[],
['capture_stderr_separately' => true]
);
self::assertStringContainsString($expectedMessage, $tester->getErrorOutput());
}
public function getCasesForWarningMessageFromCompleteOption(): iterable
{
yield 'default_name' => [
null,
'[WARNING] Not passing the "--complete" option to "orm:schema-tool:update" is deprecated',
];
yield 'custom_name' => [
'doctrine:schema:update',
'[WARNING] Not passing the "--complete" option to "doctrine:schema:update" is deprecated',
];
}
}