Skip to content

Commit

Permalink
Chore/fix body cleanup (#562)
Browse files Browse the repository at this point in the history
refactoring
  • Loading branch information
julianzimmermann authored Jul 10, 2024
1 parent ea6688a commit 8b2a8ed
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public function __construct(
public function buildDocumentResponse(
EasyApiResponseTransfer $easyApiClientResponseTransfer
): RestResponseInterface {
if ($easyApiClientResponseTransfer->getStatus() !== 'success' || $easyApiClientResponseTransfer->getHash() !== sha1($easyApiClientResponseTransfer->getData())) {
if (
$easyApiClientResponseTransfer->getStatus() !== 'success'
|| $easyApiClientResponseTransfer->getHash() !== sha1($easyApiClientResponseTransfer->getData())
) {
return $this->buildErrorRestResponse();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,27 @@ public function testBuildDocumentResponse(): void
$this->restResponseMock->expects(static::atLeastOnce())
->method('setStatus')
->with(Response::HTTP_OK)
->willReturn($this->restResponseMock);
->willReturnSelf();

$this->restResponseMock->expects(static::atLeastOnce())
->method('addResource')
->willReturnSelf();

$this->easyApiResponseTransferMock->expects(static::atLeastOnce())
->method('getStatus')
->willReturn('success');

$this->easyApiResponseTransferMock->expects(static::atLeastOnce())
->method('getStatusCode')
->willReturn(200);

$this->easyApiResponseTransferMock->expects(static::atLeastOnce())
->method('getHash')
->willReturn(sha1('test'));

$this->easyApiResponseTransferMock->expects(static::atLeastOnce())
->method('getData')
->willReturn('test');

static::assertEquals(
$this->restResponseMock,
Expand All @@ -99,21 +119,20 @@ public function testBuildDocumentResponse(): void
*/
public function testBuildErrorRestResponse(): void
{
$self = $this;
$this->restResourceBuilderMock->expects(static::atLeastOnce())
->method('createRestResponse')
->willReturn($this->restResponseMock);

$this->restResponseMock->expects(static::atLeastOnce())
->method('addError')
->with(
static::callback(
static function (RestErrorMessageTransfer $restErrorMessageTransfer) {
return $restErrorMessageTransfer->getCode() === (string)Response::HTTP_INTERNAL_SERVER_ERROR
&& $restErrorMessageTransfer->getDetail() === DocumentsRestApiConfig::ERROR_MESSAGE_UNEXPECTED
&& $restErrorMessageTransfer->getStatus() === Response::HTTP_INTERNAL_SERVER_ERROR;
},
),
)->willReturn($this->restResponseMock);
->willReturnCallback(static function (RestErrorMessageTransfer $restErrorMessageTransfer) use ($self) {
static::assertEquals((string)Response::HTTP_INTERNAL_SERVER_ERROR, $restErrorMessageTransfer->getCode());
static::assertEquals(DocumentsRestApiConfig::ERROR_MESSAGE_UNEXPECTED, $restErrorMessageTransfer->getDetail());
static::assertEquals(Response::HTTP_INTERNAL_SERVER_ERROR, $restErrorMessageTransfer->getStatus());

return $self->restResponseMock;
});

static::assertEquals(
$this->restResponseMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public function testExpand(): void
->method('getNaturalIdentifier')
->willReturn($idCustomer);

$this->documentRestRequestTransferMock->expects(static::atLeastOnce())
->method('setCustomerReference')
->willReturnSelf();

static::assertEquals(
$this->documentRestRequestTransferMock,
$this->expanderPlugin->expand($this->restRequestMock, $this->documentRestRequestTransferMock),
Expand Down

0 comments on commit 8b2a8ed

Please sign in to comment.