File tree Expand file tree Collapse file tree
tests/Fixtures/TestBundle/Entity Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Feature : Resource should contain one field for each property
2+ In order to use API resource
3+ As a developer
4+ I need to have one field exposed for each property (which take getter/setter name)
5+
6+ @createSchema
7+ Scenario : I should be able to POST a new entity
8+ When I add "Accept" header equal to "application/ld+json"
9+ And I add "Content-Type" header equal to "application/ld+json"
10+ When I send a "POST" request to "/entity_with_renamed_getter_and_setters" with body:
11+ """
12+ {
13+ "firstnameOnly": "Sarah"
14+ }
15+ """
16+ Then the response status code should be 201
17+ And the JSON should be equal to:
18+ """
19+ {
20+ "@context": "/contexts/EntityWithRenamedGetterAndSetter",
21+ "@id": "/entity_with_renamed_getter_and_setters/1",
22+ "@type": "EntityWithRenamedGetterAndSetter",
23+ "id": 1,
24+ "firstnameOnly": "Sarah"
25+ }
26+ """
Original file line number Diff line number Diff line change 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 \Tests \Fixtures \TestBundle \Entity ;
15+
16+ use ApiPlatform \Core \Annotation \ApiResource ;
17+ use Doctrine \ORM \Mapping as ORM ;
18+
19+ /**
20+ *
21+ * @ApiResource()
22+ *
23+ * @ORM\Entity
24+ */
25+ class EntityWithRenamedGetterAndSetter
26+ {
27+
28+ /**
29+ * @ORM\Id
30+ *
31+ * @ORM\Column(type="integer")
32+ *
33+ * @ORM\GeneratedValue(strategy="AUTO")
34+ */
35+ private $ id ;
36+
37+ /**
38+ * @ORM\Column(type="string")
39+ */
40+ private $ name ;
41+
42+ public function getId (): int
43+ {
44+ return $ this ->id ;
45+ }
46+
47+ public function setId (int $ id ): void
48+ {
49+ $ this ->id = $ id ;
50+ }
51+
52+ /**
53+ * @return string
54+ */
55+ public function getFirstnameOnly (): string
56+ {
57+ return $ this ->name ;
58+ }
59+
60+ /**
61+ * @param string $name
62+ */
63+ public function setFirstnameOnly (string $ name ): void
64+ {
65+ $ this ->name = $ name ;
66+ }
67+ }
You can’t perform that action at this time.
0 commit comments