Skip to content

Commit

Permalink
passing_additional_information_to_service_response
Browse files Browse the repository at this point in the history
  • Loading branch information
r-kujawa committed Mar 25, 2024
1 parent 9b58865 commit baf4e15
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
10 changes: 8 additions & 2 deletions tests/Services/Mock/FakeMockRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@

class FakeMockRequest extends ServiceRequest implements MockRequester
{
public function getIdentity()
public function getIdentity($withAdditionalInformation = false)
{
return [];
$response = [];

if ($withAdditionalInformation) {
$response = $this->response($response)->with('additional information');
}

return $response;
}
}
2 changes: 1 addition & 1 deletion tests/Services/Mock/FakeMockResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public function getStatusDescription()

public function getIdentityResponse()
{
return 'Fake';
return 'Fake' . (is_null($this->additionalInformation) ? '' : ' with ' . $this->additionalInformation);
}
}
10 changes: 8 additions & 2 deletions tests/Services/Mock/TestMockRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@

class TestMockRequest extends ServiceRequest implements MockRequester
{
public function getIdentity()
public function getIdentity($withAdditionalInformation = false)
{
return [];
$response = [];

if ($withAdditionalInformation) {
$response = $this->response($response)->with('additional information');
}

return $response;
}
}
2 changes: 1 addition & 1 deletion tests/Services/Mock/TestMockResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public function getStatusDescription()

public function getIdentityResponse()
{
return 'Real';
return 'Real' . (is_null($this->additionalInformation) ? '' : ' with ' . $this->additionalInformation);
}
}
10 changes: 10 additions & 0 deletions tests/Unit/TestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ public function calling_undefined_method_on_service_throws_bad_method_call_excep
});
}

/** @test */
public function passing_additional_information_to_service_response()
{
$this->assertRealIsAlignedWithFake(function () {
$response = $this->service->getIdentity(true);

$this->assertStringEndsWith('additional information', $response->data);
});
}

protected function assertResponseIsConfigured(ServiceResponse $response)
{
$this->assertEquals($this->providable->getId(), $response->provider->getId());
Expand Down

0 comments on commit baf4e15

Please sign in to comment.