-
Notifications
You must be signed in to change notification settings - Fork 4
/
FixedStorageTest.php
58 lines (46 loc) · 1.39 KB
/
FixedStorageTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
namespace Damax\Bundle\ApiAuthBundle\Tests\Key\Storage;
use Damax\Bundle\ApiAuthBundle\Key\Storage\FixedStorage;
use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFound;
use PHPUnit\Framework\TestCase;
class FixedStorageTest extends TestCase
{
/**
* @test
*/
public function it_checks_key_existence()
{
$storage = new FixedStorage(['john.doe' => 'ABC', 'jane.doe' => 'XYZ'], 600);
$this->assertTrue($storage->has('ABC'));
$this->assertTrue($storage->has('XYZ'));
$this->assertFalse($storage->has('123'));
return $storage;
}
/**
* @depends it_checks_key_existence
*
* @test
*/
public function it_retrieves_key(FixedStorage $storage)
{
$key = $storage->get('ABC');
$this->assertEquals('ABC', $key->key());
$this->assertEquals('john.doe', $key->identity());
$this->assertEquals(600, $key->ttl());
$key = $storage->get('XYZ');
$this->assertEquals('XYZ', $key->key());
$this->assertEquals('jane.doe', $key->identity());
$this->assertEquals(600, $key->ttl());
}
/**
* @depends it_checks_key_existence
*
* @test
*/
public function it_throws_exception_when_retrieving_missing_key(FixedStorage $storage)
{
$this->expectException(KeyNotFound::class);
$storage->get('123');
}
}