Skip to content

Commit c260480

Browse files
committed
feat: behat test PUT
1 parent a7bd731 commit c260480

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

features/book.feature

+17-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Feature: Book
88
And the count of "data" is 0
99

1010
Scenario: Insert a book: POST /v1/books
11-
When I run POST on "v1/books" with json
11+
When I run "POST" on "v1/books" with json
1212
"""
1313
{
1414
"data": {
@@ -21,3 +21,19 @@ Feature: Book
2121
And the body is json
2222
And the count of "data" is 1
2323

24+
Scenario: Modify a book: PUT /v1/books/1
25+
When I run "PUT" on "v1/books/1" with json
26+
"""
27+
{
28+
"data": {
29+
"title": "PHP is awesome",
30+
"pages": 1000
31+
}
32+
}
33+
"""
34+
Then the status code is 200
35+
And the body is json
36+
And the count of "data" is 1
37+
And json body have "$.data.title" = "PHP is awesome"
38+
And json body have "$.data.pages" = "1000"
39+

tests/Behat/RestContext.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public function iRunGet($url)
6666
}
6767

6868
/**
69-
* @When I run POST on :url with json
69+
* @When I run :method on :url with json
7070
*/
71-
public function iRunPostWithJson($url, PyStringNode $string)
71+
public function iRunRestWithJson($method, $url, PyStringNode $string)
7272
{
7373
try {
7474

@@ -81,7 +81,7 @@ public function iRunPostWithJson($url, PyStringNode $string)
8181
'json' => $postParamArray
8282
];
8383

84-
$response = $this->_client->post($url, $headers);
84+
$response = $this->_client->request($method, $url, $headers);
8585
$this->_response = $response;
8686
} catch (RequestException $e) { //4xx //5xx network
8787
if ($e->hasResponse()) {
@@ -94,7 +94,6 @@ public function iRunPostWithJson($url, PyStringNode $string)
9494
}
9595
}
9696

97-
9897
/**
9998
* @Then the status code is :arg1
10099
*/

0 commit comments

Comments
 (0)