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

FileCertificateStorageTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 43
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 4 4 1
A itFindsACertificatedBasedOnAType() 12 12 1
A itSavesACertificatesBasedOnAType() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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