Use Interfaces anywhere.

In practice, there were still too many concrete classes, which makes
integration into a framework hard. To overcome this, the codebase has
been refactored to use Interfaces when a resource is needed.

All necessary Interfaces have been created, and the existing concrete
classes now implement these interfaces.
This commit is contained in:
Jacob Kiers
2013-02-11 14:02:14 +00:00
parent 4e6cc6c811
commit 8bd355f556
23 changed files with 514 additions and 324 deletions

View File

@@ -1,20 +0,0 @@
<?php
use JacobKiers\OAuth\Client;
class ClientTest extends PHPUnit_Framework_TestCase
{
public function testKeyAndSecretAreSet()
{
$client = new Client('foo', 'bar');
$this->assertEquals('foo', $client->getKey());
$this->assertEquals('bar', $client->getSecret());
}
public function testCallbackUrlIsSet()
{
$client = new Client('foo', 'bar', 'http://example.com/foobar');
$this->assertEquals('http://example.com/foobar', $client->getCallbackUrl());
}
}

20
tests/ConsumerTest.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
use JacobKiers\OAuth\Consumer\Consumer;
class ConsumerTest extends PHPUnit_Framework_TestCase
{
public function testKeyAndSecretAreSet()
{
$consumer = new consumer('foo', 'bar');
$this->assertEquals('foo', $consumer->getKey());
$this->assertEquals('bar', $consumer->getSecret());
}
public function testCallbackUrlIsSet()
{
$consumer = new consumer('foo', 'bar', 'http://example.com/foobar');
$this->assertEquals('http://example.com/foobar', $consumer->getCallbackUrl());
}
}

View File

@@ -1,7 +1,7 @@
<?php
use Mockery as m;
use JacobKiers\OAuth\HmacSha1;
use JacobKiers\OAuth\SignatureMethod\HmacSha1;
class HmacSha1Test extends PHPUnit_Framework_TestCase
{
@@ -23,7 +23,7 @@ public function testBuildSignatureWithoutToken()
// Get mock objects
$request = $this->getRequest();
$client = $this->getClient();
$client = $this->getConsumer();
// Run method being tested
$signature = $hmacsha1->buildSignature($request, $client);
@@ -39,7 +39,7 @@ public function testBuildSignatureWithToken()
// Get mock objects
$request = $this->getRequest();
$client = $this->getClient();
$client = $this->getConsumer();
$token = $this->getToken();
// Run method being tested
@@ -56,23 +56,23 @@ private function getSignatureMethod()
private function getRequest()
{
return m::mock('JacobKiers\OAuth\Request', function ($mock) {
return m::mock('JacobKiers\OAuth\Request\Request', function ($mock) {
$mock->shouldReceive('getOAuthSignatureBaseString')
->withNoArgs()
->andReturn('POST&http%3A%2F%2Fexample.com%2Ffoobar&oauth_signature_method%3DHMAC-SHA1')->once();
});
}
private function getClient()
private function getConsumer()
{
return m::mock('JacobKiers\OAuth\Client', function ($mock) {
return m::mock('JacobKiers\OAuth\Consumer\Consumer', function ($mock) {
$mock->shouldReceive('getSecret')->withNoArgs()->andReturn('secret')->once();
});
}
private function getToken()
{
return m::mock('JacobKiers\OAuth\Token', function ($mock) {
return m::mock('JacobKiers\OAuth\Token\Token', function ($mock) {
$mock->shouldReceive('getSecret')->withNoArgs()->andReturn('token_secret');
});
}

View File

@@ -1,7 +1,7 @@
<?php
use Mockery as m;
use JacobKiers\OAuth\PlainText;
use JacobKiers\OAuth\SignatureMethod\PlainText;
class PlainTextTest extends PHPUnit_Framework_TestCase
{
@@ -23,7 +23,7 @@ public function testBuildSignatureWithoutToken()
// Get mock objects
$request = $this->getRequest();
$client = $this->getClient();
$client = $this->getConsumer();
// Run method being tested
$signature = $plaintext->buildSignature($request, $client);
@@ -39,7 +39,7 @@ public function testBuildSignatureWithToken()
// Get mock objects
$request = $this->getRequest();
$client = $this->getClient();
$client = $this->getConsumer();
$token = $this->getToken();
// Run method being tested
@@ -56,19 +56,19 @@ private function getSignatureMethod()
private function getRequest()
{
return m::mock('JacobKiers\OAuth\Request');
return m::mock('JacobKiers\OAuth\Request\Request');
}
private function getClient()
private function getConsumer()
{
return m::mock('JacobKiers\OAuth\Client', function ($mock) {
return m::mock('JacobKiers\OAuth\Consumer\Consumer', function ($mock) {
$mock->shouldReceive('getSecret')->withNoArgs()->andReturn('secret')->once();
});
}
private function getToken()
{
return m::mock('JacobKiers\OAuth\Token', function ($mock) {
return m::mock('JacobKiers\OAuth\Token\Token', function ($mock) {
$mock->shouldReceive('getSecret')->withNoArgs()->andReturn('token_secret');
});
}

View File

@@ -1,7 +1,7 @@
<?php
use Mockery as m;
use JacobKiers\OAuth\Request;
use JacobKiers\OAuth\Request\Request;
class RequestTest extends PHPUnit_Framework_TestCase
{

View File

@@ -1,7 +1,7 @@
<?php
use Mockery as m;
use JacobKiers\OAuth\SignatureMethod;
use JacobKiers\OAuth\SignatureMethod\SignatureMethod;
/**
* Create concrete class from abstract SignatureMethod.
@@ -14,9 +14,9 @@ public function getName() {
}
public function buildSignature(
\JacobKiers\OAuth\RequestInterface $request,
\JacobKiers\OAuth\Client $client,
\JacobKiers\OAuth\Token $token = null
\JacobKiers\OAuth\Request\RequestInterface $request,
\JacobKiers\OAuth\Consumer\ConsumerInterface $consumer,
\JacobKiers\OAuth\Token\TokenInterface $token = null
) {
}
}
@@ -34,10 +34,10 @@ public function testGetSignatureKeyWithoutToken()
$signature_method = $this->getSignatureMethod();
// Get mock objects
$client = $this->getClient();
$consumer = $this->getConsumer();
// Run method being tested
$signature_key = $signature_method->getSignatureKey($client);
$signature_key = $signature_method->getSignatureKey($consumer);
// Check results
$this->assertEquals('secret&', $signature_key);
@@ -49,11 +49,11 @@ public function testGetSignatureKeyWithToken()
$signature_method = $this->getSignatureMethod();
// Get mock objects
$client = $this->getClient();
$consumer = $this->getConsumer();
$token = $this->getToken();
// Run method being tested
$signature_key = $signature_method->getSignatureKey($client, $token);
$signature_key = $signature_method->getSignatureKey($consumer, $token);
// Check results
$this->assertEquals('secret&token_secret', $signature_key);
@@ -64,16 +64,16 @@ private function getSignatureMethod()
return new FooBarSignatureMethod;
}
private function getClient()
private function getConsumer()
{
return m::mock('JacobKiers\OAuth\Client', function ($mock) {
return m::mock('JacobKiers\OAuth\Consumer\Consumer', function ($mock) {
$mock->shouldReceive('getSecret')->withNoArgs()->andReturn('secret')->once();
});
}
private function getToken()
{
return m::mock('JacobKiers\OAuth\Token', function ($mock) {
return m::mock('JacobKiers\OAuth\Token\Token', function ($mock) {
$mock->shouldReceive('getSecret')->withNoArgs()->andReturn('token_secret');
});
}

View File

@@ -1,7 +1,7 @@
<?php
use JacobKiers\OAuth\Token;
use JacobKiers\OAuth\NullToken;
use JacobKiers\OAuth\Token\Token;
use JacobKiers\OAuth\Token\NullToken;
use JacobKiers\OAuth\Util;
class TokenTest extends PHPUnit_Framework_TestCase