Skip to content

Commit 67c1121

Browse files
committed
Merge branch 2.7 into main
2 parents 92e82aa + ecce956 commit 67c1121

File tree

9 files changed

+39
-27
lines changed

9 files changed

+39
-27
lines changed

features/main/crud_uri_variables.feature

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,22 @@ Feature: Uri Variables
112112
{
113113
"@id": "/companies/2/employees/2",
114114
"@type": "Employee",
115-
"id": 2,
116115
"name": "foo2",
117-
"company": "/companies/2"
116+
"company": {
117+
"@id": "/companies/2",
118+
"@type": "Company",
119+
"name": "Foo Company 2"
120+
}
118121
},
119122
{
120123
"@id": "/companies/2/employees/3",
121124
"@type": "Employee",
122-
"id": 3,
123125
"name": "foo3",
124-
"company": "/companies/2"
126+
"company": {
127+
"@id": "/companies/2",
128+
"@type": "Company",
129+
"name": "Foo Company 2"
130+
}
125131
}
126132
],
127133
"hydra:totalItems": 2

src/JsonSchema/SchemaFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ private function getMetadata(string $className, string $type = Schema::TYPE_OUTP
297297
}
298298

299299
if (!$operation) {
300-
$operation = $op;
300+
$operation = new HttpOperation();
301301
}
302302
}
303303
}

tests/Api/QueryParameterValidator/QueryParameterValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testOnKernelRequestWithUnsafeMethod()
5858
}
5959

6060
/**
61-
* If the tested filter is non-existant, then nothing should append.
61+
* If the tested filter is non-existent, then nothing should append.
6262
*/
6363
public function testOnKernelRequestWithWrongFilter()
6464
{

tests/Fixtures/TestBundle/Document/Company.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515

1616
use ApiPlatform\Metadata\ApiResource;
1717
use ApiPlatform\Metadata\Get;
18+
use ApiPlatform\Metadata\GetCollection;
1819
use ApiPlatform\Metadata\Link;
1920
use ApiPlatform\Metadata\Post;
2021
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
22+
use Symfony\Component\Serializer\Annotation\Groups;
2123

2224
#[ApiResource]
25+
#[GetCollection]
2326
#[Get]
2427
#[Post]
2528
#[ApiResource(uriTemplate: '/employees/{employeeId}/rooms/{roomId}/company/{companyId}', uriVariables: ['employeeId' => ['from_class' => Employee::class, 'from_property' => 'company']])]
@@ -38,6 +41,7 @@ class Company
3841
* @var string The dummy name
3942
*/
4043
#[ODM\Field]
44+
#[Groups(['company_employees_read'])]
4145
public $name;
4246

4347
/** @var Employee[] */

tests/Fixtures/TestBundle/Document/Employee.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
use ApiPlatform\Metadata\GetCollection;
1919
use ApiPlatform\Metadata\Post;
2020
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
21+
use Symfony\Component\Serializer\Annotation\Groups;
2122

2223
#[ApiResource]
2324
#[Post]
2425
#[ApiResource(uriTemplate: '/companies/{companyId}/employees/{id}', uriVariables: ['companyId' => ['from_class' => Company::class, 'to_property' => 'company'], 'id' => ['from_class' => Employee::class]])]
2526
#[Get]
26-
#[ApiResource(uriTemplate: '/companies/{companyId}/employees', uriVariables: ['companyId' => ['from_class' => Company::class, 'to_property' => 'company']])]
27+
#[ApiResource(uriTemplate: '/companies/{companyId}/employees', uriVariables: ['companyId' => ['from_class' => Company::class, 'to_property' => 'company']], normalizationContext: ['groups' => ['company_employees_read']])]
2728
#[GetCollection]
2829
#[ODM\Document]
2930
class Employee
@@ -38,12 +39,14 @@ class Employee
3839
* @var string The dummy name
3940
*/
4041
#[ODM\Field]
42+
#[Groups(['company_employees_read'])]
4143
public $name;
4244

4345
/**
4446
* @var ?Company
4547
*/
4648
#[ODM\ReferenceOne(targetDocument: Company::class, storeAs: 'id')]
49+
#[Groups(['company_employees_read'])]
4750
public $company;
4851

4952
public function getId()

tests/Fixtures/TestBundle/Entity/Company.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515

1616
use ApiPlatform\Metadata\ApiResource;
1717
use ApiPlatform\Metadata\Get;
18+
use ApiPlatform\Metadata\GetCollection;
1819
use ApiPlatform\Metadata\Link;
1920
use ApiPlatform\Metadata\Post;
2021
use Doctrine\ORM\Mapping as ORM;
22+
use Symfony\Component\Serializer\Annotation\Groups;
2123

2224
#[ApiResource]
25+
#[GetCollection]
2326
#[Get]
2427
#[Post]
2528
#[ApiResource(
@@ -50,6 +53,7 @@ class Company
5053
* @var string The dummy name
5154
*/
5255
#[ORM\Column]
56+
#[Groups(['company_employees_read'])]
5357
public string $name;
5458

5559
/** @var Employee[] */

tests/Fixtures/TestBundle/Entity/Employee.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ApiPlatform\Metadata\GetCollection;
1919
use ApiPlatform\Metadata\Post;
2020
use Doctrine\ORM\Mapping as ORM;
21+
use Symfony\Component\Serializer\Annotation\Groups;
2122

2223
#[ApiResource]
2324
#[Post]
@@ -33,7 +34,8 @@
3334
uriTemplate: '/companies/{companyId}/employees',
3435
uriVariables: [
3536
'companyId' => ['from_class' => Company::class, 'to_property' => 'company'],
36-
]
37+
],
38+
normalizationContext: ['groups' => ['company_employees_read']]
3739
)]
3840
#[GetCollection]
3941
#[ORM\Entity]
@@ -51,9 +53,11 @@ class Employee
5153
* @var string The dummy name
5254
*/
5355
#[ORM\Column]
56+
#[Groups(['company_employees_read'])]
5457
public string $name;
5558

5659
#[ORM\ManyToOne(targetEntity: \ApiPlatform\Tests\Fixtures\TestBundle\Entity\Company::class)]
60+
#[Groups(['company_employees_read'])]
5761
public ?Company $company = null;
5862

5963
public function getId()

tests/JsonSchema/SchemaFactoryTest.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function testBuildSchemaForNonResourceClass(): void
9292
$this->assertSame('example_bar', $definitions[$rootDefinitionKey]['properties']['bar']['example']);
9393
}
9494

95-
public function testBuildSchemaForOperationWithOverriddenSerializerGroups(): void
95+
public function testBuildSchemaWithSerializerGroups(): void
9696
{
9797
$typeFactoryProphecy = $this->prophesize(TypeFactoryInterface::class);
9898
$typeFactoryProphecy->getType(Argument::allOf(
@@ -115,30 +115,20 @@ public function testBuildSchemaForOperationWithOverriddenSerializerGroups(): voi
115115
])
116116
);
117117

118-
$serializerGroup = 'overridden_operation_dummy_put';
119-
$validationGroups = 'validation_groups_dummy_put';
118+
$serializerGroup = 'custom_operation_dummy';
120119

121120
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
122-
$propertyNameCollectionFactoryProphecy->create(OverriddenOperationDummy::class, Argument::allOf(
123-
Argument::type('array'),
124-
Argument::allOf(Argument::withEntry('serializer_groups', [$serializerGroup]), Argument::withEntry('validation_groups', [$validationGroups]))
125-
))->willReturn(new PropertyNameCollection(['alias', 'description']));
121+
$propertyNameCollectionFactoryProphecy->create(OverriddenOperationDummy::class, Argument::type('array'))->willReturn(new PropertyNameCollection(['alias', 'description']));
126122

127123
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
128-
$propertyMetadataFactoryProphecy->create(OverriddenOperationDummy::class, 'alias', Argument::allOf(
129-
Argument::type('array'),
130-
Argument::allOf(Argument::withEntry('serializer_groups', [$serializerGroup]), Argument::withEntry('validation_groups', [$validationGroups]))
131-
))->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withReadable(true));
132-
$propertyMetadataFactoryProphecy->create(OverriddenOperationDummy::class, 'description', Argument::allOf(
133-
Argument::type('array'),
134-
Argument::allOf(Argument::withEntry('serializer_groups', [$serializerGroup]), Argument::withEntry('validation_groups', [$validationGroups]))
135-
))->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withReadable(true));
124+
$propertyMetadataFactoryProphecy->create(OverriddenOperationDummy::class, 'alias', Argument::type('array'))->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withReadable(true));
125+
$propertyMetadataFactoryProphecy->create(OverriddenOperationDummy::class, 'description', Argument::type('array'))->willReturn((new ApiProperty())->withBuiltinTypes([new Type(Type::BUILTIN_TYPE_STRING)])->withReadable(true));
136126

137127
$resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class);
138128
$resourceClassResolverProphecy->isResourceClass(OverriddenOperationDummy::class)->willReturn(true);
139129

140130
$schemaFactory = new SchemaFactory($typeFactoryProphecy->reveal(), $resourceMetadataFactoryProphecy->reveal(), $propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), null, $resourceClassResolverProphecy->reveal());
141-
$resultSchema = $schemaFactory->buildSchema(OverriddenOperationDummy::class, 'json', Schema::TYPE_OUTPUT);
131+
$resultSchema = $schemaFactory->buildSchema(OverriddenOperationDummy::class, 'json', Schema::TYPE_OUTPUT, null, null, ['groups' => $serializerGroup, AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false]);
142132

143133
$rootDefinitionKey = $resultSchema->getRootDefinitionKey();
144134
$definitions = $resultSchema->getDefinitions();

tests/Symfony/Bundle/DataCollector/RequestDataCollectorTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use ApiPlatform\Tests\ProphecyTrait;
2424
use PackageVersions\Versions;
2525
use PHPUnit\Framework\TestCase;
26-
use Prophecy\Argument;
2726
use Psr\Container\ContainerInterface;
2827
use Symfony\Component\HttpFoundation\ParameterBag;
2928
use Symfony\Component\HttpFoundation\Request;
@@ -135,7 +134,8 @@ public function testWithResourceWithTraceables()
135134
{
136135
$this->apiResourceClassWillReturn(DummyEntity::class);
137136

138-
$this->filterLocator->has(Argument::type('string'))->willReturn(false);
137+
$this->filterLocator->has('a_filter')->willReturn(false);
138+
$this->filterLocator->has('foo')->willReturn(false);
139139

140140
$dataCollector = new RequestDataCollector(
141141
$this->metadataFactory->reveal(),
@@ -152,7 +152,8 @@ public function testVersionCollection()
152152
{
153153
$this->apiResourceClassWillReturn(DummyEntity::class);
154154

155-
$this->filterLocator->has(Argument::type('string'))->willReturn(false);
155+
$this->filterLocator->has('a_filter')->willReturn(false);
156+
$this->filterLocator->has('foo')->willReturn(false);
156157

157158
$dataCollector = new RequestDataCollector(
158159
$this->metadataFactory->reveal(),

0 commit comments

Comments
 (0)