Skip to content

Commit 4cfdace

Browse files
authored
Merge pull request #3 from php-api-clients/tests
Tests
2 parents 15515d2 + de55ff7 commit 4cfdace

File tree

8 files changed

+203
-2
lines changed

8 files changed

+203
-2
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"psr/http-message": "^1.0"
1717
},
1818
"require-dev": {
19+
"guzzlehttp/psr7": "^1.3",
1920
"humbug/humbug": "1.0.0-alpha2",
2021
"phpunit/phpunit": "^5.5 || ^4.8",
2122
"squizlabs/php_codesniffer": "^2.6"

composer.lock

Lines changed: 60 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Definition/AccessTokenTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace ApiClients\Tests\Tools\Psr7\Oauth1\Definition;
4+
5+
use ApiClients\Tools\Psr7\Oauth1\Definition\AccessToken;
6+
7+
class AccessTokenTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testAccessToken()
10+
{
11+
$token = 'token';
12+
$accessToken = new AccessToken($token);
13+
$this->assertSame($token, $accessToken->getAccessToken());
14+
$this->assertSame($token, $accessToken->getToken());
15+
$this->assertSame($token, (string)$accessToken);
16+
}
17+
}

tests/Definition/ConsumerKeyTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace ApiClients\Tests\Tools\Psr7\Oauth1\Definition;
4+
5+
use ApiClients\Tools\Psr7\Oauth1\Definition\ConsumerKey;
6+
7+
class ConsumerKeyTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testAccessToken()
10+
{
11+
$key = 'key';
12+
$consumerKey = new ConsumerKey($key);
13+
$this->assertSame($key, $consumerKey->getConsumerKey());
14+
$this->assertSame($key, (string)$consumerKey);
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace ApiClients\Tests\Tools\Psr7\Oauth1\Definition;
4+
5+
use ApiClients\Tools\Psr7\Oauth1\Definition\ConsumerSecret;
6+
7+
class ConsumerSecretTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testAccessToken()
10+
{
11+
$key = 'key';
12+
$consumerSecret = new ConsumerSecret($key);
13+
$this->assertSame($key, $consumerSecret->getConsumerSecret());
14+
$this->assertSame($key, (string)$consumerSecret);
15+
}
16+
}

tests/Definition/RequestTokenTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace ApiClients\Tests\Tools\Psr7\Oauth1\Definition;
4+
5+
use ApiClients\Tools\Psr7\Oauth1\Definition\RequestToken;
6+
7+
class RequestTokenTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testAccessToken()
10+
{
11+
$token = 'token';
12+
$requestToken = new RequestToken($token);
13+
$this->assertSame($token, $requestToken->getRequestToken());
14+
$this->assertSame($token, $requestToken->getToken());
15+
$this->assertSame($token, (string)$requestToken);
16+
}
17+
}

tests/Definition/TokenSecretTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace ApiClients\Tests\Tools\Psr7\Oauth1\Definition;
4+
5+
use ApiClients\Tools\Psr7\Oauth1\Definition\TokenSecret;
6+
7+
class TokenSecretTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testAccessToken()
10+
{
11+
$token = 'tokenSecret';
12+
$tokenSecret = new TokenSecret($token);
13+
$this->assertSame($token, $tokenSecret->getTokenSecret());
14+
$this->assertSame($token, (string)$tokenSecret);
15+
}
16+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace ApiClients\Tests\Tools\Psr7\Oauth1\Signature;
4+
5+
use ApiClients\Tools\Psr7\Oauth1\Definition\ConsumerSecret;
6+
use ApiClients\Tools\Psr7\Oauth1\Definition\TokenSecret;
7+
use ApiClients\Tools\Psr7\Oauth1\Signature\HmacSha1Signature;
8+
use GuzzleHttp\Psr7\Uri;
9+
use Psr\Http\Message\UriInterface;
10+
11+
class HmacSha1SignatureTest extends \PHPUnit_Framework_TestCase
12+
{
13+
public function testGetMethod()
14+
{
15+
$this->assertSame('HMAC-SHA1', (new HmacSha1Signature(new ConsumerSecret('secret')))->getMethod());
16+
}
17+
18+
public function provideSign()
19+
{
20+
return [
21+
[
22+
new Uri('https://example.com/'),
23+
'T7pWk5I7re3JTz5FS3LK8rVbQ0U=',
24+
'uRcxk5ukl+O0nSa9PgMEoIvOQ+M=',
25+
],
26+
[
27+
new Uri('https://example.com/thea.pot',[], 'THEAPOT'),
28+
'XyTxyDmU2s3iBMBpSX4DbZ47Ltg=',
29+
'H6aCWT5WcUlqw4/qXVm4tMjE7P0=',
30+
],
31+
[
32+
new Uri('https://example.com/?foo=bar', ['foo' => 'bar',]),
33+
'OXZBqYIhLdj7CT6bYudGqc8OzlU=',
34+
'3oA2qaA8dpQFdB8n0tyjrXLNvsg=',
35+
],
36+
[
37+
new Uri('https://example.com/',['foo' => 'bar',], 'HEAD'),
38+
'T7pWk5I7re3JTz5FS3LK8rVbQ0U=',
39+
'uRcxk5ukl+O0nSa9PgMEoIvOQ+M=',
40+
],
41+
];
42+
}
43+
44+
/**
45+
* @param UriInterface $uri
46+
* @param $signedSignature
47+
* @dataProvider provideSign
48+
*/
49+
public function testSign(UriInterface $uri, $signedSignature, $signedTokenSecretSignature)
50+
{
51+
$secret = new ConsumerSecret('consumerSecret');
52+
$signature = new HmacSha1Signature($secret);
53+
$tokenSecret = new TokenSecret('tokenSecret');
54+
$this->assertSame($signedSignature, $signature->sign($uri));
55+
$signature = $signature->withTokenSecret($tokenSecret);
56+
$this->assertSame($signedTokenSecretSignature, $signature->sign($uri));
57+
$signature = $signature->withoutTokenSecret();
58+
$this->assertSame($signedSignature, $signature->sign($uri));
59+
}
60+
}

0 commit comments

Comments
 (0)