oauth2-server/tests/unit/util/SecureKeyTest.php

36 lines
972 B
PHP
Raw Normal View History

2013-02-04 19:46:29 +00:00
<?php
2014-05-03 10:55:25 +01:00
namespace LeagueTests\util;
2014-01-16 16:50:30 +00:00
2014-11-08 18:26:12 +00:00
use League\OAuth2\Server\Util\SecureKey;
2014-01-16 16:50:30 +00:00
class SecureKeyTest extends \PHPUnit_Framework_TestCase
2013-02-04 19:46:29 +00:00
{
2014-05-03 10:55:25 +01:00
public function testGenerate()
2014-04-06 21:08:35 +01:00
{
$v1 = SecureKey::generate();
$v2 = SecureKey::generate();
$v3 = SecureKey::generate(50);
2013-02-04 19:46:29 +00:00
2014-04-06 21:08:35 +01:00
$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 18:26:12 +00:00
->will($this->returnValue($result));
2014-04-06 21:08:35 +01:00
SecureKey::setAlgorithm($algorithm);
$this->assertSame($algorithm, SecureKey::getAlgorithm());
$this->assertEquals($result, SecureKey::generate(11));
}
2014-05-03 10:55:25 +01:00
}