Code Duplication    Length = 43-54 lines in 2 locations

tests/Certificate/Storage/FileCertificateStorageTest.php 1 location

@@ 10-52 (lines=43) @@
7
use Bunq\Certificate\Storage\FileCertificateStorage;
8
use PHPUnit\Framework\TestCase;
9
10
final class FileCertificateStorageTest extends TestCase
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');
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

tests/Token/Storage/FileTokenStorageTest.php 1 location

@@ 10-63 (lines=54) @@
7
use Bunq\Token\TokenType;
8
use PHPUnit\Framework\TestCase;
9
10
final class FileTokenStorageTest extends TestCase
11
{
12
    /**
13
     * @var FileTokenStorage
14
     */
15
    private $storage;
16
17
    public function setUp()
18
    {
19
        $this->storage = new FileTokenStorage('/tmp');
20
    }
21
22
    /**
23
     * @test
24
     */
25
    public function itFindsATokenBasedOnAType()
26
    {
27
        $tokenType = TokenType::INSTALLATION_TOKEN();
28
29
        @mkdir('/tmp/tokens');
30
        file_put_contents('/tmp/tokens/' . $tokenType->toString(), 'tokenstring');
31
32
        $result = $this->storage->load($tokenType);
33
34
        $this->assertEquals('tokenstring', $result->toString());
35
    }
36
37
    /**
38
     * @test
39
     * @expectedException \Bunq\Token\Storage\TokenNotFoundException
40
     * @expectedExceptionMessage Could not find token "session.token" in path: /tmp/tokens
41
     */
42
    public function itThrowsAnExceptionWhenLoadingANonExistingToken()
43
    {
44
        $tokenType = TokenType::SESSION_TOKEN();
45
46
        $this->storage->load($tokenType);
47
    }
48
49
    /**
50
     * @test
51
     */
52
    public function itSavesATokenBasedOnAType()
53
    {
54
        $tokenType = TokenType::INSTALLATION_TOKEN();
55
        $token     = DefaultToken::fromString('newTokenData');
56
57
        $this->storage->save($token, $tokenType);
58
59
        $result = @file_get_contents('/tmp/tokens/' . $tokenType->toString());
60
61
        $this->assertSame($token->toString(), $result);
62
    }
63
}
64
65