-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #395 from kbsali/320-add-support-for-updating-atta…
…chments-over-rest-api Add support for updating attachments
- Loading branch information
Showing
5 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace Redmine\Tests\Unit\Api\Attachment; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use Redmine\Api\Attachment; | ||
use Redmine\Exception\UnexpectedResponseException; | ||
use Redmine\Tests\Fixtures\AssertingHttpClient; | ||
|
||
#[CoversClass(Attachment::class)] | ||
class UpdateTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider getUpdateData | ||
*/ | ||
#[DataProvider('getUpdateData')] | ||
public function testUpdateReturnsCorrectResponse($id, array $params, $expectedPath, $expectedContent, $expectedReturn) | ||
{ | ||
$client = AssertingHttpClient::create( | ||
$this, | ||
[ | ||
'PUT', | ||
$expectedPath, | ||
'application/json', | ||
$expectedContent, | ||
204, | ||
'', | ||
'' | ||
] | ||
); | ||
|
||
// Create the object under test | ||
$api = new Attachment($client); | ||
|
||
// Perform the tests | ||
$this->assertSame($expectedReturn, $api->update($id, $params)); | ||
} | ||
|
||
public static function getUpdateData(): array | ||
{ | ||
return [ | ||
'test with all params' => [ | ||
5, | ||
[ | ||
'filename' => 'renamed.zip', | ||
'description' => 'updated', | ||
], | ||
'/attachments/5.json', | ||
'{"attachment":{"filename":"renamed.zip","description":"updated"}}', | ||
true, | ||
], | ||
]; | ||
} | ||
|
||
public function testUpdateThrowsUnexpectedResponseException() | ||
{ | ||
$client = AssertingHttpClient::create( | ||
$this, | ||
[ | ||
'PUT', | ||
'/attachments/5.json', | ||
'application/json', | ||
'{"attachment":[]}', | ||
403, | ||
'', | ||
'', | ||
] | ||
); | ||
|
||
$api = new Attachment($client); | ||
|
||
$this->expectException(UnexpectedResponseException::class); | ||
$this->expectExceptionMessage('The Redmine server replied with an unexpected response.'); | ||
|
||
$api->update(5, []); | ||
} | ||
} |