Completed
Pull Request — master (#1)
by Timothy
05:37
created

ExtractorChainTest::testExtractFromEmptyChain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace AbacaphiliacTest\Extractor;
4
5
use Abacaphiliac\Extractor\ExtractionInterface;
6
use Abacaphiliac\Extractor\ExtractorChain;
7
8
/**
9
 * @covers \Abacaphiliac\Extractor\ExtractorChain
10
 */
11
class ExtractorChainTest extends \PHPUnit_Framework_TestCase
12
{
13
    public function testExtractFromEmptyChain()
14
    {
15
        $sut = new ExtractorChain();
16
        
17
        $actual = $sut->extract();
18
        
19
        self::assertCount(0, $actual);
20
    }
21
    
22
    public function testDefaultExtraction()
23
    {
24
        $sut = new ExtractorChain([
25
            $firstExtractor = $this->getMockBuilder(ExtractionInterface::class)->getMock(),
26
            $secondExtractor = $this->getMockBuilder(ExtractionInterface::class)->getMock(),
27
        ]);
28
        
29
        $firstExtractor->expects(self::any())->method('extract')->will(self::returnValue([
30
            'Foo' => 'Bar',
31
            'Bar' => 'Foo',
32
        ]));
33
        
34
        $secondExtractor->expects(self::any())->method('extract')->will(self::returnValue([
35
            'Foo' => 'FooBar',
36
            'Fizz' => 'Buzz',
37
        ]));
38
        
39
        $actual = $sut->extract();
40
        
41
        self::assertArraySubset(
42
            [
43
                'Foo' => 'FooBar',
44
                'Bar' => 'Foo',
45
                'Fizz' => 'Buzz',
46
            ],
47
            $actual
48
        );
49
    }
50
    
51
    public function testExtractNonRecursively()
52
    {
53
        $sut = new ExtractorChain([
54
            $firstExtractor = $this->getMockBuilder(ExtractionInterface::class)->getMock(),
55
            $secondExtractor = $this->getMockBuilder(ExtractionInterface::class)->getMock(),
56
        ], false);
57
58
        $firstExtractor->expects(self::any())->method('extract')->will(self::returnValue([
59
            'Foo' => [
60
                'Fizz' => 'Buzz',
61
            ],
62
        ]));
63
64
        $secondExtractor->expects(self::any())->method('extract')->will(self::returnValue([
65
            'Foo' => 'Bar',
66
        ]));
67
68
        $actual = $sut->extract();
69
70
        self::assertArraySubset(
71
            [
72
                'Foo' => 'Bar',
73
            ],
74
            $actual
75
        );
76
    }
77
    
78
    public function testExtractTraversable()
79
    {
80
        $sut = new ExtractorChain([
81
            $firstExtractor = $this->getMockBuilder(ExtractionInterface::class)->getMock(),
82
            $secondExtractor = $this->getMockBuilder(ExtractionInterface::class)->getMock(),
83
        ]);
84
85
        $firstExtractor->expects(self::any())->method('extract')->will(self::returnValue(new \ArrayIterator([
86
            'Foo' => [
87
                'Fizz' => 'Buzz',
88
            ],
89
        ])));
90
91
        $secondExtractor->expects(self::any())->method('extract')->will(self::returnValue(new \ArrayIterator([
92
            'Foo' => [
93
                'Fizz' => 'Bar',
94
            ],
95
        ])));
96
97
        $actual = $sut->extract();
98
99
        self::assertArraySubset(
100
            [
101
                'Foo' => [
102
                    'Fizz' => 'Bar',
103
                ],
104
            ],
105
            $actual
106
        );
107
    }
108
109
    /**
110
     * @expectedException \Abacaphiliac\Extractor\Exception\UnexpectedValueException
111
     */
112
    public function testInvalidExtraction()
113
    {
114
        $sut = new ExtractorChain([
115
            $extractor = $this->getMockBuilder(ExtractionInterface::class)->getMock(),
116
        ]);
117
118
        $extractor->expects(self::any())->method('extract')->will(self::returnValue(new \stdClass()));
119
120
        $sut->extract();
121
    }
122
}
123