JsonLoaderTest::testHasErrorWithInvalidFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 3
c 2
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ComposerRequireCheckerTest;
4
5
use ComposerRequireChecker\Exception\InvalidJsonException;
6
use ComposerRequireChecker\Exception\NotReadableException;
7
use ComposerRequireChecker\JsonLoader;
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * @covers \ComposerRequireChecker\JsonLoader
12
 */
13
final class JsonLoaderTest extends TestCase
14
{
15
    public function testHasErrorWithWrongPath(): void
16
    {
17
        $path = __DIR__ . '/wrong/path/non-existing-file.json';
18
        $this->expectException(NotReadableException::class);
19
        new JsonLoader($path);
20
    }
21
22
    public function testHasErrorWithInvalidFile(): void
23
    {
24
        $path = __DIR__ . '/../fixtures/invalidJson';
25
        $this->expectException(InvalidJsonException::class);
26
        new JsonLoader($path);
27
    }
28
29
    public function testHasDataWithValidFile(): void
30
    {
31
        $path = __DIR__ . '/../fixtures/validJson.json';
32
        $loader = new JsonLoader($path);
33
        $this->assertEquals($loader->getData(), ['foo' => 'bar']);
34
    }
35
}
36