2013-02-05 01:16:29 +05:30
|
|
|
<?php
|
|
|
|
|
2014-05-03 15:25:25 +05:30
|
|
|
namespace LeagueTests\util;
|
2014-01-16 22:20:30 +05:30
|
|
|
|
2014-11-08 23:56:12 +05:30
|
|
|
use League\OAuth2\Server\Util\SecureKey;
|
2014-01-16 22:20:30 +05:30
|
|
|
|
|
|
|
class SecureKeyTest extends \PHPUnit_Framework_TestCase
|
2013-02-05 01:16:29 +05:30
|
|
|
{
|
2014-05-03 15:25:25 +05:30
|
|
|
public function testGenerate()
|
2014-04-07 01:38:35 +05:30
|
|
|
{
|
|
|
|
$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)
|
2014-11-08 23:56:12 +05:30
|
|
|
->will($this->returnValue($result));
|
2014-04-07 01:38:35 +05:30
|
|
|
|
|
|
|
SecureKey::setAlgorithm($algorithm);
|
|
|
|
$this->assertSame($algorithm, SecureKey::getAlgorithm());
|
|
|
|
$this->assertEquals($result, SecureKey::generate(11));
|
|
|
|
}
|
2014-05-03 15:25:25 +05:30
|
|
|
}
|