AbstractTestCase   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A dataPath() 0 4 1
A dataFile() 0 8 2
A readTestVectorsFile() 0 9 3
A getTestVectors() 0 8 2
1
<?php
2
3
namespace Btccom\JustEncrypt\Test;
4
5
abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase
6
{
7
    /**
8
     * @var array
9
     */
10
    private $vectors = null;
11
12
    /**
13
     * AbstractTestCase constructor.
14
     * @param null $name
15
     * @param array $data
16
     * @param string $dataName
17
     */
18
    public function __construct($name = null, array $data = [], $dataName = '')
19
    {
20
        $this->getTestVectors();
21
        parent::__construct($name, $data, $dataName);
22
    }
23
24
    /**
25
     * @param string $file
26
     * @return string
27
     */
28
    public function dataPath($file)
29
    {
30
        return __DIR__ . '/data/' . $file;
31
    }
32
33
    /**
34
     * @param string $filename
35
     * @return string
36
     */
37
    public function dataFile($filename)
38
    {
39
        $contents = file_get_contents($this->dataPath($filename));
40
        if (false === $contents) {
41
            throw new \RuntimeException('Failed to data file ' . $filename);
42
        }
43
        return $contents;
44
    }
45
46
    /**
47
     * @return array
48
     */
49
    private function readTestVectorsFile()
50
    {
51
        $decoded = json_decode(file_get_contents(__DIR__ .'/data/crypt_vectors.json'), true);
52
        if (!$decoded || json_last_error() !== JSON_ERROR_NONE) {
53
            throw new \RuntimeException('failed to read vectors file');
54
        }
55
56
        return $decoded;
57
    }
58
59
    /**
60
     * @return array
61
     */
62
    public function getTestVectors()
63
    {
64
        if (null === $this->vectors) {
65
            $this->vectors = $this->readTestVectorsFile();
66
        }
67
68
        return $this->vectors;
69
    }
70
}
71