-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
172 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
language: php | ||
|
||
php: | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
|
||
before_script: | ||
- curl -s http://getcomposer.org/installer | php | ||
- php composer.phar update --prefer-dist | ||
|
||
script: bin/phpspec run -fpretty --verbose | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache |
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,58 @@ | ||
<?php | ||
|
||
namespace Nixilla\Api\LoggerBundle\Twig; | ||
|
||
class CurlFormatter extends \Twig_Extension | ||
{ | ||
public function getName() | ||
{ | ||
return 'nixilla_api_logger'; | ||
} | ||
|
||
public function getFilters() | ||
{ | ||
return array( | ||
new \Twig_SimpleFilter('format_curl_command', array($this, 'formatForCurl')) | ||
); | ||
} | ||
|
||
public function formatForCurl(array $singleCall) | ||
{ | ||
return sprintf( | ||
'curl -v -X %s%s %s/%s%s', | ||
$singleCall['method'], | ||
$this->generateHeaders($singleCall['request_headers']), | ||
$singleCall['host'], | ||
$singleCall['path'], | ||
$this->formatParams($singleCall) | ||
); | ||
} | ||
|
||
private function generateHeaders($request_headers) | ||
{ | ||
$output = ''; | ||
|
||
foreach($request_headers as $value) | ||
{ | ||
$output .= sprintf(' -H "%s"', $value); | ||
} | ||
|
||
return $output; | ||
} | ||
|
||
private function formatParams($singleCall) | ||
{ | ||
if($singleCall['method'] != 'GET') | ||
{ | ||
foreach($singleCall['request_headers'] as $header) | ||
{ | ||
if($header == 'Content-Type: application/json') | ||
{ | ||
return sprintf(" --data '%s'", json_encode($singleCall['params'])); | ||
} | ||
} | ||
|
||
return sprintf(" --data '%s'", http_build_query($singleCall['params'])); | ||
} | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
spec/Nixilla/Api/LoggerBundle/NixillaApiLoggerBundleSpec.php
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,20 @@ | ||
<?php | ||
|
||
namespace spec\Nixilla\Api\LoggerBundle; | ||
|
||
use Nixilla\Api\LoggerBundle\NixillaApiLoggerBundle; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
class NixillaApiLoggerBundleSpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('Nixilla\Api\LoggerBundle\NixillaApiLoggerBundle'); | ||
} | ||
|
||
function it_should_be_a_bundle() | ||
{ | ||
$this->shouldHaveType('Symfony\Component\HttpKernel\Bundle\Bundle'); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace spec\Nixilla\Api\LoggerBundle\Twig; | ||
|
||
use Nixilla\Api\LoggerBundle\Twig\CurlFormatter; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
class CurlFormatterSpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('Nixilla\Api\LoggerBundle\Twig\CurlFormatter'); | ||
} | ||
|
||
function it_provides_Twig_filter_which_formats_input_into_curl_command() | ||
{ | ||
$this->formatForCurl([ | ||
'host' => 'http://endpoint', | ||
'path' => 'api/endoint', | ||
'method' => 'POST', | ||
'params' => ['foo' => 'bar', 'baz' => 1], | ||
'request_headers' => [ 'Authorization: Bearer lakdjfghalkdjfgh' ] | ||
])->shouldBeEqualTo("curl -v -X POST -H \"Authorization: Bearer lakdjfghalkdjfgh\" http://endpoint/api/endoint --data 'foo=bar&baz=1'"); | ||
|
||
$this->formatForCurl([ | ||
'host' => 'http://endpoint', | ||
'path' => 'api/endoint', | ||
'method' => 'PATCH', | ||
'params' => ['foo' => 'bar', 'baz' => ['key' => 'value']], | ||
'request_headers' => [ 'Authorization: Bearer lakdjfghalkdjfgh', 'Content-Type: application/json' ] | ||
])->shouldBeEqualTo("curl -v -X PATCH -H \"Authorization: Bearer lakdjfghalkdjfgh\" -H \"Content-Type: application/json\" http://endpoint/api/endoint --data '{\"foo\":\"bar\",\"baz\":{\"key\":\"value\"}}'"); | ||
} | ||
|
||
function it_has_a_name() | ||
{ | ||
$this->getName()->shouldNotReturn(null); | ||
} | ||
|
||
function it_has_required_getFilters_method() | ||
{ | ||
$this->getFilters()->shouldHaveCount(1); | ||
} | ||
} |