Completed
Pull Request — master (#2)
by thomas
71:58
created

AbstractTestCase::readTestVectorsFile()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 0
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
     * @return array
26
     */
27
    private function readTestVectorsFile()
28
    {
29
        $decoded = json_decode(file_get_contents(__DIR__ .'/data/crypt_vectors.json'), true);
30
        if (!$decoded || json_last_error() !== JSON_ERROR_NONE) {
31
            throw new \RuntimeException('failed to read vectors file');
32
        }
33
34
        return $decoded;
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    public function getTestVectors()
41
    {
42
        if (null === $this->vectors) {
43
            $this->vectors = $this->readTestVectorsFile();
44
        }
45
46
        return $this->vectors;
47
    }
48
}
49