forked from fillup/guzzle-services
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing command exception throwing, fixing validating additionalParame…
…ters, adding validation tests. Closes guzzle#43
- Loading branch information
Showing
7 changed files
with
137 additions
and
11 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.idea | ||
.DS_STORE | ||
coverage | ||
phpunit.xml | ||
composer.lock | ||
vendor/ | ||
artifacts/ |
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,15 @@ | ||
all: clean test | ||
|
||
test: | ||
vendor/bin/phpunit | ||
|
||
coverage: | ||
vendor/bin/phpunit --coverage-html=artifacts/coverage | ||
|
||
view-coverage: | ||
open artifacts/coverage/index.html | ||
|
||
clean: | ||
rm -rf artifacts/* | ||
|
||
.PHONY: coverage |
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,114 @@ | ||
<?php | ||
|
||
namespace GuzzleHttp\Tests\Command\Guzzle; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Command\Guzzle\GuzzleClient; | ||
use GuzzleHttp\Command\CommandTransaction; | ||
use GuzzleHttp\Command\Guzzle\Description; | ||
use GuzzleHttp\Command\Guzzle\Subscriber\ValidateInput; | ||
use GuzzleHttp\Command\Event\PrepareEvent; | ||
|
||
/** | ||
* @covers GuzzleHttp\Command\Guzzle\Subscriber\ValidateInput | ||
*/ | ||
class ValidateInputTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @expectedException \GuzzleHttp\Command\Exception\CommandException | ||
* @expectedExceptionMessage Validation errors: [bar] is a required string | ||
*/ | ||
public function testValidates() | ||
{ | ||
$description = new Description([ | ||
'operations' => [ | ||
'foo' => [ | ||
'uri' => 'http://httpbin.org', | ||
'httpMethod' => 'GET', | ||
'responseModel' => 'j', | ||
'parameters' => [ | ||
'bar' => [ | ||
'type' => 'string', | ||
'required' => true | ||
] | ||
] | ||
] | ||
] | ||
]); | ||
|
||
$client = new GuzzleClient(new Client(), $description); | ||
$val = new ValidateInput(); | ||
$event = new PrepareEvent(new CommandTransaction( | ||
$client, | ||
$client->getCommand('foo') | ||
)); | ||
$val->onPrepare($event); | ||
} | ||
|
||
/** | ||
* @expectedException \RuntimeException | ||
* @expectedExceptionMessage is not a GuzzleHttp\Command\Guzzle\GuzzleCommandInterface | ||
*/ | ||
public function testEnsuresCorrectCommandType() | ||
{ | ||
$val = new ValidateInput(); | ||
$client = $this->getMockBuilder('GuzzleHttp\Command\ServiceClientInterface') | ||
->getMockForAbstractClass(); | ||
$command = $this->getMockBuilder('GuzzleHttp\Command\CommandInterface') | ||
->getMockForAbstractClass(); | ||
$val->onPrepare(new PrepareEvent(new CommandTransaction( | ||
$client, | ||
$command | ||
))); | ||
} | ||
|
||
public function testSuccessfulValidationDoesNotThrow() | ||
{ | ||
$description = new Description([ | ||
'operations' => [ | ||
'foo' => [ | ||
'uri' => 'http://httpbin.org', | ||
'httpMethod' => 'GET', | ||
'responseModel' => 'j', | ||
'parameters' => [] | ||
] | ||
] | ||
]); | ||
|
||
$client = new GuzzleClient(new Client(), $description); | ||
$val = new ValidateInput(); | ||
$event = new PrepareEvent(new CommandTransaction( | ||
$client, | ||
$client->getCommand('foo') | ||
)); | ||
$val->onPrepare($event); | ||
} | ||
|
||
/** | ||
* @expectedException \GuzzleHttp\Command\Exception\CommandException | ||
* @expectedExceptionMessage Validation errors: [bar] must be of type string | ||
*/ | ||
public function testValidatesAdditionalParameters() | ||
{ | ||
$description = new Description([ | ||
'operations' => [ | ||
'foo' => [ | ||
'uri' => 'http://httpbin.org', | ||
'httpMethod' => 'GET', | ||
'responseModel' => 'j', | ||
'additionalParameters' => [ | ||
'type' => 'string' | ||
] | ||
] | ||
] | ||
]); | ||
|
||
$client = new GuzzleClient(new Client(), $description); | ||
$val = new ValidateInput(); | ||
$event = new PrepareEvent(new CommandTransaction( | ||
$client, | ||
$client->getCommand('foo', ['bar' => new \stdClass()]) | ||
)); | ||
$val->onPrepare($event); | ||
} | ||
} |