Skip to content

Commit 57bb60e

Browse files
Merge branch 'hotfix/with-alias-function' into main
2 parents cebf74c + 8e6edfc commit 57bb60e

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

src/SharedQueryBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function withAlias(string $entity, string $property): string
141141
}
142142
$property = \ltrim($property, '.');
143143

144-
return \sprintf('%s.%s', $entity, $property);
144+
return \sprintf('%s.%s', $entityAlias, $property);
145145
}
146146

147147
public function getEntityForAlias(string $alias): ?string
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
namespace Andante\Doctrine\ORM\Tests;
7+
8+
use Andante\Doctrine\ORM\Exception\LogicException;
9+
use Andante\Doctrine\ORM\Tests\Model\Employee;
10+
use Andante\Doctrine\ORM\Tests\Model\Organization;
11+
use Andante\Doctrine\ORM\Tests\Model\Person;
12+
13+
class SharedQueryBuilderAliasesTest extends TestCase
14+
{
15+
public function testWithAlias(): void
16+
{
17+
$sqb = $this->createSqb();
18+
$sqb
19+
->from(Organization::class, 'o')
20+
->join(Person::class, 'p');
21+
self::assertSame('o.name', $sqb->withAlias(Organization::class, 'name'));
22+
self::assertSame('p.name', $sqb->withAlias(Person::class, 'name'));
23+
24+
$this->expectException(LogicException::class);
25+
$sqb->withAlias(Employee::class, 'name');
26+
}
27+
}

tests/SharedQueryBuilderParametersTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Doctrine\ORM\EntityManagerInterface;
1414
use Doctrine\ORM\Query;
1515
use Doctrine\ORM\QueryBuilder;
16-
use PHPStan\Testing\TestCase;
1716

1817
class SharedQueryBuilderParametersTest extends TestCase
1918
{
@@ -191,15 +190,6 @@ public function testInvalidParameterNameTypeThrowsException(): void
191190
$sqb->setParameter(new \stdClass(), 1);
192191
}
193192

194-
private function createSqb(): SharedQueryBuilder
195-
{
196-
return new SharedQueryBuilder(
197-
new QueryBuilder(
198-
$this->createStub(EntityManagerInterface::class)
199-
)
200-
);
201-
}
202-
203193
/**
204194
* @param array<string|int, mixed> $expected
205195
* @param ArrayCollection<int, Query\Parameter> $parameters

tests/TestCase.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
namespace Andante\Doctrine\ORM\Tests;
7+
8+
use Andante\Doctrine\ORM\SharedQueryBuilder;
9+
use Doctrine\ORM\EntityManagerInterface;
10+
use Doctrine\ORM\QueryBuilder;
11+
12+
class TestCase extends \PHPUnit\Framework\TestCase
13+
{
14+
protected function createSqb(): SharedQueryBuilder
15+
{
16+
return new SharedQueryBuilder(
17+
new QueryBuilder(
18+
$this->createStub(EntityManagerInterface::class)
19+
)
20+
);
21+
}
22+
}

0 commit comments

Comments
 (0)