Completed
Push — master ( b91597...be19b0 )
by Mitchel
02:09
created

FileCertificateStorageTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Bunq\Tests\Certificate\Storage;
4
5
use Bunq\Certificate\CertificateType;
6
use Bunq\Certificate\DefaultCertificate;
7
use Bunq\Certificate\Storage\FileCertificateStorage;
8
use PHPUnit\Framework\TestCase;
9
10 View Code Duplication
final class FileCertificateStorageTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    /**
13
     * @var FileCertificateStorage
14
     */
15
    private $storage;
16
17
    public function setUp()
18
    {
19
        $this->storage = new FileCertificateStorage('/tmp');
20
    }
21
22
    /**
23
     * @test
24
     */
25
    public function itFindsACertificatedBasedOnAType()
26
    {
27
        $certificate = DefaultCertificate::fromString('savedCertificate');
28
        $publicKey   = CertificateType::PRIVATE_KEY();
29
30
        @mkdir('/tmp/certificates');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
31
        file_put_contents('/tmp/certificates/' . $publicKey, $certificate->toString());
32
33
        $loadedCertificate = $this->storage->load($publicKey);
34
35
        $this->assertSame($certificate->toString(), $loadedCertificate->toString());
36
    }
37
38
    /**
39
     * @test
40
     */
41
    public function itSavesACertificatesBasedOnAType()
42
    {
43
        $certificate = DefaultCertificate::fromString('test');
44
        $publicKey   = CertificateType::PUBLIC_KEY();
45
46
        $this->storage->save($certificate, $publicKey);
47
48
        $result = @file_get_contents('/tmp/certificates/' . $publicKey);
49
50
        $this->assertSame($certificate->toString(), $result);
51
    }
52
}
53