Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Tests: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Dec 17, 2015
1 parent f244d18 commit 65b254f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/GopaySimple.php
Expand Up @@ -165,7 +165,7 @@ protected function makeRequest($method, $endpoint, $args = [])
break;

default:
throw new GopayException("Unsupported HTTP method ($method)", NULL, $args);
throw new GopayException("Unsupported HTTP method ($method)", 0, NULL, $args);
}

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
Expand Down
3 changes: 3 additions & 0 deletions tests/buildin/server.php
Expand Up @@ -15,6 +15,9 @@
case 'token':
echo @json_encode(['access_token' => 'foobar-token']);
break;
case 'fail':
exit(0);
break;
default:
echo @json_encode(['errors' => [0 => ['error_code' => 1, 'scope' => 'S', 'field' => 'S', 'message' => 'failed mocking']]]);
}
35 changes: 35 additions & 0 deletions tests/cases/GopaySimple.api.phpt
Expand Up @@ -4,6 +4,7 @@
* Test: Markette/GopaySimple/GopaySimple (API)
*/

use Markette\GopaySimple\GopayException;
use Markette\GopaySimple\GopaySimple;
use Tester\Assert;

Expand Down Expand Up @@ -34,6 +35,19 @@ final class ApiGopay extends GopaySimple
return $this->call($method, $endpoint, $args);
}

public function doError()
{
$this->args = ['type' => 'error'];
$this->token = (object)['access_token' => 'foobar'];
return $this->call('GET', 'invalid');
}

public function doFail()
{
$this->args = ['type' => 'fail'];
return $this->call('GET', 'invalid');
}

protected function getEndpoint($type = NULL)
{
return PHP_SERVER . '/server.php?' . http_build_query($this->args);
Expand All @@ -60,3 +74,24 @@ test(function () {

Assert::equal('payments/payment/12345', $response->uri);
});

test(function () {
Assert::throws(function () {
$gopay = new ApiGopay('foo', 'bar');
$gopay->doApiToken('FOOBAR', 'invalid');
}, GopayException::class);
});

test(function () {
Assert::throws(function () {
$gopay = new ApiGopay('foo', 'bar');
$gopay->doError();
}, GopayException::class);
});

test(function () {
Assert::throws(function () {
$gopay = new ApiGopay('foo', 'bar');
$gopay->doFail();
}, GopayException::class, "Authorization failed (" . PHP_SERVER . "/server.php?type=fail)%a%");
});
27 changes: 27 additions & 0 deletions tests/cases/GopaySimple.authentication.phpt
Expand Up @@ -4,6 +4,7 @@
* Test: Markette/GopaySimple/GopaySimple (AUTHENTICATION)
*/

use Markette\GopaySimple\GopayException;
use Markette\GopaySimple\GopaySimple;
use Tester\Assert;

Expand All @@ -21,6 +22,18 @@ final class AuthGopay extends GopaySimple
return $this->authenticate(['scope' => 'test']);
}

public function doError()
{
$this->args = ['type' => 'error'];
return $this->authenticate(['scope' => 'test']);
}

public function doFail()
{
$this->args = ['type' => 'fail'];
return $this->authenticate(['scope' => 'test']);
}

protected function getEndpoint($type = NULL)
{
return PHP_SERVER . '/server.php?' . http_build_query($this->args);
Expand All @@ -41,3 +54,17 @@ test(function () {
Assert::equal('foo', $response->PHP_AUTH_USER);
Assert::equal('bar', $response->PHP_AUTH_PW);
});

test(function () {
Assert::throws(function () {
$gopay = new AuthGopay('foo', 'bar');
$gopay->doError();
}, GopayException::class);
});

test(function () {
Assert::throws(function () {
$gopay = new AuthGopay('foo', 'bar');
$gopay->doFail();
}, GopayException::class, "Authorization failed (" . PHP_SERVER . "/server.php?type=fail)%a%");
});

0 comments on commit 65b254f

Please sign in to comment.