Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use Doctrine\ORM\Repository\Exception\InvalidMagicMethodCall;
use Doctrine\Persistence\ObjectRepository;
Expand Down Expand Up @@ -185,6 +186,11 @@ protected function getEntityManager(): EntityManagerInterface
return $this->em;
}

final protected function expr(): Expr
{
return $this->em->getExpressionBuilder();
}

/** @phpstan-return ClassMetadata<T> */
protected function getClassMetadata(): ClassMetadata
{
Expand Down
35 changes: 35 additions & 0 deletions tests/Tests/ORM/EntityRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query\Expr;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(EntityRepository::class)]
class EntityRepositoryTest extends TestCase
{
public function testExpr(): void
{
$expr = static::createStub(Expr::class);

$em = static::createStub(EntityManagerInterface::class);
$em->method('getExpressionBuilder')->willReturn($expr);

$metadata = new ClassMetadata('foo');

$repository = new class ($em, $metadata) extends EntityRepository {
public function testExpr(): void
{
TestCase::assertSame($this->getEntityManager()->getExpressionBuilder(), $this->expr());
}
};

$repository->testExpr();
}
}
Loading