-
Notifications
You must be signed in to change notification settings - Fork 4
/
LookupKeyStorageCommandTest.php
78 lines (62 loc) · 1.85 KB
/
LookupKeyStorageCommandTest.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
namespace Damax\Bundle\ApiAuthBundle\Tests\Command\Storage;
use Damax\Bundle\ApiAuthBundle\Command\Storage\LookupKeyCommand;
use Damax\Bundle\ApiAuthBundle\Key\Key;
use Damax\Bundle\ApiAuthBundle\Key\Storage\KeyNotFound;
use Damax\Bundle\ApiAuthBundle\Key\Storage\Storage;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Command\Command;
/**
* @group integration
* @group console
*/
class LookupKeyStorageCommandTest extends StorageCommandTestCase
{
/**
* @var Storage|MockObject
*/
private $storage;
protected function createCommand(): Command
{
$this->storage = $this->createMock(Storage::class);
return new LookupKeyCommand($this->storage);
}
/**
* @test
*/
public function it_finds_key()
{
$this->storage
->expects($this->once())
->method('get')
->with('XYZ')
->willReturn(new Key('XYZ', 'john.doe', 60))
;
$code = $this->tester->execute(['command' => 'damax:api-auth:storage:lookup-key', 'key' => 'XYZ']);
$output = <<<CONSOLE
---------- ----------
Key XYZ
Identity john.doe
TTL 60
---------- ----------
CONSOLE;
$this->assertSame(0, $code);
$this->assertEquals($output, $this->tester->getDisplay());
}
/**
* @test
*/
public function it_fails_to_find_key()
{
$this->storage
->expects($this->once())
->method('get')
->with('XYZ')
->willThrowException(new KeyNotFound())
;
$code = $this->tester->execute(['command' => 'damax:api-auth:storage:lookup-key', 'key' => 'XYZ']);
$this->assertSame(1, $code);
$this->assertEquals('[ERROR] Key not found.', trim($this->tester->getDisplay()));
}
}