-
-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6190 from soyuka/merge
Merge 3.2
- Loading branch information
Showing
18 changed files
with
262 additions
and
22 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
features/doctrine/issue6175/standard_put_entity_inheritence.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Feature: Update properties of a resource that are inherited with standard PUT operation | ||
|
||
@!mongodb | ||
@createSchema | ||
Scenario: Update properties of a resource that are inherited with standard PUT operation | ||
Given there is a dummy entity with a mapped superclass | ||
When I add "Content-Type" header equal to "application/ld+json" | ||
And I send a "PUT" request to "/dummy_mapped_subclasses/1" with body: | ||
""" | ||
{ | ||
"foo": "updated value" | ||
} | ||
""" | ||
Then the response status code should be 200 | ||
And the response should be in JSON | ||
And the JSON should be equal to: | ||
""" | ||
{ | ||
"@context": "/contexts/DummyMappedSubclass", | ||
"@id": "/dummy_mapped_subclasses/1", | ||
"@type": "DummyMappedSubclass", | ||
"id": 1, | ||
"foo": "updated value" | ||
} | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/JsonSchema/Tests/BackwardCompatibleSchemaFactoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\JsonSchema\Tests; | ||
|
||
use ApiPlatform\JsonSchema\BackwardCompatibleSchemaFactory; | ||
use ApiPlatform\JsonSchema\Schema; | ||
use ApiPlatform\JsonSchema\SchemaFactoryInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class BackwardCompatibleSchemaFactoryTest extends TestCase | ||
{ | ||
public function testWithSingleType(): void | ||
{ | ||
$schema = new Schema(); | ||
$schema->setDefinitions(new \ArrayObject([ | ||
'a' => new \ArrayObject([ | ||
'properties' => new \ArrayObject([ | ||
'foo' => new \ArrayObject(['type' => 'integer', 'exclusiveMinimum' => 0, 'exclusiveMaximum' => 1]), | ||
]), | ||
]), | ||
])); | ||
$schemaFactory = $this->createMock(SchemaFactoryInterface::class); | ||
$schemaFactory->method('buildSchema')->willReturn($schema); | ||
$schemaFactory = new BackwardCompatibleSchemaFactory($schemaFactory); | ||
$schema = $schemaFactory->buildSchema('a', serializerContext: [BackwardCompatibleSchemaFactory::SCHEMA_DRAFT4_VERSION => true]); | ||
$schema = $schema->getDefinitions()['a']; | ||
|
||
$this->assertTrue($schema['properties']['foo']['exclusiveMinimum']); | ||
$this->assertTrue($schema['properties']['foo']['exclusiveMaximum']); | ||
$this->assertEquals($schema['properties']['foo']['minimum'], 0); | ||
$this->assertEquals($schema['properties']['foo']['maximum'], 1); | ||
} | ||
|
||
public function testWithMultipleType(): void | ||
{ | ||
$schema = new Schema(); | ||
$schema->setDefinitions(new \ArrayObject([ | ||
'a' => new \ArrayObject([ | ||
'properties' => new \ArrayObject([ | ||
'foo' => new \ArrayObject(['type' => ['number', 'null'], 'exclusiveMinimum' => 0, 'exclusiveMaximum' => 1]), | ||
]), | ||
]), | ||
])); | ||
$schemaFactory = $this->createMock(SchemaFactoryInterface::class); | ||
$schemaFactory->method('buildSchema')->willReturn($schema); | ||
$schemaFactory = new BackwardCompatibleSchemaFactory($schemaFactory); | ||
$schema = $schemaFactory->buildSchema('a', serializerContext: [BackwardCompatibleSchemaFactory::SCHEMA_DRAFT4_VERSION => true]); | ||
$schema = $schema->getDefinitions()['a']; | ||
|
||
$this->assertTrue($schema['properties']['foo']['exclusiveMinimum']); | ||
$this->assertTrue($schema['properties']['foo']['exclusiveMaximum']); | ||
$this->assertEquals($schema['properties']['foo']['minimum'], 0); | ||
$this->assertEquals($schema['properties']['foo']['maximum'], 1); | ||
} | ||
|
||
public function testWithoutNumber(): void | ||
{ | ||
$schema = new Schema(); | ||
$schema->setDefinitions(new \ArrayObject([ | ||
'a' => new \ArrayObject([ | ||
'properties' => new \ArrayObject([ | ||
'foo' => new \ArrayObject(['type' => ['string', 'null'], 'exclusiveMinimum' => 0, 'exclusiveMaximum' => 1]), | ||
]), | ||
]), | ||
])); | ||
$schemaFactory = $this->createMock(SchemaFactoryInterface::class); | ||
$schemaFactory->method('buildSchema')->willReturn($schema); | ||
$schemaFactory = new BackwardCompatibleSchemaFactory($schemaFactory); | ||
$schema = $schemaFactory->buildSchema('a', serializerContext: [BackwardCompatibleSchemaFactory::SCHEMA_DRAFT4_VERSION => true]); | ||
$schema = $schema->getDefinitions()['a']; | ||
|
||
$this->assertEquals($schema['properties']['foo']['exclusiveMinimum'], 0); | ||
$this->assertEquals($schema['properties']['foo']['exclusiveMaximum'], 1); | ||
} | ||
|
||
public function testWithoutFlag(): void | ||
{ | ||
$schema = new Schema(); | ||
$schema->setDefinitions(new \ArrayObject([ | ||
'a' => new \ArrayObject([ | ||
'properties' => new \ArrayObject([ | ||
'foo' => new \ArrayObject(['type' => ['string', 'null'], 'exclusiveMinimum' => 0, 'exclusiveMaximum' => 1]), | ||
]), | ||
]), | ||
])); | ||
$schemaFactory = $this->createMock(SchemaFactoryInterface::class); | ||
$schemaFactory->method('buildSchema')->willReturn($schema); | ||
$schemaFactory = new BackwardCompatibleSchemaFactory($schemaFactory); | ||
$schema = $schemaFactory->buildSchema('a', serializerContext: [BackwardCompatibleSchemaFactory::SCHEMA_DRAFT4_VERSION => false]); | ||
$schema = $schema->getDefinitions()['a']; | ||
|
||
$this->assertEquals($schema['properties']['foo']['exclusiveMinimum'], 0); | ||
$this->assertEquals($schema['properties']['foo']['exclusiveMaximum'], 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity; | ||
|
||
use ApiPlatform\Metadata\Put; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity] | ||
#[Put( | ||
extraProperties: [ | ||
'standard_put' => true, | ||
], | ||
allowCreate: true | ||
)] | ||
class DummyMappedSubclass extends DummyMappedSuperclass | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column] | ||
private ?int $id = null; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/Fixtures/TestBundle/Entity/DummyMappedSuperclass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\MappedSuperclass] | ||
class DummyMappedSuperclass | ||
{ | ||
#[ORM\Column(length: 255, nullable: true)] | ||
private ?string $foo = null; | ||
|
||
public function getFoo(): ?string | ||
{ | ||
return $this->foo; | ||
} | ||
|
||
public function setFoo(?string $foo): static | ||
{ | ||
$this->foo = $foo; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.