Passed
Push — master ( 3021fc...1455fb )
by Jean Paul
01:48
created

JsonExtractorTest::testNoInputException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php declare( strict_types = 1 );
2
3
namespace Coco\SourceWatcher\Tests\Core\Extractors;
4
5
use Coco\SourceWatcher\Core\Extractors\JsonExtractor;
6
use Coco\SourceWatcher\Core\Row;
7
use Coco\SourceWatcher\Core\SourceWatcherException;
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * Class JsonExtractorTest
12
 * @package Coco\SourceWatcher\Tests\Core\Extractors
13
 */
14
class JsonExtractorTest extends TestCase
15
{
16
    /**
17
     *
18
     */
19
    public function testSetterGetterAttributeInput () : void
20
    {
21
        $jsonExtractor = new JsonExtractor();
22
23
        $givenInput = "/some/file/path/file.json";
24
        $expectedInput = "/some/file/path/file.json";
25
26
        $jsonExtractor->setInput( $givenInput );
27
28
        $this->assertEquals( $expectedInput, $jsonExtractor->getInput() );
29
    }
30
31
    /**
32
     *
33
     */
34
    public function testSetGetColumns () : void
35
    {
36
        $jsonExtractor = new JsonExtractor();
37
38
        $givenColumns = array( "color" => "colors.*.color" );
39
        $expectedColumns = array( "color" => "colors.*.color" );
40
41
        $jsonExtractor->setColumns( $givenColumns );
42
43
        $this->assertEquals( $expectedColumns, $jsonExtractor->getColumns() );
44
    }
45
46
    /**
47
     * @throws SourceWatcherException
48
     */
49
    public function testExtractColors () : void
50
    {
51
        $jsonExtractor = new JsonExtractor();
52
        $jsonExtractor->setColumns( array( "color" => "colors.*.color" ) );
53
        $jsonExtractor->setInput( __DIR__ . "/../../../samples/data/json/colors.json" );
54
55
        $expected = [ new Row( [ "color" => "black" ] ), new Row( [ "color" => "white" ] ), new Row( [ "color" => "red" ] ), new Row( [ "color" => "blue" ] ), new Row( [ "color" => "yellow" ] ), new Row( [ "color" => "green" ] ) ];
56
57
        $this->assertEquals( $expected, $jsonExtractor->extract() );
58
    }
59
60
    /**
61
     * @throws SourceWatcherException
62
     */
63
    public function testNoInputException () : void
64
    {
65
        $this->expectException( SourceWatcherException::class );
66
67
        $jsonExtractor = new JsonExtractor();
68
        $jsonExtractor->setInput( null );
69
        $jsonExtractor->extract();
70
    }
71
}
72