Passed
Push — main ( a1448d...532f1f )
by Peter
03:51
created

GenerateKeysTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Console\Commands\Oauth2;
6
7
use Opulence\Console\Responses\IResponse;
8
use PHPUnit\Framework\TestCase;
9
10
class GenerateKeysTest extends TestCase
11
{
12
    private GenerateKeys $sut;
13
14
    /** @var string */
15
    private $privateKeyPassword = 'foopass';
16
17
    /** @var string */
18
    private $privateKeyPath = '/tmp/private';
19
20
    /** @var string */
21
    private $publicKeyPath = '/tmp/public';
22
23
    public function setUp(): void
24
    {
25
        $this->sut = new GenerateKeys($this->privateKeyPassword, $this->privateKeyPath, $this->publicKeyPath);
26
    }
27
28
    public function testExecuteWritesFatalIfOpenSslIsNotAvailable()
29
    {
30
        $responseMock = $this->getMockBuilder(IResponse::class)
31
            ->disableOriginalConstructor()
32
            ->getMock();
33
34
        $responseMock->expects($this->once())
35
            ->method('writeln')
36
            ->with('<fatal>OpenSSL is not installed.</fatal>');
37
38
        $this->sut->setIsOpenSslAvailable(false);
39
40
        $this->sut->execute($responseMock);
41
    }
42
43
    public function testExecuteCreatesOpenSslKeys()
44
    {
45
        if (!defined('OPENSSL_VERSION_NUMBER')) {
46
            $this->markTestSkipped('no openssl installed');
47
        }
48
49
        if (!is_writable(dirname($this->privateKeyPath)) || !is_writable(dirname($this->publicKeyPath))) {
50
            $this->markTestSkipped('private or public key path are not writable');
51
        }
52
53
        $responseMock = $this->getMockBuilder(IResponse::class)
54
            ->disableOriginalConstructor()
55
            ->getMock();
56
57
        $this->sut->execute($responseMock);
58
        $this->assertFileExists($this->privateKeyPath);
59
        $this->assertFileExists($this->publicKeyPath);
60
    }
61
}
62