2013-02-05 01:16:29 +05:30
|
|
|
<?php
|
|
|
|
|
2014-01-16 22:20:30 +05:30
|
|
|
namespace LeagueTests\Util;
|
|
|
|
|
2014-04-07 01:38:35 +05:30
|
|
|
use \League\OAuth2\Server\Util\SecureKey;
|
2014-01-16 22:20:30 +05:30
|
|
|
use \Mockery as M;
|
|
|
|
|
|
|
|
class SecureKeyTest extends \PHPUnit_Framework_TestCase
|
2013-02-05 01:16:29 +05:30
|
|
|
{
|
2014-04-07 01:38:35 +05:30
|
|
|
function testGenerate()
|
|
|
|
{
|
|
|
|
$v1 = SecureKey::generate();
|
|
|
|
$v2 = SecureKey::generate();
|
|
|
|
$v3 = SecureKey::generate(50);
|
2013-02-05 01:16:29 +05:30
|
|
|
|
2014-04-07 01:38:35 +05:30
|
|
|
$this->assertEquals(40, strlen($v1));
|
|
|
|
$this->assertTrue($v1 !== $v2);
|
|
|
|
$this->assertEquals(50, strlen($v3));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGenerateWithDifferentAlgorithm()
|
|
|
|
{
|
|
|
|
$algorithm = $this->getMock('League\OAuth2\Server\Util\KeyAlgorithm\KeyAlgorithmInterface');
|
|
|
|
|
|
|
|
$result = 'dasdsdsaads';
|
|
|
|
$algorithm
|
|
|
|
->expects($this->once())
|
|
|
|
->method('generate')
|
|
|
|
->with(11)
|
|
|
|
->will($this->returnValue($result))
|
|
|
|
;
|
|
|
|
|
|
|
|
SecureKey::setAlgorithm($algorithm);
|
|
|
|
$this->assertSame($algorithm, SecureKey::getAlgorithm());
|
|
|
|
$this->assertEquals($result, SecureKey::generate(11));
|
|
|
|
}
|
2013-02-05 01:16:29 +05:30
|
|
|
}
|