PipelineTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 32
c 1
b 0
f 0
dl 0
loc 78
rs 10
wmc 8

7 Methods

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