Add unit tests for signature methods, and a couple for Request.
This commit is contained in:
75
tests/PlainTextTest.php
Normal file
75
tests/PlainTextTest.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
use Mockery as m;
|
||||
use GaryJones\OAuth\PlainText;
|
||||
|
||||
class PlainTextTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function tearDown()
|
||||
{
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testSignatureName()
|
||||
{
|
||||
$plaintext = $this->getSignatureMethod();
|
||||
$this->assertEquals('PLAINTEXT', $plaintext->getName());
|
||||
}
|
||||
|
||||
public function testBuildSignatureWithoutToken()
|
||||
{
|
||||
// Create instance of class to test
|
||||
$plaintext = $this->getSignatureMethod();
|
||||
|
||||
// Get mock objects
|
||||
$request = $this->getRequest();
|
||||
$client = $this->getClient();
|
||||
|
||||
// Run method being tested
|
||||
$signature = $plaintext->buildSignature($request, $client);
|
||||
|
||||
// Check results
|
||||
$this->assertEquals('secret&', $signature);
|
||||
}
|
||||
|
||||
public function testBuildSignatureWithToken()
|
||||
{
|
||||
// Create instance of class to test
|
||||
$plaintext = $this->getSignatureMethod();
|
||||
|
||||
// Get mock objects
|
||||
$request = $this->getRequest();
|
||||
$client = $this->getClient();
|
||||
$token = $this->getToken();
|
||||
|
||||
// Run method being tested
|
||||
$signature = $plaintext->buildSignature($request, $client, $token);
|
||||
|
||||
// Check results
|
||||
$this->assertEquals('secret&token_secret', $signature);
|
||||
}
|
||||
|
||||
private function getSignatureMethod()
|
||||
{
|
||||
return new PlainText;
|
||||
}
|
||||
|
||||
private function getRequest()
|
||||
{
|
||||
return m::mock('GaryJones\OAuth\Request');
|
||||
}
|
||||
|
||||
private function getClient()
|
||||
{
|
||||
return m::mock('GaryJones\OAuth\Client', function ($mock) {
|
||||
$mock->shouldReceive('getSecret')->withNoArgs()->andReturn('secret')->once();
|
||||
});
|
||||
}
|
||||
|
||||
private function getToken()
|
||||
{
|
||||
return m::mock('GaryJones\OAuth\Token', function ($mock) {
|
||||
$mock->shouldReceive('getSecret')->withNoArgs()->andReturn('token_secret');
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user