Skip to content

Commit cc8e6d1

Browse files
committed
Merge branch 2.7 into 3.0
2 parents 67f9f7f + 6842ce6 commit cc8e6d1

File tree

6 files changed

+53
-4
lines changed

6 files changed

+53
-4
lines changed

features/main/relation.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,4 +547,3 @@ Feature: Relations support
547547
"hydra:totalItems": 1
548548
}
549549
"""
550-

src/Metadata/Extractor/ResourceExtractorTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private function phpize(\SimpleXMLElement|array|null $resource, string $key, str
5555

5656
switch ($type) {
5757
case 'bool|string':
58-
return \in_array((string) $resource[$key], ['1', '0', 'true', 'false'], true) ? $this->phpize($resource, $key, 'bool') : $this->phpize($resource, $key, 'string');
58+
return \is_bool($resource[$key]) || \in_array((string) $resource[$key], ['1', '0', 'true', 'false'], true) ? $this->phpize($resource, $key, 'bool') : $this->phpize($resource, $key, 'string');
5959
case 'string':
6060
return (string) $resource[$key];
6161
case 'integer':

src/Metadata/Extractor/YamlResourceExtractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ private function buildBase(array $resource): array
149149
'securityPostDenormalizeMessage' => $this->phpize($resource, 'securityPostDenormalizeMessage', 'string'),
150150
'securityPostValidation' => $this->phpize($resource, 'securityPostValidation', 'string'),
151151
'securityPostValidationMessage' => $this->phpize($resource, 'securityPostValidationMessage', 'string'),
152-
'input' => $this->phpize($resource, 'input', 'string'),
153-
'output' => $this->phpize($resource, 'output', 'string'),
152+
'input' => $this->phpize($resource, 'input', 'bool|string'),
153+
'output' => $this->phpize($resource, 'output', 'bool|string'),
154154
'normalizationContext' => $this->buildArrayValue($resource, 'normalizationContext'),
155155
'denormalizationContext' => $this->buildArrayValue($resource, 'denormalizationContext'),
156156
'validationContext' => $this->buildArrayValue($resource, 'validationContext'),

tests/Metadata/Extractor/YamlExtractorTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,40 @@ public function testValidYaml(): void
457457
], $extractor->getResources());
458458
}
459459

460+
public function testInputAndOutputAreBooleans(): void
461+
{
462+
$extractor = new YamlResourceExtractor([__DIR__.'/yaml/input-and-output-are-booleans.yaml']);
463+
$resources = $extractor->getResources();
464+
465+
$this->assertArrayHasKey(Program::class, $resources);
466+
$this->assertArrayHasKey(0, $resources[Program::class]);
467+
$this->assertArrayHasKey('operations', $resources[Program::class][0]);
468+
$this->assertArrayHasKey('0', $resources[Program::class][0]['operations']);
469+
470+
$this->assertArrayHasKey('input', $resources[Program::class][0]['operations'][0]);
471+
$this->assertFalse($resources[Program::class][0]['operations'][0]['input']);
472+
473+
$this->assertArrayHasKey('output', $resources[Program::class][0]['operations'][0]);
474+
$this->assertFalse($resources[Program::class][0]['operations'][0]['output']);
475+
}
476+
477+
public function testInputAndOutputAreStrings(): void
478+
{
479+
$extractor = new YamlResourceExtractor([__DIR__.'/yaml/input-and-output-are-strings.yaml']);
480+
$resources = $extractor->getResources();
481+
482+
$this->assertArrayHasKey(Program::class, $resources);
483+
$this->assertArrayHasKey(0, $resources[Program::class]);
484+
$this->assertArrayHasKey('operations', $resources[Program::class][0]);
485+
$this->assertArrayHasKey('0', $resources[Program::class][0]['operations']);
486+
487+
$this->assertArrayHasKey('input', $resources[Program::class][0]['operations'][0]);
488+
$this->assertSame(Program::class.'Input', $resources[Program::class][0]['operations'][0]['input']);
489+
490+
$this->assertArrayHasKey('output', $resources[Program::class][0]['operations'][0]);
491+
$this->assertSame(Program::class.'Output', $resources[Program::class][0]['operations'][0]['output']);
492+
}
493+
460494
/**
461495
* @dataProvider getInvalidPaths
462496
*/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resources:
2+
ApiPlatform\Tests\Fixtures\TestBundle\Entity\Program:
3+
- uriTemplate: /users/{author}/programs.{_format}
4+
uriVariables: ['author']
5+
operations:
6+
ApiPlatform\Metadata\Post:
7+
input: false
8+
output: false
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resources:
2+
ApiPlatform\Tests\Fixtures\TestBundle\Entity\Program:
3+
- uriTemplate: /users/{author}/programs.{_format}
4+
uriVariables: ['author']
5+
operations:
6+
ApiPlatform\Metadata\Post:
7+
input: ApiPlatform\Tests\Fixtures\TestBundle\Entity\ProgramInput
8+
output: ApiPlatform\Tests\Fixtures\TestBundle\Entity\ProgramOutput

0 commit comments

Comments
 (0)