|
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
|
|
|
|