1
|
|
|
<?php declare( strict_types = 1 ); |
2
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Tests\Core; |
4
|
|
|
|
5
|
|
|
use Coco\SourceWatcher\Core\Extractor; |
6
|
|
|
use Coco\SourceWatcher\Core\Extractors\CsvExtractor; |
7
|
|
|
use Coco\SourceWatcher\Core\IO\Inputs\FileInput; |
8
|
|
|
use Coco\SourceWatcher\Core\Loader; |
9
|
|
|
use Coco\SourceWatcher\Core\Loaders\DatabaseLoader; |
10
|
|
|
use Coco\SourceWatcher\Core\Pipeline; |
11
|
|
|
use Coco\SourceWatcher\Core\Transformer; |
12
|
|
|
use Coco\SourceWatcher\Core\Transformers\RenameColumnsTransformer; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
class PipelineTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
public function testSetGetExtractor () : void |
18
|
|
|
{ |
19
|
|
|
$pipeline = new Pipeline(); |
20
|
|
|
|
21
|
|
|
$givenExtractor = $this->createMock( Extractor::class ); |
22
|
|
|
$expectedExtractor = $this->createMock( Extractor::class ); |
23
|
|
|
|
24
|
|
|
$pipeline->setExtractor( $givenExtractor ); |
25
|
|
|
|
26
|
|
|
$this->assertEquals( $expectedExtractor, $pipeline->getExtractor() ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testSetGetSteps () : void |
30
|
|
|
{ |
31
|
|
|
$pipeline = new Pipeline(); |
32
|
|
|
|
33
|
|
|
$givenSteps = []; |
34
|
|
|
$expectedSteps = []; |
35
|
|
|
|
36
|
|
|
$transformer = $this->createMock( Transformer::class ); |
37
|
|
|
$givenSteps[] = $transformer; |
38
|
|
|
$expectedSteps[] = $transformer; |
39
|
|
|
|
40
|
|
|
$loader = $this->createMock( Loader::class ); |
41
|
|
|
$givenSteps[] = $loader; |
42
|
|
|
$expectedSteps[] = $loader; |
43
|
|
|
|
44
|
|
|
$pipeline->setSteps( $givenSteps ); |
45
|
|
|
|
46
|
|
|
$this->assertEquals( $expectedSteps, $pipeline->getSteps() ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testPipeStep () : void |
50
|
|
|
{ |
51
|
|
|
$pipeline = new Pipeline(); |
52
|
|
|
|
53
|
|
|
$transformer = $this->createMock( Transformer::class ); |
54
|
|
|
|
55
|
|
|
$this->assertNull( $pipeline->pipe( $transformer ) ); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
private Pipeline $pipeline; |
59
|
|
|
|
60
|
|
|
protected function setUp () : void |
61
|
|
|
{ |
62
|
|
|
$this->pipeline = new Pipeline(); |
63
|
|
|
|
64
|
|
|
$csvExtractor = new CsvExtractor(); |
65
|
|
|
$csvExtractor->setInput( new FileInput( __DIR__ . "/../../samples/data/csv/csv1.csv" ) ); |
66
|
|
|
|
67
|
|
|
// set the extractor |
68
|
|
|
$this->pipeline->setExtractor( $csvExtractor ); |
69
|
|
|
|
70
|
|
|
$transformer = new RenameColumnsTransformer(); |
71
|
|
|
$transformer->options( [ "columns" => [ "email" => "email_address" ] ] ); |
72
|
|
|
|
73
|
|
|
// pipe the transformer |
74
|
|
|
$this->pipeline->pipe( $transformer ); |
75
|
|
|
|
76
|
|
|
// pipe the loader |
77
|
|
|
$this->pipeline->pipe( $this->createMock( DatabaseLoader::class ) ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
protected function tearDown () : void |
81
|
|
|
{ |
82
|
|
|
unset( $this->pipeline ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testExecute () : void |
86
|
|
|
{ |
87
|
|
|
$this->assertNull( $this->pipeline->execute() ); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testGetResults () : void |
91
|
|
|
{ |
92
|
|
|
$this->pipeline->execute(); |
93
|
|
|
|
94
|
|
|
$this->assertNotNull( $this->pipeline->getResults() ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testIterator () : void |
98
|
|
|
{ |
99
|
|
|
$this->pipeline->execute(); |
100
|
|
|
|
101
|
|
|
foreach ( $this->pipeline as $key => $value ) { |
102
|
|
|
$this->assertNotNull( $key ); |
103
|
|
|
$this->assertNotNull( $value ); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.