Completed
Pull Request — master (#3)
by Harry
07:29
created

RowProcessorTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 60
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testAddProcessor() 0 6 1
A testHasProcessor() 0 10 1
A testRemoveProcessor() 0 12 1
A testProcess() 0 16 1
1
<?php
2
/**
3
 * This file is part of graze/data-file
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Test\Unit\Format\Processor;
15
16
use Graze\DataFile\Test\Format\Processor\FakeRowProcessor;
17
use Graze\DataFile\Test\TestCase;
18
19
class RowProcessorTest extends TestCase
20
{
21
    /**
22
     * @var FakeRowProcessor
23
     */
24
    private $processor;
25
26
    public function setUp()
27
    {
28
        $this->processor = new FakeRowProcessor();
29
    }
30
31
    public function testAddProcessor()
32
    {
33
        static::assertEquals($this->processor, $this->processor->addProcessor(function ($row) {
34
            return $row;
35
        }));
36
    }
37
38
    public function testHasProcessor()
39
    {
40
        $processor = function ($row) {
41
            return $row;
42
        };
43
44
        static::assertFalse($this->processor->hasProcessor($processor));
45
        $this->processor->addProcessor($processor);
46
        static::assertTrue($this->processor->hasProcessor($processor));
47
    }
48
49
    public function testRemoveProcessor()
50
    {
51
        $processor = function ($row) {
52
            return $row;
53
        };
54
55
        static::assertFalse($this->processor->hasProcessor($processor));
56
        $this->processor->addProcessor($processor);
57
        static::assertTrue($this->processor->hasProcessor($processor));
58
        $this->processor->removeProcessor($processor);
59
        static::assertFalse($this->processor->hasProcessor($processor));
60
    }
61
62
    public function testProcess()
63
    {
64
        $calledRow = [];
65
66
        $processor = function (array $row) use (&$calledRow) {
67
            $calledRow = $row;
68
            return array_map(function ($item) {
69
                return str_pad($item, 2);
70
            }, $row);
71
        };
72
73
        $this->processor->addProcessor($processor);
74
75
        static::assertEquals(['a ', 'b ', 'c '], $this->processor->process(['a', 'b', 'c']));
76
        static::assertEquals(['a', 'b', 'c'], $calledRow);
77
    }
78
}
79