Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
* release/1.2.0:
  Update Changelog
  Use command 1.1.0
  Remove HHVM from travis file
  Update .travis.yml
  Minimum php version fix
  Guzzle 7 support
  Fix the "weird" equal not operator
  Update changelog
  Update Changelog
  Use wire name when visiting array
  Add Unit Test which covers the regression
  Revert "Do not mutate command at validation"
  Adding descriptive error message on parameter failure
  • Loading branch information
Konafets committed Nov 13, 2020
2 parents 9e3abf2 + b3b9f3c commit 21e931a
Show file tree
Hide file tree
Showing 29 changed files with 145 additions and 143 deletions.
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
sudo: false

language: php

dist: trusty

php:
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm
- 7.3
- 7.4
- nightly

matrix:
fast_finish: true
allow_failures:
- php: 7.1
- php: hhvm
- php: nightly

before_script:
Expand Down
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change Log

## [1.2.0](https://github.com/guzzle/guzzle-services/tree/1.2.0) (2020-11-13)

[Full Changelog](https://github.com/guzzle/guzzle-services/compare/1.2.0...HEAD)

**Closed issues:**

- Fix weird "equal equal not" operator [\#154](https://github.com/guzzle/guzzle-services/issues/154)

**Merged pull requests:**

- Support Guzzle 7 [\#176](https://github.com/guzzle/guzzle-services/pull/176) ([ptlevi](https://github.com/ptlevi))

## [1.1.3](https://github.com/guzzle/guzzle-services/tree/1.1.3) (2017-10-06)

[Full Changelog](https://github.com/guzzle/guzzle-services/compare/1.1.2...HEAD)
Expand Down Expand Up @@ -348,4 +360,4 @@



\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
}
],
"require": {
"php": ">=5.5",
"guzzlehttp/guzzle": "^6.2",
"guzzlehttp/command": "~1.0"
"php": ">=7.3",
"guzzlehttp/guzzle": "^7.0.1",
"guzzlehttp/command": "^1.1.0",
"guzzlehttp/uri-template": "^0.2.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
"phpunit/phpunit": "~9.0"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 6 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<phpunit bootstrap="./vendor/autoload.php"
colors="true">
<testsuites>
<testsuite>
<testsuite name="Unit">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./app</directory>
</include>
</coverage>
</phpunit>
4 changes: 2 additions & 2 deletions src/GuzzleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function getDescription()
*/
private function getSerializer($commandToRequestTransformer)
{
return $commandToRequestTransformer ==! null
return $commandToRequestTransformer !== null
? $commandToRequestTransformer
: new Serializer($this->description);
}
Expand All @@ -114,7 +114,7 @@ private function getDeserializer($responseToResultTransformer)
{
$process = (! isset($this->config['process']) || $this->config['process'] === true);

return $responseToResultTransformer ==! null
return $responseToResultTransformer !== null
? $responseToResultTransformer
: new Deserializer($this->description, $process);
}
Expand Down
8 changes: 5 additions & 3 deletions src/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use GuzzleHttp\Command\Guzzle\RequestLocation\XmlLocation;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Uri;
use GuzzleHttp\Psr7\UriResolver;
use GuzzleHttp\UriTemplate\UriTemplate;
use Psr\Http\Message\RequestInterface;

/**
Expand Down Expand Up @@ -154,11 +156,11 @@ private function createCommandWithUri(
}

// Expand the URI template.
$uri = \GuzzleHttp\uri_template($operation->getUri(), $variables);
$uri = new Uri(UriTemplate::expand($operation->getUri(), $variables));

return new Request(
$operation->getHttpMethod(),
Uri::resolve($this->description->getBaseUri(), $uri)
$operation->getHttpMethod() ?: 'GET',
UriResolver::resolve($this->description->getBaseUri(), $uri)
);
}
}
18 changes: 7 additions & 11 deletions tests/DescriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
use GuzzleHttp\Command\Guzzle\Operation;
use GuzzleHttp\Command\Guzzle\Parameter;
use GuzzleHttp\Command\Guzzle\SchemaFormatter;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;

/**
* @covers \GuzzleHttp\Command\Guzzle\Description
*/
class DescriptionTest extends \PHPUnit_Framework_TestCase
class DescriptionTest extends TestCase
{
protected $operations;

public function setup()
public function setup(): void
{
$this->operations = [
'test_command' => [
Expand Down Expand Up @@ -65,11 +67,9 @@ public function testCanUseResponseClass()
$this->assertNotNull($op->getResponseModel());
}

/**
* @expectedException \InvalidArgumentException
*/
public function testRetrievingMissingModelThrowsException()
{
$this->expectException(InvalidArgumentException::class);
$d = new Description([]);
$d->getModel('foo');
}
Expand Down Expand Up @@ -105,20 +105,16 @@ public function testPersistsCustomAttributes()
$this->assertNull($d->getData('missing'));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testThrowsExceptionForMissingOperation()
{
$this->expectException(InvalidArgumentException::class);
$s = new Description([]);
$this->assertNull($s->getOperation('foo'));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testValidatesOperationTypes()
{
$this->expectException(InvalidArgumentException::class);
new Description([
'operations' => ['foo' => new \stdClass()]
]);
Expand Down
32 changes: 13 additions & 19 deletions tests/DeserializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Command\CommandInterface;
use GuzzleHttp\Command\Exception\CommandException;
use GuzzleHttp\Command\Guzzle\Description;
use GuzzleHttp\Command\Guzzle\DescriptionInterface;
use GuzzleHttp\Command\Guzzle\GuzzleClient;
Expand All @@ -13,20 +14,21 @@
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Tests\Command\Guzzle\Asset\Exception\CustomCommandException;
use GuzzleHttp\Tests\Command\Guzzle\Asset\Exception\OtherCustomCommandException;
use Predis\Response\ResponseInterface;
use PHPUnit\Framework\MockObject\MockBuilder;
use PHPUnit\Framework\TestCase;

/**
* @covers \GuzzleHttp\Command\Guzzle\Deserializer
*/
class DeserializerTest extends \PHPUnit_Framework_TestCase
class DeserializerTest extends TestCase
{
/** @var ServiceClientInterface|\PHPUnit_Framework_MockObject_MockObject */
/** @var ServiceClientInterface|MockBuilder */
private $serviceClient;

/** @var CommandInterface|\PHPUnit_Framework_MockObject_MockObject */
/** @var CommandInterface|MockBuilder */
private $command;

public function setUp()
public function setUp(): void
{
$this->serviceClient = $this->getMockBuilder(GuzzleClient::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -80,11 +82,9 @@ public function testDoNothingIfNoException()
$client->foo(['bar' => 'baz']);
}

/**
* @expectedException \GuzzleHttp\Tests\Command\Guzzle\Asset\Exception\CustomCommandException
*/
public function testCreateExceptionWithCode()
{
$this->expectException(CustomCommandException::class);
$response = new Response(404);
$mock = new MockHandler([$response]);

Expand Down Expand Up @@ -165,11 +165,9 @@ public function testNotCreateExceptionIfDoesNotMatchCode()
$client->foo(['bar' => 'baz']);
}

/**
* @expectedException \GuzzleHttp\Tests\Command\Guzzle\Asset\Exception\CustomCommandException
*/
public function testCreateExceptionWithExactMatchOfReasonPhrase()
{
$this->expectException(CustomCommandException::class);
$response = new Response(404, [], null, '1.1', 'Bar');
$mock = new MockHandler([$response]);

Expand Down Expand Up @@ -209,11 +207,9 @@ public function testCreateExceptionWithExactMatchOfReasonPhrase()
$client->foo(['bar' => 'baz']);
}

/**
* @expectedException \GuzzleHttp\Tests\Command\Guzzle\Asset\Exception\OtherCustomCommandException
*/
public function testFavourMostPreciseMatch()
{
$this->expectException(OtherCustomCommandException::class);
$response = new Response(404, [], null, '1.1', 'Bar');
$mock = new MockHandler([$response]);

Expand Down Expand Up @@ -254,12 +250,10 @@ public function testFavourMostPreciseMatch()
$client->foo(['bar' => 'baz']);
}

/**
* @expectedException \GuzzleHttp\Command\Exception\CommandException
* @expectedExceptionMessage 404
*/
public function testDoesNotAddResultWhenExceptionIsPresent()
{
$this->expectExceptionMessage("404");
$this->expectException(CommandException::class);
$description = new Description([
'operations' => [
'foo' => [
Expand Down Expand Up @@ -381,6 +375,6 @@ public function testReturnsExpectedResult()
'content' => 'OK'
]
];
$this->assertArraySubset($expected, $result['LoginResponse']);
$this->assertEquals($expected, $result['LoginResponse']);
}
}
43 changes: 19 additions & 24 deletions tests/GuzzleClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
* @covers \GuzzleHttp\Command\Guzzle\GuzzleClient
*/
class GuzzleClientTest extends \PHPUnit_Framework_TestCase
class GuzzleClientTest extends TestCase
{
public function testExecuteCommandViaMagicMethod()
{
Expand Down Expand Up @@ -179,8 +180,8 @@ public function testExecuteWithMultiPartLocation()

$client->doMultiPartLocation(['foo' => 'Foo']);
$multiPartRequestBody = (string) $mock->getLastRequest()->getBody();
$this->assertContains('name="foo"', $multiPartRequestBody);
$this->assertContains('Foo', $multiPartRequestBody);
$this->assertStringContainsString('name="foo"', $multiPartRequestBody);
$this->assertStringContainsString('Foo', $multiPartRequestBody);

$client->doMultiPartLocation([
'foo' => 'Foo',
Expand All @@ -189,20 +190,20 @@ public function testExecuteWithMultiPartLocation()
]);

$multiPartRequestBody = (string) $mock->getLastRequest()->getBody();
$this->assertContains('name="foo"', $multiPartRequestBody);
$this->assertContains('Foo', $multiPartRequestBody);
$this->assertContains('name="bar"', $multiPartRequestBody);
$this->assertContains('Bar', $multiPartRequestBody);
$this->assertContains('name="baz"', $multiPartRequestBody);
$this->assertContains('Baz', $multiPartRequestBody);
$this->assertStringContainsString('name="foo"', $multiPartRequestBody);
$this->assertStringContainsString('Foo', $multiPartRequestBody);
$this->assertStringContainsString('name="bar"', $multiPartRequestBody);
$this->assertStringContainsString('Bar', $multiPartRequestBody);
$this->assertStringContainsString('name="baz"', $multiPartRequestBody);
$this->assertStringContainsString('Baz', $multiPartRequestBody);

$client->doMultiPartLocation([
'file' => fopen(dirname(__FILE__) . '/Asset/test.html', 'r'),
]);
$multiPartRequestBody = (string) $mock->getLastRequest()->getBody();
$this->assertContains('name="file"', $multiPartRequestBody);
$this->assertContains('filename="test.html"', $multiPartRequestBody);
$this->assertContains('<title>Title</title>', $multiPartRequestBody);
$this->assertStringContainsString('name="file"', $multiPartRequestBody);
$this->assertStringContainsString('filename="test.html"', $multiPartRequestBody);
$this->assertStringContainsString('<title>Title</title>', $multiPartRequestBody);
}

public function testHasConfig()
Expand Down Expand Up @@ -342,12 +343,10 @@ public function testValidateDescription()
$this->assertEquals(200, $response->getStatusCode());
}

/**
* @expectedException \GuzzleHttp\Command\Exception\CommandException
* @expectedExceptionMessage Validation errors: [baz] is a required string: baz
*/
public function testValidateDescriptionFailsDueMissingRequiredParameter()
{
$this->expectExceptionMessage("Validation errors: [baz] is a required string: baz");
$this->expectException(\GuzzleHttp\Command\Exception\CommandException::class);
$client = new HttpClient();
$description = new Description(
[
Expand Down Expand Up @@ -421,12 +420,10 @@ public function testValidateDescriptionFailsDueMissingRequiredParameter()
$this->assertEquals(200, $result['statusCode']);
}

/**
* @expectedException \GuzzleHttp\Command\Exception\CommandException
* @expectedExceptionMessage Validation errors: [baz] must be of type integer
*/
public function testValidateDescriptionFailsDueTypeMismatch()
{
$this->expectExceptionMessage("Validation errors: [baz] must be of type integer");
$this->expectException(\GuzzleHttp\Command\Exception\CommandException::class);
$client = new HttpClient();
$description = new Description(
[
Expand Down Expand Up @@ -635,12 +632,10 @@ public function testMagicMethodExecutesCommands()
$this->assertEquals('foo', $guzzle->foo([]));
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage No operation found named Foo
*/
public function testThrowsWhenOperationNotFoundInDescription()
{
$this->expectExceptionMessage("No operation found named Foo");
$this->expectException(\InvalidArgumentException::class);
$client = new HttpClient();
$description = new Description([]);
$guzzle = new GuzzleClient(
Expand Down
Loading

0 comments on commit 21e931a

Please sign in to comment.