Skip to content

Commit

Permalink
Merge branch 2.7 into 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Nov 15, 2022
2 parents 67f9f7f + 6842ce6 commit cc8e6d1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
1 change: 0 additions & 1 deletion features/main/relation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -547,4 +547,3 @@ Feature: Relations support
"hydra:totalItems": 1
}
"""

2 changes: 1 addition & 1 deletion src/Metadata/Extractor/ResourceExtractorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private function phpize(\SimpleXMLElement|array|null $resource, string $key, str

switch ($type) {
case 'bool|string':
return \in_array((string) $resource[$key], ['1', '0', 'true', 'false'], true) ? $this->phpize($resource, $key, 'bool') : $this->phpize($resource, $key, 'string');
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');
case 'string':
return (string) $resource[$key];
case 'integer':
Expand Down
4 changes: 2 additions & 2 deletions src/Metadata/Extractor/YamlResourceExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ private function buildBase(array $resource): array
'securityPostDenormalizeMessage' => $this->phpize($resource, 'securityPostDenormalizeMessage', 'string'),
'securityPostValidation' => $this->phpize($resource, 'securityPostValidation', 'string'),
'securityPostValidationMessage' => $this->phpize($resource, 'securityPostValidationMessage', 'string'),
'input' => $this->phpize($resource, 'input', 'string'),
'output' => $this->phpize($resource, 'output', 'string'),
'input' => $this->phpize($resource, 'input', 'bool|string'),
'output' => $this->phpize($resource, 'output', 'bool|string'),
'normalizationContext' => $this->buildArrayValue($resource, 'normalizationContext'),
'denormalizationContext' => $this->buildArrayValue($resource, 'denormalizationContext'),
'validationContext' => $this->buildArrayValue($resource, 'validationContext'),
Expand Down
34 changes: 34 additions & 0 deletions tests/Metadata/Extractor/YamlExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,40 @@ public function testValidYaml(): void
], $extractor->getResources());
}

public function testInputAndOutputAreBooleans(): void
{
$extractor = new YamlResourceExtractor([__DIR__.'/yaml/input-and-output-are-booleans.yaml']);
$resources = $extractor->getResources();

$this->assertArrayHasKey(Program::class, $resources);
$this->assertArrayHasKey(0, $resources[Program::class]);
$this->assertArrayHasKey('operations', $resources[Program::class][0]);
$this->assertArrayHasKey('0', $resources[Program::class][0]['operations']);

$this->assertArrayHasKey('input', $resources[Program::class][0]['operations'][0]);
$this->assertFalse($resources[Program::class][0]['operations'][0]['input']);

$this->assertArrayHasKey('output', $resources[Program::class][0]['operations'][0]);
$this->assertFalse($resources[Program::class][0]['operations'][0]['output']);
}

public function testInputAndOutputAreStrings(): void
{
$extractor = new YamlResourceExtractor([__DIR__.'/yaml/input-and-output-are-strings.yaml']);
$resources = $extractor->getResources();

$this->assertArrayHasKey(Program::class, $resources);
$this->assertArrayHasKey(0, $resources[Program::class]);
$this->assertArrayHasKey('operations', $resources[Program::class][0]);
$this->assertArrayHasKey('0', $resources[Program::class][0]['operations']);

$this->assertArrayHasKey('input', $resources[Program::class][0]['operations'][0]);
$this->assertSame(Program::class.'Input', $resources[Program::class][0]['operations'][0]['input']);

$this->assertArrayHasKey('output', $resources[Program::class][0]['operations'][0]);
$this->assertSame(Program::class.'Output', $resources[Program::class][0]['operations'][0]['output']);
}

/**
* @dataProvider getInvalidPaths
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resources:
ApiPlatform\Tests\Fixtures\TestBundle\Entity\Program:
- uriTemplate: /users/{author}/programs.{_format}
uriVariables: ['author']
operations:
ApiPlatform\Metadata\Post:
input: false
output: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resources:
ApiPlatform\Tests\Fixtures\TestBundle\Entity\Program:
- uriTemplate: /users/{author}/programs.{_format}
uriVariables: ['author']
operations:
ApiPlatform\Metadata\Post:
input: ApiPlatform\Tests\Fixtures\TestBundle\Entity\ProgramInput
output: ApiPlatform\Tests\Fixtures\TestBundle\Entity\ProgramOutput

0 comments on commit cc8e6d1

Please sign in to comment.