Skip to content

Commit 356ef32

Browse files
committed
Add a deprecated resource and field. Fix tests.
1 parent b56241d commit 356ef32

File tree

9 files changed

+127
-76
lines changed

9 files changed

+127
-76
lines changed

api/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
44

55
###> symfony/framework-bundle ###
6-
APP_ENV=prod
6+
APP_ENV=dev
77
APP_SECRET=!ChangeMe!
88
TRUSTED_PROXIES=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
99
TRUSTED_HOSTS=localhost,api

api/composer.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
{
22
"type": "project",
33
"license": "MIT",
4-
"repositories": [
5-
{
6-
"type": "vcs",
7-
"url": "https://github.com/dunglas/core"
8-
}
9-
],
104
"require": {
115
"php": "^7.1.3",
126
"ext-iconv": "*",
137
"api-platform/api-pack": "^1.0",
14-
"api-platform/core": "dev-serializer-41 as 2.3",
8+
"api-platform/core": "^2.3@dev",
159
"guzzlehttp/guzzle": "^6.3",
1610
"nelmio/cors-bundle": "^1.5",
1711
"sensiolabs/security-checker": "^4.1",

api/composer.lock

Lines changed: 16 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/features/books.feature

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Feature: Manage books and their reviews
33
As a client software developer
44
I need to be able to retrieve, create, update and delete them trough the API.
55

6-
# the "@createSchema" annotation provided by API Platform creates a temporary SQLite database for testing the API
76
@createSchema
87
Scenario: Create a book
98
When I add "Content-Type" header equal to "application/ld+json"
@@ -27,12 +26,13 @@ Feature: Manage books and their reviews
2726
"@context": "/contexts/Book",
2827
"@id": "/books/1",
2928
"@type": "http://schema.org/Book",
30-
"id": 1,
3129
"isbn": "9781782164104",
30+
"title": "Persistence in PHP with the Doctrine ORM",
3231
"description": "This book is designed for PHP developers and architects who want to modernize their skills through better understanding of Persistence and ORM.",
3332
"author": "K\u00e9vin Dunglas",
34-
"title": "Persistence in PHP with the Doctrine ORM",
35-
"publicationDate": "2013-12-01T00:00:00+00:00"
33+
"publicationDate": "2013-12-01T00:00:00+00:00",
34+
"id": 1,
35+
"reviews": []
3636
}
3737
"""
3838

@@ -52,15 +52,29 @@ Feature: Manage books and their reviews
5252
{
5353
"@id": "/books/1",
5454
"@type": "http://schema.org/Book",
55-
"id": 1,
5655
"isbn": "9781782164104",
56+
"title": "Persistence in PHP with the Doctrine ORM",
5757
"description": "This book is designed for PHP developers and architects who want to modernize their skills through better understanding of Persistence and ORM.",
5858
"author": "K\u00e9vin Dunglas",
59-
"title": "Persistence in PHP with the Doctrine ORM",
60-
"publicationDate": "2013-12-01T00:00:00+00:00"
59+
"publicationDate": "2013-12-01T00:00:00+00:00",
60+
"id": 1,
61+
"reviews": []
6162
}
6263
],
63-
"hydra:totalItems": 1
64+
"hydra:totalItems": 1,
65+
"hydra:search": {
66+
"@type": "hydra:IriTemplate",
67+
"hydra:template": "\/books{?properties[]}",
68+
"hydra:variableRepresentation": "BasicRepresentation",
69+
"hydra:mapping": [
70+
{
71+
"@type": "IriTemplateMapping",
72+
"variable": "properties[]",
73+
"property": null,
74+
"required": false
75+
}
76+
]
77+
}
6478
}
6579
"""
6680

@@ -122,16 +136,16 @@ Feature: Manage books and their reviews
122136
"@context": "/contexts/Review",
123137
"@id": "/reviews/1",
124138
"@type": "http://schema.org/Review",
125-
"id": 1,
126-
"rating": 5,
127139
"body": "Must have!",
140+
"rating": 5,
141+
"letter": null,
128142
"book": "/books/1",
129143
"author": "Foo Bar",
130-
"publicationDate": "2016-01-01T00:00:00+00:00"
144+
"publicationDate": "2016-01-01T00:00:00+00:00",
145+
"id": 1
131146
}
132147
"""
133148

134-
@dropSchema
135149
Scenario: Get reviews by book
136150
When I add "Accept" header equal to "application/ld+json"
137151
And I send a "GET" request to "/reviews?book=/books/1"
@@ -148,27 +162,42 @@ Feature: Manage books and their reviews
148162
{
149163
"@id": "/reviews/1",
150164
"@type": "http://schema.org/Review",
151-
"id": 1,
152-
"rating": 5,
153165
"body": "Must have!",
166+
"rating": 5,
167+
"letter": null,
154168
"book": "/books/1",
155169
"author": "Foo Bar",
156-
"publicationDate": "2016-01-01T00:00:00+00:00"
170+
"publicationDate": "2016-01-01T00:00:00+00:00",
171+
"id": 1
157172
}
158173
],
159174
"hydra:totalItems": 1,
160175
"hydra:view": {
161176
"@id": "/reviews?book=%2Fbooks%2F1",
162177
"@type": "hydra:PartialCollectionView"
163178
},
179+
"hydra:view": {
180+
"@id": "\/reviews?book=%2Fbooks%2F1",
181+
"@type": "hydra:PartialCollectionView"
182+
},
164183
"hydra:search": {
165184
"@type": "hydra:IriTemplate",
166-
"hydra:template": "/reviews{?}",
185+
"hydra:template": "\/reviews{?book,book[]}",
167186
"hydra:variableRepresentation": "BasicRepresentation",
168-
"hydra:mapping": []
187+
"hydra:mapping": [
188+
{
189+
"@type": "IriTemplateMapping",
190+
"variable": "book",
191+
"property": "book",
192+
"required": false
193+
},
194+
{
195+
"@type": "IriTemplateMapping",
196+
"variable": "book[]",
197+
"property": "book",
198+
"required": false
199+
}
200+
]
169201
}
170202
}
171203
"""
172-
173-
# The "@dropSchema" annotation must be added on the last scenario of the feature file to drop the temporary SQLite database
174-
#"Scenario: Fetch

api/features/bootstrap/FeatureContext.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ class FeatureContext implements Context, SnippetAcceptingContext
1515
*/
1616
private $doctrine;
1717

18-
/**
19-
* @var \Doctrine\Common\Persistence\ObjectManager
20-
*/
21-
private $manager;
22-
2318
/**
2419
* @var SchemaTool
2520
*/
@@ -40,24 +35,18 @@ class FeatureContext implements Context, SnippetAcceptingContext
4035
public function __construct(ManagerRegistry $doctrine)
4136
{
4237
$this->doctrine = $doctrine;
43-
$this->manager = $doctrine->getManager();
44-
$this->schemaTool = new SchemaTool($this->manager);
45-
$this->classes = $this->manager->getMetadataFactory()->getAllMetadata();
38+
$manager = $doctrine->getManager();
39+
$this->schemaTool = new SchemaTool($manager);
40+
$this->classes = $manager->getMetadataFactory()->getAllMetadata();
4641
}
4742

4843
/**
4944
* @BeforeScenario @createSchema
5045
*/
5146
public function createDatabase()
52-
{
53-
$this->schemaTool->createSchema($this->classes);
54-
}
55-
56-
/**
57-
* @AfterScenario @dropSchema
58-
*/
59-
public function dropDatabase()
6047
{
6148
$this->schemaTool->dropSchema($this->classes);
49+
$this->doctrine->getManager()->clear();
50+
$this->schemaTool->createSchema($this->classes);
6251
}
6352
}

api/src/Action/.gitkeep

Whitespace-only changes.

api/src/Entity/Book.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace App\Entity;
44

5+
use ApiPlatform\Core\Annotation\ApiFilter;
56
use ApiPlatform\Core\Annotation\ApiProperty;
67
use ApiPlatform\Core\Annotation\ApiResource;
7-
use ApiPlatform\Core\Annotation\ApiFilter;
88
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
99
use Doctrine\Common\Collections\ArrayCollection;
1010
use Doctrine\Common\Collections\Collection;

api/src/Entity/Parchment.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace App\Entity;
4+
5+
use ApiPlatform\Core\Annotation\ApiResource;
6+
use Doctrine\ORM\Mapping as ORM;
7+
use Symfony\Component\Validator\Constraints as Assert;
8+
9+
/**
10+
* @ORM\Entity
11+
* @ApiResource(deprecationReason="Create a Book instead")
12+
*/
13+
class Parchment
14+
{
15+
/**
16+
* @var int
17+
*
18+
* @ORM\Column(type="integer")
19+
* @ORM\Id
20+
* @ORM\GeneratedValue(strategy="AUTO")
21+
*/
22+
private $id;
23+
24+
public function getId(): ?int
25+
{
26+
return $this->id;
27+
}
28+
29+
/**
30+
* @var string The title of the book
31+
*
32+
* @Assert\NotBlank
33+
* @ORM\Column
34+
*/
35+
public $title;
36+
37+
/**
38+
* @var string A description of the item
39+
*
40+
* @Assert\NotBlank
41+
* @ORM\Column(type="text")
42+
*/
43+
public $description;
44+
}

api/src/Entity/Review.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @see http://schema.org/Review Documentation on Schema.org
1616
*
1717
* @ORM\Entity
18-
* @ApiResource(iri="http://schema.org/Review", attributes={"filters"={"review.search_filter"}})
18+
* @ApiResource(iri="http://schema.org/Review")
1919
* @ApiFilter(SearchFilter::class, properties={"book": "exact"})
2020
*/
2121
class Review
@@ -45,6 +45,15 @@ class Review
4545
*/
4646
public $rating;
4747

48+
/**
49+
* @var string DEPRECATED (use rating now): A letter to rate the book
50+
*
51+
* @Assert\Choice({"a", "b", "c", "d"})
52+
* @ORM\Column(type="string", nullable=true)
53+
* @ApiProperty(deprecationReason="Use the rating property instead")
54+
*/
55+
public $letter;
56+
4857
/**
4958
* @var Book The item that is being reviewed/rated
5059
*

0 commit comments

Comments
 (0)