Passed
Push — master ( f38dcf...954e17 )
by Jean Paul
01:37
created

PipelineTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 18
rs 10
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() );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->pipeline->execute() targeting Coco\SourceWatcher\Core\Pipeline::execute() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
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 ) );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->pipeline->pipe($transformer) targeting Coco\SourceWatcher\Core\Pipeline::pipe() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
98
    }
99
}
100