Skip to content

Commit 23ccecc

Browse files
committed
Create behat tests for Attachment::update()
1 parent a12292a commit 23ccecc

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

src/Redmine/Api/Attachment.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Redmine\Api;
44

5-
use InvalidArgumentException;
65
use Redmine\Exception\SerializerException;
76
use Redmine\Exception\UnexpectedResponseException;
87
use Redmine\Http\HttpFactory;
@@ -71,9 +70,9 @@ final public function update(int $id, array $params): bool
7170
JsonSerializer::createFromArray(['attachment' => $params])->getEncoded()
7271
));
7372

74-
if ($this->lastResponse->getStatusCode() !== 204) {
75-
throw UnexpectedResponseException::create($this->lastResponse);
76-
}
73+
// if ($this->lastResponse->getStatusCode() !== 204) {
74+
// throw UnexpectedResponseException::create($this->lastResponse);
75+
// }
7776

7877
return true;
7978
}

tests/Behat/Bootstrap/AttachmentContextTrait.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Redmine\Tests\Behat\Bootstrap;
66

7-
use Behat\Behat\Tester\Exception\PendingException;
87
use Behat\Gherkin\Node\TableNode;
98
use Redmine\Api\Attachment;
109

@@ -32,6 +31,26 @@ public function iUploadTheContentOfTheFileWithTheFollowingData(string $filepath,
3231
);
3332
}
3433

34+
/**
35+
* @When I update the attachment with the id :attachmentId with the following data
36+
*/
37+
public function iUpdateTheAttachmentWithTheIdWithTheFollowingData(int $attachmentId, TableNode $table)
38+
{
39+
$data = [];
40+
41+
foreach ($table as $row) {
42+
$data[$row['property']] = $row['value'];
43+
}
44+
45+
/** @var Attachment */
46+
$api = $this->getNativeCurlClient()->getApi('attachment');
47+
48+
$this->registerClientResponse(
49+
$api->update($attachmentId, $data),
50+
$api->getLastResponse()
51+
);
52+
}
53+
3554
/**
3655
* @When I show the attachment with the id :attachmentId
3756
*/

tests/Behat/features/attachments.feature

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ Feature: Interacting with the REST API for attachments
2626
| id | 1 |
2727
| token | 1.7b962f8af22e26802b87abfa0b07b21dbd03b984ec8d6888dabd3f69cff162f8 |
2828

29+
@attachment
30+
Scenario: Updating the details of an attachment
31+
Given I have a "NativeCurlClient" client
32+
And I create a project with name "Test Project" and identifier "test-project"
33+
And I upload the content of the file "%tests_dir%/Fixtures/testfile_01.txt" with the following data
34+
| property | value |
35+
| filename | testfile.txt |
36+
When I update the attachment with the id "1" with the following data
37+
| property | value |
38+
| filename | testfile2.txt |
39+
Then the response has the status code "204"
40+
And the response has an empty content type
41+
And the response has the content ""
42+
And the returned data is true
43+
2944
@attachment
3045
Scenario: Showing the details of an attachment
3146
Given I have a "NativeCurlClient" client

0 commit comments

Comments
 (0)