Skip to content

Commit 6826437

Browse files
authored
Merge pull request #2699 from Toflar/strict-types
Added an additional test for strict types validation
2 parents 0569e10 + a183b9f commit 6826437

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

features/security/strong_typing.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ Feature: Handle properly invalid data submitted to the API
4242
}
4343
"""
4444

45+
Scenario: Create a resource without a required property with a strongly-typed setter
46+
When I add "Content-Type" header equal to "application/ld+json"
47+
And I send a "POST" request to "/dummies" with body:
48+
"""
49+
{
50+
"name": null
51+
}
52+
"""
53+
Then the response status code should be 400
54+
And the response should be in JSON
55+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
56+
And the JSON node "@context" should be equal to "/contexts/Error"
57+
And the JSON node "@type" should be equal to "hydra:Error"
58+
And the JSON node "hydra:title" should be equal to "An error occurred"
59+
And the JSON node "hydra:description" should be equal to 'The type of the "name" attribute must be "string", "NULL" given.'
60+
4561
Scenario: Create a resource with wrong value type for relation
4662
When I add "Content-Type" header equal to "application/ld+json"
4763
And I send a "POST" request to "/dummies" with body:

tests/Fixtures/TestBundle/Entity/Dummy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ public function setId($id)
188188
$this->id = $id;
189189
}
190190

191-
public function setName($name)
191+
public function setName(string $name)
192192
{
193193
$this->name = $name;
194194
}
195195

196-
public function getName()
196+
public function getName(): string
197197
{
198198
return $this->name;
199199
}

0 commit comments

Comments
 (0)