File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212use Doctrine \Inflector \Inflector ;
1313use Doctrine \Inflector \InflectorFactory ;
1414use Doctrine \ORM \Mapping \ClassMetadata ;
15+ use Doctrine \ORM \Query \Expr ;
1516use Doctrine \ORM \Query \ResultSetMappingBuilder ;
1617use Doctrine \ORM \Repository \Exception \InvalidMagicMethodCall ;
1718use Doctrine \Persistence \ObjectRepository ;
@@ -185,6 +186,11 @@ protected function getEntityManager(): EntityManagerInterface
185186 return $ this ->em ;
186187 }
187188
189+ final protected function expr (): Expr
190+ {
191+ return $ this ->em ->getExpressionBuilder ();
192+ }
193+
188194 /** @phpstan-return ClassMetadata<T> */
189195 protected function getClassMetadata (): ClassMetadata
190196 {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Doctrine \Tests \ORM ;
6+
7+ use Doctrine \ORM \EntityManagerInterface ;
8+ use Doctrine \ORM \EntityRepository ;
9+ use Doctrine \ORM \Mapping \ClassMetadata ;
10+ use Doctrine \ORM \Query \Expr ;
11+ use PHPUnit \Framework \Attributes \CoversClass ;
12+ use PHPUnit \Framework \TestCase ;
13+
14+ #[CoversClass(EntityRepository::class)]
15+ class EntityRepositoryTest extends TestCase
16+ {
17+ public function testExpr (): void
18+ {
19+ $ expr = static ::createStub (Expr::class);
20+
21+ $ em = static ::createStub (EntityManagerInterface::class);
22+ $ em ->method ('getExpressionBuilder ' )->willReturn ($ expr );
23+
24+ $ metadata = new ClassMetadata ('foo ' );
25+
26+ $ repository = new class ($ em , $ metadata ) extends EntityRepository {
27+ public function testExpr (): void
28+ {
29+ TestCase::assertSame ($ this ->getEntityManager ()->getExpressionBuilder (), $ this ->expr ());
30+ }
31+ };
32+
33+ $ repository ->testExpr ();
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments