Skip to content

Commit a12292a

Browse files
committed
Add test for UnexpectedResponseException in Attachment::update()
1 parent c616f78 commit a12292a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Redmine/Api/Attachment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function show($id)
6363
*
6464
* @return true if the request was successful
6565
*/
66-
public function update(int $id, array $params): bool
66+
final public function update(int $id, array $params): bool
6767
{
6868
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeJsonRequest(
6969
'PATCH',

tests/Unit/Api/Attachment/UpdateTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPUnit\Framework\Attributes\DataProvider;
77
use PHPUnit\Framework\TestCase;
88
use Redmine\Api\Attachment;
9+
use Redmine\Exception\UnexpectedResponseException;
910
use Redmine\Tests\Fixtures\AssertingHttpClient;
1011

1112
#[CoversClass(Attachment::class)]
@@ -52,4 +53,27 @@ public static function getUpdateData(): array
5253
],
5354
];
5455
}
56+
57+
public function testUpdateThrowsUnexpectedResponseException()
58+
{
59+
$client = AssertingHttpClient::create(
60+
$this,
61+
[
62+
'PATCH',
63+
'/attachments/5.json',
64+
'application/json',
65+
'{"attachment":[]}',
66+
403,
67+
'',
68+
'',
69+
]
70+
);
71+
72+
$api = new Attachment($client);
73+
74+
$this->expectException(UnexpectedResponseException::class);
75+
$this->expectExceptionMessage('The Redmine server replied with an unexpected response.');
76+
77+
$api->update(5, []);
78+
}
5579
}

0 commit comments

Comments
 (0)