Test Failed
Push — master ( a6b51e...5fffdb )
by Gabriel
08:05
created

CryptHelperTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testKeyPathFromStoragePath() 0 8 1
A testGenerateKeys() 0 17 2
1
<?php
2
3
namespace ByTIC\Hello\Tests\Utility {
4
5
    use ByTIC\Hello\Tests\AbstractTest;
6
    use ByTIC\Hello\Utility\CryptHelper;
7
8
    /**
9
     * Class CryptHelperTest
10
     * @package ByTIC\Hello\Tests\Utility
11
     */
12
    class CryptHelperTest extends AbstractTest
13
    {
14
        public static function testKeyPathFromStoragePath()
15
        {
16
            $path = CryptHelper::keyPath('oath.key');
17
            self::assertSame(
18
                TEST_FIXTURE_PATH . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'oath.key',
19
                $path
20
            );
21
        }
22
23
        public static function testGenerateKeys()
24
        {
25
            CryptHelper::generateKeys();
26
27
            $files = ['oauth-private.key', 'oauth-public.key'];
28
            foreach ($files as $file) {
29
                $path = storage_path($file);
30
                self::assertFileExists($path);
31
32
                $content = file_get_contents($path);
33
                self::assertStringStartsWith('-----BEGIN', $content);
34
                self::assertStringEndsWith('KEY-----', $content);
35
36
                self::assertGreaterThan(100, filesize($path), "output file [{$file}] should be at least 100bytes");
37
                unlink($path);
38
            }
39
        }
40
    }
41
}
42
43
namespace {
44
45
    /**
46
     * @param $file
47
     * @return string
48
     */
49
    function storage_path($file)
50
    {
51
        return TEST_FIXTURE_PATH . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . $file;
52
    }
53
}
54