Skip to content

Commit

Permalink
Merge pull request #41 from ker0x/feature/refactor
Browse files Browse the repository at this point in the history
[n/a] Remove method camelize from UtilityTrait, improve tests
  • Loading branch information
ker0x authored Mar 20, 2017
2 parents dc03182 + e446c21 commit 46a7fdf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
12 changes: 0 additions & 12 deletions src/Helper/UtilityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@
trait UtilityTrait
{

/**
* Returns the input lower_case_delimited_string as a CamelCasedString.
*
* @param string $string String to be camelize
* @param string $delimiter The delimiter in the input string
* @return string
*/
public function camelize(string $string, string $delimiter = '_'): string
{
return implode('', array_map('ucfirst', array_map('strtolower', explode($delimiter, $string))));
}

/**
* Enhanced version of array_filter which allow to filter recursively
*
Expand Down
14 changes: 6 additions & 8 deletions src/Model/Message/Attachment/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,15 @@ private function isAttachmentId($value): bool
*/
public function jsonSerialize(): array
{
$payload = [
'url' => $this->url,
'is_reusable' => $this->reusable,
'attachment_id' => $this->attachmentId,
];

$json = parent::jsonSerialize();
$json += [
'payload' => array_filter($payload),
'payload' => [
'url' => $this->url,
'is_reusable' => $this->reusable,
'attachment_id' => $this->attachmentId,
],
];

return $json;
return $this->arrayFilter($json);
}
}
2 changes: 2 additions & 0 deletions tests/Mocks/Message/Template/airline_boardingpass.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
],
"logo_image_url": "https://www.example.com/en/logo.png",
"header_image_url": "https://www.example.com/en/fb/header.png",
"header_text_field": "Boarding Pass",
"qr_code": "M1SMITH NICOLAS CG4X7U nawouehgawgnapwi3jfa0wfh",
"above_bar_code_image_url": "https://www.example.com/en/PLAT.png",
"flight_info": {
Expand Down Expand Up @@ -96,6 +97,7 @@
],
"logo_image_url": "https://www.example.com/en/logo.png",
"header_image_url": "https://www.example.com/en/fb/header.png",
"header_text_field": "Boarding Pass",
"qr_code": "M1JONES FARBOUND CG4X7U nawouehgawgnapwi3jfa0wfh",
"above_bar_code_image_url": "https://www.example.com/en/PLAT.png",
"flight_info": {
Expand Down
6 changes: 4 additions & 2 deletions tests/TestCase/Model/Message/Attachment/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public function testTemplateAirlineBoardingPass()
->addSecondaryFields('Gate', 'D57')
->addSecondaryFields('Seat', '74J')
->addSecondaryFields('Sec.Nr.', '003')
->setHeaderImageUrl('https://www.example.com/en/fb/header.png');
->setHeaderImageUrl('https://www.example.com/en/fb/header.png')
->setHeaderTextField('Boarding Pass');


$boardingPass2 = new BoardingPass('Jones Farbound', 'CG4X7U', 'https://www.example.com/en/logo.png', 'M1JONES FARBOUND CG4X7U nawouehgawgnapwi3jfa0wfh', 'https://www.example.com/en/PLAT.png', $flightInfo);
Expand All @@ -62,7 +63,8 @@ public function testTemplateAirlineBoardingPass()
->addSecondaryFields('Gate', 'D57')
->addSecondaryFields('Seat', '74K')
->addSecondaryFields('Sec.Nr.', '004')
->setHeaderImageUrl('https://www.example.com/en/fb/header.png');
->setHeaderImageUrl('https://www.example.com/en/fb/header.png')
->setHeaderTextField('Boarding Pass');;

$boardingPass = [
$boardingPass1,
Expand Down
11 changes: 11 additions & 0 deletions tests/TestCase/Response/SendResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,15 @@ public function testResponseWithError()
$this->assertEquals(1234567, $sendResponse->getErrorSubcode());
$this->assertEquals('BLBz/WZt8dN', $sendResponse->getErrorFbtraceId());
}

public function testRawResponse()
{
$body = file_get_contents(__DIR__ . '/../../Mocks/Response/Send/basic.json');

$response = new Response(200, [], $body);
$sendResponse = new SendResponse($response);

$this->assertEquals(200, $sendResponse->getResponse()->getStatusCode());
$this->assertEquals($body, $sendResponse->getResponse()->getBody());
}
}

0 comments on commit 46a7fdf

Please sign in to comment.