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

CryptHelperTest.php ➔ storage_path()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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