Skip to content

Commit 0e1af77

Browse files
author
abluchet
committed
fix #1153
1 parent 4275dc9 commit 0e1af77

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

src/Bridge/Doctrine/Orm/Filter/AbstractFilter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ protected function splitPropertyParts(string $property/*, string $resourceClass*
233233
@trigger_error(sprintf('Method %s() will have a second `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.', __FUNCTION__), E_USER_DEPRECATED);
234234
}
235235
}
236+
}
236237

238+
if (!isset($resourceClass)) {
237239
return [
238240
'associations' => array_slice($parts, 0, -1),
239241
'field' => end($parts),
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\Tests\Bridge\Doctrine\Orm\Filter;
15+
16+
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Doctrine\Orm\Filter\DummyFilter;
17+
use Doctrine\Common\Persistence\ManagerRegistry;
18+
use Symfony\Component\HttpFoundation\RequestStack;
19+
20+
/**
21+
* Regression test case on issue 1154.
22+
*
23+
* @author Antoine Bluchet <[email protected]>
24+
*/
25+
class AbstractFilterTest extends \PHPUnit_Framework_TestCase
26+
{
27+
public function testSplitPropertiesWithoutResourceClass()
28+
{
29+
$managerRegistry = $this->prophesize(ManagerRegistry::class);
30+
$requestStack = $this->prophesize(RequestStack::class);
31+
32+
$filter = new DummyFilter($managerRegistry->reveal(), $requestStack->reveal());
33+
34+
$this->assertEquals($filter->doSplitPropertiesWithoutResourceClass('foo.bar'), [
35+
'associations' => ['foo'],
36+
'field' => 'bar',
37+
]);
38+
}
39+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Doctrine\Orm\Filter;
15+
16+
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractFilter;
17+
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
18+
use Doctrine\ORM\QueryBuilder;
19+
20+
class DummyFilter extends AbstractFilter
21+
{
22+
public function doSplitPropertiesWithoutResourceClass($property)
23+
{
24+
return $this->splitPropertyParts($property);
25+
}
26+
27+
protected function filterProperty(string $property, $values, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null)
28+
{
29+
}
30+
31+
public function getDescription(string $resourceClass): array
32+
{
33+
return [];
34+
}
35+
}

0 commit comments

Comments
 (0)