Skip to content

Commit c24b677

Browse files
committed
Merge branch '2.3'
2 parents d5c9d0b + 77da03e commit c24b677

File tree

9 files changed

+96
-10
lines changed

9 files changed

+96
-10
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ jobs:
183183
mkdir -p build/logs/tmp build/cov
184184
for f in $(find features -name '*.feature' -not -path 'features/main/exposed_state.feature' | circleci tests split --split-by=timings); do
185185
_f=${f//\//_}
186-
FEATURE="${_f}" phpdbg -qrr vendor/bin/behat --profile=coverage --suite=default --tags=~@postgres --format=progress --out=std --format=junit --out=build/logs/tmp/"${_f}" "$f"
186+
FEATURE="${_f}" phpdbg -qrr vendor/bin/behat --profile=coverage --suite=default --format=progress --out=std --format=junit --out=build/logs/tmp/"${_f}" "$f"
187187
done
188188
- run:
189189
name: Merge Behat test reports

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ script:
5252
vendor/bin/behat --suite=default --format=progress;
5353
fi
5454
- tests/Fixtures/app/console api:swagger:export > swagger.json && npx swagger-cli validate swagger.json && rm swagger.json
55-
- tests/Fixtures/app/console api:swagger:export --yaml > swagger.yaml && npx swagger-cli validate --no-schema swagger.yaml && rm swagger.yaml
55+
- tests/Fixtures/app/console api:swagger:export --yaml > swagger.yaml && npx swagger-cli validate swagger.yaml && rm swagger.yaml

src/Bridge/Doctrine/Orm/Util/QueryChecker.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static function hasOrderByOnToManyJoin(QueryBuilder $queryBuilder, Manage
9595

9696
$orderByAliases = [];
9797
foreach ($orderByParts as $orderBy) {
98-
$parts = QueryJoinParser::getOrderByParts($orderBy);
98+
$parts = $orderBy->getParts();
9999

100100
foreach ($parts as $part) {
101101
$pos = strpos($part, '.');
@@ -111,12 +111,12 @@ public static function hasOrderByOnToManyJoin(QueryBuilder $queryBuilder, Manage
111111

112112
foreach ($joinParts as $joins) {
113113
foreach ($joins as $join) {
114-
$alias = QueryJoinParser::getJoinAlias($join);
114+
$alias = $join->getAlias();
115115

116116
if (!isset($orderByAliases[$alias])) {
117117
continue;
118118
}
119-
$relationship = QueryJoinParser::getJoinRelationship($join);
119+
$relationship = $join->getJoin();
120120

121121
if (false !== strpos($relationship, '.')) {
122122
/*

src/Bridge/Doctrine/Orm/Util/QueryJoinParser.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public static function getClassMetadataFromJoinAlias(string $alias, QueryBuilder
4848
$aliasMap[$rootAlias] = 'root';
4949

5050
foreach ($joins as $join) {
51-
$alias = self::getJoinAlias($join);
52-
$relationship = self::getJoinRelationship($join);
51+
$alias = $join->getAlias();
52+
$relationship = $join->getJoin();
5353

5454
$pos = strpos($relationship, '.');
5555

@@ -100,6 +100,8 @@ public static function getClassMetadataFromJoinAlias(string $alias, QueryBuilder
100100
*/
101101
public static function getJoinRelationship(Join $join): string
102102
{
103+
@trigger_error(sprintf('The use of "%s::getJoinRelationship()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getJoin()" directly instead.', __CLASS__, Join::class), E_USER_DEPRECATED);
104+
103105
return $join->getJoin();
104106
}
105107

@@ -108,17 +110,20 @@ public static function getJoinRelationship(Join $join): string
108110
*/
109111
public static function getJoinAlias(Join $join): string
110112
{
113+
@trigger_error(sprintf('The use of "%s::getJoinAlias()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getAlias()" directly instead.', __CLASS__, Join::class), E_USER_DEPRECATED);
114+
111115
return $join->getAlias();
112116
}
113117

114118
/**
115119
* Gets the parts from an OrderBy expression.
116120
*
117-
*
118121
* @return string[]
119122
*/
120123
public static function getOrderByParts(OrderBy $orderBy): array
121124
{
125+
@trigger_error(sprintf('The use of "%s::getOrderByParts()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getParts()" directly instead.', __CLASS__, OrderBy::class), E_USER_DEPRECATED);
126+
122127
return $orderBy->getParts();
123128
}
124129
}

src/Operation/Factory/SubresourceOperationFactory.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,14 @@ private function computeSubresourceOperations(string $resourceClass, array &$tre
127127
$operation['operation_name']
128128
);
129129

130+
$prefix = trim(trim($rootResourceMetadata->getAttribute('route_prefix', '')), '/');
131+
if ('' !== $prefix) {
132+
$prefix .= '/';
133+
}
134+
130135
$operation['path'] = $subresourceOperation['path'] ?? sprintf(
131-
'/%s/{id}/%s%s',
136+
'/%s%s/{id}/%s%s',
137+
$prefix,
132138
$this->pathSegmentNameGenerator->getSegmentName($rootShortname, true),
133139
$this->pathSegmentNameGenerator->getSegmentName($operation['property'], $operation['collection']),
134140
self::FORMAT_SUFFIX

tests/Bridge/Doctrine/Orm/Util/QueryJoinParserTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,50 @@ public function testGetClassMetadataFromJoinAlias()
4343
$this->assertEquals($metadata, $classMetadata->reveal());
4444
}
4545

46+
/**
47+
* @group legacy
48+
* @expectedDeprecation The use of "ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryJoinParser::getJoinRelationship()" is deprecated since 2.3 and will be removed in 3.0. Use "Doctrine\ORM\Query\Expr\Join::getJoin()" directly instead.
49+
*/
4650
public function testGetJoinRelationshipWithJoin()
4751
{
4852
$join = new Join('INNER_JOIN', 'a_1.relatedDummy', 'a_1', null, 'a_1.name = r.name');
4953
$this->assertEquals('a_1.relatedDummy', QueryJoinParser::getJoinRelationship($join));
5054
}
5155

56+
/**
57+
* @group legacy
58+
* @expectedDeprecation The use of "ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryJoinParser::getJoinRelationship()" is deprecated since 2.3 and will be removed in 3.0. Use "Doctrine\ORM\Query\Expr\Join::getJoin()" directly instead.
59+
*/
5260
public function testGetJoinRelationshipWithClassJoin()
5361
{
5462
$join = new Join('INNER_JOIN', RelatedDummy::class, 'a_1', null, 'a_1.name = r.name');
5563
$this->assertEquals(RelatedDummy::class, QueryJoinParser::getJoinRelationship($join));
5664
}
5765

66+
/**
67+
* @group legacy
68+
* @expectedDeprecation The use of "ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryJoinParser::getJoinAlias()" is deprecated since 2.3 and will be removed in 3.0. Use "Doctrine\ORM\Query\Expr\Join::getAlias()" directly instead.
69+
*/
5870
public function testGetJoinAliasWithJoin()
5971
{
6072
$join = new Join('INNER_JOIN', 'relatedDummy', 'a_1', null, 'a_1.name = r.name');
6173
$this->assertEquals('a_1', QueryJoinParser::getJoinAlias($join));
6274
}
6375

76+
/**
77+
* @group legacy
78+
* @expectedDeprecation The use of "ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryJoinParser::getJoinAlias()" is deprecated since 2.3 and will be removed in 3.0. Use "Doctrine\ORM\Query\Expr\Join::getAlias()" directly instead.
79+
*/
6480
public function testGetJoinAliasWithClassJoin()
6581
{
6682
$join = new Join('LEFT_JOIN', RelatedDummy::class, 'a_1', null, 'a_1.name = r.name');
6783
$this->assertEquals('a_1', QueryJoinParser::getJoinAlias($join));
6884
}
6985

86+
/**
87+
* @group legacy
88+
* @expectedDeprecation The use of "ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryJoinParser::getOrderByParts()" is deprecated since 2.3 and will be removed in 3.0. Use "Doctrine\ORM\Query\Expr\OrderBy::getParts()" directly instead.
89+
*/
7090
public function testGetOrderByPartsWithOrderBy()
7191
{
7292
$orderBy = new OrderBy('name', 'asc');

tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,16 @@ public function testExecuteWithYaml()
6262
operationId: getDummyCarCollection
6363
YAML;
6464

65-
$this->assertContains($expected, $result);
65+
$this->assertContains($expected, $result, 'nested object should be present.');
66+
67+
$expected = <<<YAML
68+
'/dummy_cars/{id}':
69+
get:
70+
tags: []
71+
operationId: getDummyCarItem
72+
YAML;
73+
74+
$this->assertContains($expected, $result, 'arrays should be correctly formatted.');
6675
}
6776

6877
public function testWriteToFile()

tests/Fixtures/TestBundle/Entity/DummyCar.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
/**
2828
* @ApiResource(
29+
* itemOperations={"get"={"swagger_context"={"tags"={}}}, "put", "delete"},
2930
* attributes={
3031
* "normalization_context"={"groups"={"colors"}},
3132
* "sunset"="2050-01-01"

tests/Operation/Factory/SubresourceOperationFactoryTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,4 +607,49 @@ public function testCreateWithEndButNoCollection()
607607
] + SubresourceOperationFactory::ROUTE_OPTIONS,
608608
], $result);
609609
}
610+
611+
public function testCreateWithRootResourcePrefix()
612+
{
613+
$resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);
614+
$resourceMetadataFactoryProphecy->create(RelatedDummyEntity::class)->shouldBeCalled()->willReturn(new ResourceMetadata('relatedDummyEntity'));
615+
$resourceMetadataFactoryProphecy->create(DummyEntity::class)->shouldBeCalled()->willReturn(new ResourceMetadata('dummyEntity', null, null, null, null, ['route_prefix' => 'root_resource_prefix']));
616+
617+
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
618+
$propertyNameCollectionFactoryProphecy->create(DummyEntity::class)->shouldBeCalled()->willReturn(new PropertyNameCollection(['subresource']));
619+
$propertyNameCollectionFactoryProphecy->create(RelatedDummyEntity::class)->shouldBeCalled()->willReturn(new PropertyNameCollection(['bar', 'anotherSubresource']));
620+
621+
$subresourceMetadataCollectionWithMaxDepth = (new PropertyMetadata())->withSubresource(new SubresourceMetadata(RelatedDummyEntity::class, false, 1));
622+
$anotherSubresourceMetadata = (new PropertyMetadata())->withSubresource(new SubresourceMetadata(DummyEntity::class, false));
623+
624+
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
625+
$propertyMetadataFactoryProphecy->create(DummyEntity::class, 'subresource')->shouldBeCalled()->willReturn($subresourceMetadataCollectionWithMaxDepth);
626+
$propertyMetadataFactoryProphecy->create(RelatedDummyEntity::class, 'bar')->shouldBeCalled()->willReturn(new PropertyMetadata());
627+
$propertyMetadataFactoryProphecy->create(RelatedDummyEntity::class, 'anotherSubresource')->shouldBeCalled()->willReturn($anotherSubresourceMetadata);
628+
629+
$pathSegmentNameGeneratorProphecy = $this->prophesize(PathSegmentNameGeneratorInterface::class);
630+
$pathSegmentNameGeneratorProphecy->getSegmentName('dummyEntity', true)->shouldBeCalled()->willReturn('dummy_entities');
631+
$pathSegmentNameGeneratorProphecy->getSegmentName('subresource', false)->shouldBeCalled()->willReturn('subresource');
632+
633+
$subresourceOperationFactory = new SubresourceOperationFactory(
634+
$resourceMetadataFactoryProphecy->reveal(),
635+
$propertyNameCollectionFactoryProphecy->reveal(),
636+
$propertyMetadataFactoryProphecy->reveal(),
637+
$pathSegmentNameGeneratorProphecy->reveal()
638+
);
639+
640+
$this->assertEquals([
641+
'api_dummy_entities_subresource_get_subresource' => [
642+
'property' => 'subresource',
643+
'collection' => false,
644+
'resource_class' => RelatedDummyEntity::class,
645+
'shortNames' => ['relatedDummyEntity', 'dummyEntity'],
646+
'identifiers' => [
647+
['id', DummyEntity::class, true],
648+
],
649+
'route_name' => 'api_dummy_entities_subresource_get_subresource',
650+
'path' => '/root_resource_prefix/dummy_entities/{id}/subresource.{_format}',
651+
'operation_name' => 'subresource_get_subresource',
652+
] + SubresourceOperationFactory::ROUTE_OPTIONS,
653+
], $subresourceOperationFactory->create(DummyEntity::class));
654+
}
610655
}

0 commit comments

Comments
 (0)