-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mudi Ugbowanko
committed
Aug 31, 2014
1 parent
5c6c323
commit 227c98d
Showing
5 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Renegare\Soauth; | ||
|
||
use Silex\Application; | ||
|
||
trait SoauthTestCaseTrait { | ||
|
||
public function createCredentials(array $overrides = []) { | ||
$attr = array_merge([ | ||
'accessCode' => 'valid-test-access-code=', | ||
'authCode' => 'valid-test-auth-code=', | ||
'clientId' => 1, | ||
'lifetime' => 3600, | ||
'refreshCode' => 'valid-test-refresh-code=', | ||
'username' => 'test@example.com' | ||
], $overrides); | ||
|
||
extract($attr); | ||
|
||
return new Credentials($authCode, $accessCode, $refreshCode, $lifetime, $clientId, $username); | ||
} | ||
|
||
public function saveCredentials(CredentialsInterface $credentials, $createdTime = null, Application $app) { | ||
if($app['soauth.test']) { | ||
$storage = $app['soauth.storage.handler.mock']; | ||
} else { | ||
$storage = $app['soauth.storage.handler']; | ||
} | ||
|
||
return $storage->save($credentials, $createdTime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Renegare\Soauth\Test; | ||
|
||
use Renegare\Soauth\Test\FlowTestCase; | ||
use Renegare\Soauth\SoauthTestCaseTrait; | ||
use Silex\Application; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class TestCaseTraitTest extends FlowTestCase { | ||
use SoauthTestCaseTrait; | ||
|
||
|
||
public function testCreateCredentials() { | ||
$credentials = $this->createCredentials(); | ||
|
||
$this->assertEquals([ | ||
'accessCode' => 'valid-test-access-code=', | ||
'authCode' => 'valid-test-auth-code=', | ||
'clientId' => 1, | ||
'lifetime' => 3600, | ||
'refreshCode' => 'valid-test-refresh-code=', | ||
'username' => 'test@example.com', | ||
], $credentials->toArray()); | ||
} | ||
|
||
public function testCreateCredentialsWithOverrides() { | ||
$credentials = $this->createCredentials([ | ||
'accessCode' => 'override-test-access-code=', | ||
'authCode' => 'override-test-auth-code=', | ||
'clientId' => 2, | ||
'lifetime' => 7200, | ||
'refreshCode' => 'override-test-refresh-code=', | ||
'username' => 'override@example.com', | ||
'extra.params' => 'have no effect!' | ||
]); | ||
|
||
$this->assertEquals([ | ||
'accessCode' => 'override-test-access-code=', | ||
'authCode' => 'override-test-auth-code=', | ||
'clientId' => 2, | ||
'lifetime' => 7200, | ||
'refreshCode' => 'override-test-refresh-code=', | ||
'username' => 'override@example.com' | ||
], $credentials->toArray()); | ||
} | ||
|
||
public function testStoreCredentials() { | ||
$app = $this->createApplication(); | ||
|
||
// using the storage handler | ||
$credentials = $this->createCredentials(); | ||
$mockStorage = $this->getMock('Renegare\Soauth\StorageHandlerInterface'); | ||
$mockStorage->expects($this->once())->method('save') | ||
->with($this->equalTo($credentials), $this->equalTo(null)); | ||
$app['soauth.test'] = false; | ||
$app['soauth.storage.handler'] = $mockStorage; | ||
$this->saveCredentials($credentials, null, $app); | ||
|
||
// using mock | ||
$time = strtotime('-1 hour'); | ||
$credentials = $this->createCredentials(); | ||
$mockStorage = $this->getMock('Renegare\Soauth\StorageHandlerInterface'); | ||
$mockStorage->expects($this->once())->method('save') | ||
->with($this->equalTo($credentials), $this->equalTo($time)); | ||
$app['soauth.test'] = true; | ||
$app['soauth.storage.handler.mock'] = $mockStorage; | ||
$this->saveCredentials($credentials, $time, $app); | ||
} | ||
} |