CryptHelperTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 3
Bugs 2 Features 1
Metric Value
wmc 3
eloc 15
c 3
b 2
f 1
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGenerateKeys() 0 15 2
A testKeyPathFromStoragePath() 0 6 1
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
                \Nip\storage_path('hello/keys/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 = \Nip\storage_path('hello/keys/' . $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 Nip {
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