| Total Complexity | 3 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class InMemoryStorageTest extends TestCase |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @test |
||
| 15 | */ |
||
| 16 | public function it_checks_key_existence() |
||
| 17 | { |
||
| 18 | $storage = new InMemoryStorage(['john.doe' => 'ABC', 'jane.doe' => 'XYZ'], 600); |
||
| 19 | |||
| 20 | $this->assertTrue($storage->has('ABC')); |
||
| 21 | $this->assertTrue($storage->has('XYZ')); |
||
| 22 | $this->assertFalse($storage->has('123')); |
||
| 23 | |||
| 24 | return $storage; |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @depends it_checks_key_existence |
||
| 29 | * |
||
| 30 | * @test |
||
| 31 | */ |
||
| 32 | public function it_retrieves_key(InMemoryStorage $storage) |
||
| 33 | { |
||
| 34 | $key = $storage->get('ABC'); |
||
| 35 | |||
| 36 | $this->assertEquals('ABC', $key->key()); |
||
| 37 | $this->assertEquals('john.doe', $key->identity()); |
||
| 38 | $this->assertEquals(600, $key->ttl()); |
||
| 39 | |||
| 40 | $key = $storage->get('XYZ'); |
||
| 41 | |||
| 42 | $this->assertEquals('XYZ', $key->key()); |
||
| 43 | $this->assertEquals('jane.doe', $key->identity()); |
||
| 44 | $this->assertEquals(600, $key->ttl()); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @depends it_checks_key_existence |
||
| 49 | * |
||
| 50 | * @test |
||
| 51 | */ |
||
| 52 | public function it_throws_exception_when_retrieving_missing_key(InMemoryStorage $storage) |
||
| 53 | { |
||
| 54 | $this->expectException(KeyNotFound::class); |
||
| 55 | |||
| 56 | $storage->get('123'); |
||
| 57 | } |
||
| 59 |