Skip to content

Commit 17a231d

Browse files
committed
Merge 4.0
2 parents db40a63 + 421d97e commit 17a231d

File tree

12 files changed

+59
-4
lines changed

12 files changed

+59
-4
lines changed

features/hydra/collection.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ Feature: Collections support
7777
When I send a "GET" request to "/dummies?page=7"
7878
Then the response status code should be 200
7979
And the response should be in JSON
80-
And the header "Content-Location" should be equal to "/dummies.jsonld?page=7"
8180
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
8281
And the JSON should be valid according to this schema:
8382
"""

features/main/crud.feature

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Feature: Create-Retrieve-Update-Delete
6060
Then the response status code should be 200
6161
And the response should be in JSON
6262
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
63+
And the header "Content-Location" should not exist
6364
And the JSON should be equal to:
6465
"""
6566
{
@@ -100,13 +101,14 @@ Feature: Create-Retrieve-Update-Delete
100101
Scenario: Get a not found exception
101102
When I send a "GET" request to "/dummies/42"
102103
Then the response status code should be 404
104+
And the header "Content-Location" should not exist
103105

104106
Scenario: Get a collection
105107
When I send a "GET" request to "/dummies"
106108
Then the response status code should be 200
107109
And the response should be in JSON
108110
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
109-
And the header "Content-Location" should be equal to "/dummies.jsonld"
111+
And the header "Content-Location" should not exist
110112
And the JSON should be equal to:
111113
"""
112114
{
@@ -616,6 +618,7 @@ Feature: Create-Retrieve-Update-Delete
616618
Then the response status code should be 200
617619
And the response should be in JSON
618620
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
621+
And the header "Content-Location" should not exist
619622
And the JSON should be equal to:
620623
"""
621624
{
@@ -640,6 +643,7 @@ Feature: Create-Retrieve-Update-Delete
640643
Then the response status code should be 200
641644
And the response should be in JSON
642645
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
646+
And the header "Content-Location" should not exist
643647
And the JSON should be equal to:
644648
"""
645649
{
@@ -657,6 +661,7 @@ Feature: Create-Retrieve-Update-Delete
657661
Then the response status code should be 200
658662
And the response should be in JSON
659663
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
664+
And the header "Content-Location" should not exist
660665
And the JSON should be equal to:
661666
"""
662667
{
@@ -676,6 +681,7 @@ Feature: Create-Retrieve-Update-Delete
676681
Then the response status code should be 200
677682
And the response should be in JSON
678683
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
684+
And the header "Content-Location" should not exist
679685
And the JSON should be equal to:
680686
"""
681687
{
@@ -718,6 +724,7 @@ Feature: Create-Retrieve-Update-Delete
718724
Then the response status code should be 200
719725
And the response should be in JSON
720726
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
727+
And the header "Content-Location" should not exist
721728
And the JSON should be equal to:
722729
"""
723730
{
@@ -737,6 +744,7 @@ Feature: Create-Retrieve-Update-Delete
737744
Then the response status code should be 200
738745
And the response should be in JSON
739746
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
747+
And the header "Content-Location" should not exist
740748
And the JSON should be equal to:
741749
"""
742750
{

features/main/crud_abstract.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Feature: Create-Retrieve-Update-Delete on abstract resource
3535
Then the response status code should be 200
3636
And the response should be in JSON
3737
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
38+
And the header "Content-Location" should not exist
3839
And the JSON should be equal to:
3940
"""
4041
{
@@ -52,6 +53,7 @@ Feature: Create-Retrieve-Update-Delete on abstract resource
5253
Then the response status code should be 200
5354
And the response should be in JSON
5455
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
56+
And the header "Content-Location" should not exist
5557
And the JSON should be valid according to this schema:
5658
"""
5759
{

features/main/crud_uri_variables.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Feature: Uri Variables
9696
Then the response status code should be 200
9797
And the response should be in JSON
9898
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
99+
And the header "Content-Location" should not exist
99100
And the JSON should be equal to:
100101
"""
101102
{
@@ -164,6 +165,7 @@ Feature: Uri Variables
164165
Then the response status code should be 200
165166
And the response should be in JSON
166167
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
168+
And the header "Content-Location" should not exist
167169
And the JSON should be equal to:
168170
"""
169171
{
@@ -183,6 +185,7 @@ Feature: Uri Variables
183185
Then the response status code should be 200
184186
And the response should be in JSON
185187
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
188+
And the header "Content-Location" should not exist
186189
And the JSON should be equal to:
187190
"""
188191
{
@@ -200,3 +203,4 @@ Feature: Uri Variables
200203
When I add "Content-Type" header equal to "application/ld+json"
201204
And I send a "GET" request to "/companies/1/employees/2"
202205
Then the response status code should be 404
206+
And the header "Content-Location" should not exist

src/Laravel/ApiPlatformProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
223223
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
224224
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
225+
use Symfony\Component\Serializer\Normalizer\BackedEnumNormalizer;
225226
use Symfony\Component\Serializer\Normalizer\DateIntervalNormalizer;
226227
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
227228
use Symfony\Component\Serializer\Normalizer\DateTimeZoneNormalizer;
@@ -1020,6 +1021,7 @@ public function register(): void
10201021
$list->insert($app->make(DateTimeZoneNormalizer::class), -915);
10211022
$list->insert($app->make(DateIntervalNormalizer::class), -915);
10221023
$list->insert($app->make(DateTimeNormalizer::class), -910);
1024+
$list->insert($app->make(BackedEnumNormalizer::class), -910);
10231025
$list->insert($app->make(ObjectNormalizer::class), -1000);
10241026
$list->insert($app->make(ItemNormalizer::class), -895);
10251027
$list->insert($app->make(OpenApiNormalizer::class), -780);

src/Laravel/Tests/EloquentTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace ApiPlatform\Laravel\Tests;
1515

1616
use ApiPlatform\Laravel\Test\ApiTestAssertionsTrait;
17+
use ApiPlatform\Laravel\workbench\app\Enums\BookStatus;
1718
use Illuminate\Foundation\Testing\RefreshDatabase;
1819
use Orchestra\Testbench\Concerns\WithWorkbench;
1920
use Orchestra\Testbench\TestCase;
@@ -27,6 +28,19 @@ class EloquentTest extends TestCase
2728
use RefreshDatabase;
2829
use WithWorkbench;
2930

31+
public function testBackedEnumsNormalization(): void
32+
{
33+
BookFactory::new([
34+
'status' => BookStatus::DRAFT,
35+
])->has(AuthorFactory::new())->count(10)->create();
36+
37+
$response = $this->get('/api/books', ['Accept' => ['application/ld+json']]);
38+
$book = $response->json()['member'][0];
39+
40+
$this->assertArrayHasKey('status', $book);
41+
$this->assertSame('DRAFT', $book['status']);
42+
}
43+
3044
public function testSearchFilter(): void
3145
{
3246
BookFactory::new()->has(AuthorFactory::new())->count(10)->create();

src/Laravel/Tests/GraphQlTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace ApiPlatform\Laravel\Tests;
1515

1616
use ApiPlatform\Laravel\Test\ApiTestAssertionsTrait;
17+
use ApiPlatform\Laravel\workbench\app\Enums\BookStatus;
1718
use Illuminate\Config\Repository;
1819
use Illuminate\Foundation\Application;
1920
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -133,6 +134,7 @@ public function testCreateBook(): void
133134
'name' => fake()->name(),
134135
'author' => 'api/authors/'.$author->id,
135136
'isbn' => fake()->isbn13(),
137+
'status' => BookStatus::PUBLISHED,
136138
'isAvailable' => 1 === random_int(0, 1),
137139
],
138140
],
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Laravel\workbench\app\Enums;
15+
16+
enum BookStatus: string
17+
{
18+
case PUBLISHED = 'PUBLISHED';
19+
case DRAFT = 'DRAFT';
20+
}

src/Laravel/workbench/app/Models/Book.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use ApiPlatform\Laravel\Eloquent\Filter\OrFilter;
2323
use ApiPlatform\Laravel\Eloquent\Filter\PartialSearchFilter;
2424
use ApiPlatform\Laravel\Eloquent\Filter\RangeFilter;
25+
use ApiPlatform\Laravel\workbench\app\Enums\BookStatus;
2526
use ApiPlatform\Metadata\ApiResource;
2627
use ApiPlatform\Metadata\Delete;
2728
use ApiPlatform\Metadata\Get;
@@ -92,6 +93,7 @@ class Book extends Model
9293
protected $fillable = ['name', 'publication_date', 'isbn', 'is_available', 'published'];
9394
protected $casts = [
9495
'is_available' => 'boolean',
96+
'status' => BookStatus::class,
9597
];
9698

9799
public function author(): BelongsTo

src/Laravel/workbench/database/factories/BookFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Workbench\Database\Factories;
1515

16+
use ApiPlatform\Laravel\workbench\app\Enums\BookStatus;
1617
use Illuminate\Database\Eloquent\Factories\Factory;
1718
use Symfony\Component\Uid\Ulid;
1819
use Workbench\App\Models\Book;
@@ -38,6 +39,7 @@ public function definition(): array
3839
'isbn' => fake()->isbn13(),
3940
'publication_date' => fake()->optional()->date(),
4041
'is_available' => 1 === random_int(0, 1),
42+
'status' => BookStatus::PUBLISHED,
4143
'internal_note' => fake()->text(),
4244
'published' => fake()->boolean(100),
4345
];

0 commit comments

Comments
 (0)