-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathArchiveTokenCommandTest.php
More file actions
101 lines (80 loc) · 2.57 KB
/
Copy pathArchiveTokenCommandTest.php
File metadata and controls
101 lines (80 loc) · 2.57 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
declare(strict_types=1);
namespace Yokai\SecurityTokenBundle\Tests\Command;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;
use Yokai\SecurityTokenBundle\Archive\ArchivistInterface;
/**
* @author Yann Eugoné <eugone.yann@gmail.com>
*
* phpcs:ignoreFile PSR1.Methods.CamelCapsMethodName.NotCamelCaps
*/
class ArchiveTokenCommandTest extends KernelTestCase
{
/**
* @var MockObject<ArchivistInterface>
*/
private $archivist;
/**
* @var Application
*/
private $application;
protected function setUp(): void
{
$this->archivist = $this->createMock(ArchivistInterface::class);
self::bootKernel();
self::$kernel->getContainer()->set('yokai_security_token.archivist', $this->archivist);
$this->application = new Application(self::$kernel);
}
protected function tearDown(): void
{
parent::tearDown();
unset(
$this->archivist,
$this->application
);
}
protected function command()
{
return $this->application->get('yokai:security-token:archive');
}
protected function runCommand(Command $command, array $options = []): string
{
$input = ['command' => $command->getName()];
foreach ($options as $name => $value) {
$input['--' . $name] = $value;
}
$tester = new CommandTester($command);
$tester->execute($input);
return $tester->getDisplay();
}
/**
* @test
*/
public function it_archive_every_token_when_run_without_options_with_confirmation(): void
{
$command = $this->command();
$this->archivist->expects(self::once())
->method('archive')
->with(null)
->willReturn(10);
$output = $this->runCommand($command);
self::assertStringContainsString('Successfully archived 10 security token(s).', $output);
}
/**
* @test
*/
public function it_archive_partial_tokens_when_run_with_options(): void
{
$command = $this->command();
$this->archivist->expects(self::once())
->method('archive')
->with('init_password')
->willReturn(10);
$output = $this->runCommand($command, ['purpose' => 'init_password']);
self::assertStringContainsString('Successfully archived 10 security token(s).', $output);
}
}