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
|
|
|
/** |
16
|
|
|
* Class PipelineTest |
17
|
|
|
* |
18
|
|
|
* @package Coco\SourceWatcher\Tests\Core |
19
|
|
|
*/ |
20
|
|
|
class PipelineTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
private Pipeline $pipeline; |
23
|
|
|
|
24
|
|
|
protected function setUp () : void |
25
|
|
|
{ |
26
|
|
|
$this->pipeline = new Pipeline(); |
27
|
|
|
|
28
|
|
|
$csvExtractor = new CsvExtractor(); |
29
|
|
|
$csvExtractor->setInput( new FileInput( __DIR__ . "/../../samples/data/csv/csv1.csv" ) ); |
30
|
|
|
|
31
|
|
|
// pipe the extractor |
32
|
|
|
$this->pipeline->pipe( $csvExtractor ); |
33
|
|
|
|
34
|
|
|
$transformer = new RenameColumnsTransformer(); |
35
|
|
|
$transformer->options( [ "columns" => [ "email" => "email_address" ] ] ); |
36
|
|
|
|
37
|
|
|
// pipe the transformer |
38
|
|
|
$this->pipeline->pipe( $transformer ); |
39
|
|
|
|
40
|
|
|
// pipe the loader |
41
|
|
|
$this->pipeline->pipe( $this->createMock( DatabaseLoader::class ) ); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function tearDown () : void |
45
|
|
|
{ |
46
|
|
|
unset( $this->pipeline ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testExecute () : void |
50
|
|
|
{ |
51
|
|
|
$this->assertNull( $this->pipeline->execute() ); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testGetResults () : void |
55
|
|
|
{ |
56
|
|
|
$this->pipeline->execute(); |
57
|
|
|
|
58
|
|
|
$this->assertNotNull( $this->pipeline->getResults() ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testIterator () : void |
62
|
|
|
{ |
63
|
|
|
$this->pipeline->execute(); |
64
|
|
|
|
65
|
|
|
foreach ( $this->pipeline as $key => $value ) { |
66
|
|
|
$this->assertNotNull( $key ); |
67
|
|
|
$this->assertNotNull( $value ); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testSetGetSteps () : void |
72
|
|
|
{ |
73
|
|
|
$this->pipeline = new Pipeline(); |
74
|
|
|
|
75
|
|
|
$givenSteps = []; |
76
|
|
|
$expectedSteps = []; |
77
|
|
|
|
78
|
|
|
$transformer = $this->createMock( Transformer::class ); |
79
|
|
|
$givenSteps[] = $transformer; |
80
|
|
|
$expectedSteps[] = $transformer; |
81
|
|
|
|
82
|
|
|
$loader = $this->createMock( Loader::class ); |
83
|
|
|
$givenSteps[] = $loader; |
84
|
|
|
$expectedSteps[] = $loader; |
85
|
|
|
|
86
|
|
|
$this->pipeline->setSteps( $givenSteps ); |
87
|
|
|
|
88
|
|
|
$this->assertEquals( $expectedSteps, $this->pipeline->getSteps() ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testPipeStep () : void |
92
|
|
|
{ |
93
|
|
|
$this->pipeline = new Pipeline(); |
94
|
|
|
|
95
|
|
|
$transformer = $this->createMock( Transformer::class ); |
96
|
|
|
|
97
|
|
|
$this->assertNull( $this->pipeline->pipe( $transformer ) ); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
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.