Fixed a few PRs and some cleanup (#589)

* fix for #581

* fix for #582

* Remove final

This will fix #584

* Type cast to string properly

* Convert to json string if needed

* cs
This commit is contained in:
Tobias Nyholm 2019-04-09 20:37:32 +02:00 committed by GitHub
parent ad67b4179c
commit c3ea40c94e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 19 deletions

View File

@ -100,7 +100,7 @@ class Member extends HttpApi
$params = [ $params = [
'address' => $address, 'address' => $address,
'name' => $name, 'name' => $name,
'vars' => $vars, 'vars' => \json_encode($vars),
'subscribed' => $subscribed ? 'yes' : 'no', 'subscribed' => $subscribed ? 'yes' : 'no',
'upsert' => $upsert ? 'yes' : 'no', 'upsert' => $upsert ? 'yes' : 'no',
]; ];
@ -144,19 +144,21 @@ class Member extends HttpApi
Assert::isArray($data); Assert::isArray($data);
foreach ($data as $field => $value) { foreach ($data as $field => &$value) {
switch ($field) { switch ($field) {
case 'address': case 'address':
Assert::stringNotEmpty($value); Assert::stringNotEmpty($value);
break; break;
case 'vars':
if (is_array($value)) {
$value = json_encode($value);
}
// We should assert that "vars"'s $value is a string.
// no break
case 'name': case 'name':
Assert::string($value); Assert::string($value);
break;
case 'vars':
Assert::isArray($value);
break; break;
case 'subscribed': case 'subscribed':
Assert::oneOf($value, ['yes', 'no']); Assert::oneOf($value, ['yes', 'no']);
@ -195,14 +197,16 @@ class Member extends HttpApi
foreach ($parameters as $field => $value) { foreach ($parameters as $field => $value) {
switch ($field) { switch ($field) {
case 'vars':
if (is_array($value)) {
$value = json_encode($value);
}
// We should assert that "vars"'s $value is a string.
// no break
case 'address': case 'address':
case 'name': case 'name':
Assert::stringNotEmpty($value); Assert::stringNotEmpty($value);
break;
case 'vars':
Assert::isArray($value);
break; break;
case 'subscribed': case 'subscribed':
Assert::oneOf($value, ['yes', 'no']); Assert::oneOf($value, ['yes', 'no']);

View File

@ -80,7 +80,7 @@ class Route extends HttpApi
Assert::isArray($actions); Assert::isArray($actions);
$params = [ $params = [
'priority' => $priority, 'priority' => (string) $priority,
'expression' => $expression, 'expression' => $expression,
'action' => $actions, 'action' => $actions,
'description' => $description, 'description' => $description,
@ -129,7 +129,7 @@ class Route extends HttpApi
} }
if (!empty($priority)) { if (!empty($priority)) {
$params['priority'] = $priority; $params['priority'] = (string) $priority;
} }
$response = $this->httpPut(sprintf('/v3/routes/%s', $routeId), $params); $response = $this->httpPut(sprintf('/v3/routes/%s', $routeId), $params);

View File

@ -53,7 +53,7 @@ class RequestBuilder
public function create(string $method, string $uri, array $headers = [], $body = null): RequestInterface public function create(string $method, string $uri, array $headers = [], $body = null): RequestInterface
{ {
if (!is_array($body)) { if (!is_array($body)) {
$stream = $this->getStreamFactory()->createStream($body); $stream = $this->getStreamFactory()->createStream((string) $body);
return $this->createRequest($method, $uri, $headers, $stream); return $this->createRequest($method, $uri, $headers, $stream);
} }

View File

@ -23,7 +23,7 @@ use Psr\Http\Client\ClientInterface;
/** /**
* This class is the base class for the Mailgun SDK. * This class is the base class for the Mailgun SDK.
*/ */
final class Mailgun class Mailgun
{ {
/** /**
* @var string|null * @var string|null

View File

@ -70,7 +70,7 @@ class MemberTest extends TestCase
$data = [ $data = [
'address' => 'foo@example.com', 'address' => 'foo@example.com',
'name' => 'Foo', 'name' => 'Foo',
'vars' => [], 'vars' => \json_encode([]),
'subscribed' => 'yes', 'subscribed' => 'yes',
'upsert' => 'no', 'upsert' => 'no',
]; ];
@ -162,9 +162,9 @@ class MemberTest extends TestCase
public function testUpdate() public function testUpdate()
{ {
$data = [ $data = [
'vars' => [ 'vars' => \json_encode([
'foo' => 'bar', 'foo' => 'bar',
], ]),
'subscribed' => 'yes', 'subscribed' => 'yes',
]; ];
@ -182,7 +182,7 @@ class MemberTest extends TestCase
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$data = [ $data = [
'vars' => 'foo=bar', 'vars' => 4711,
'subscribed' => 'yes', 'subscribed' => 'yes',
]; ];

View File

@ -63,7 +63,7 @@ class RouteTest extends TestCase
'expression' => 'catch_all()', 'expression' => 'catch_all()',
'action' => 'forward("mailbox@myapp.com")', 'action' => 'forward("mailbox@myapp.com")',
'description' => 'example', 'description' => 'example',
'priority' => 100, 'priority' => '100',
]); ]);
$api = $this->getApiInstance(); $api = $this->getApiInstance();