Passed
Push — master ( 0647f1...378494 )
by Jean Paul
01:41
created

SourceWatcherTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php declare( strict_types = 1 );
2
3
namespace Coco\SourceWatcher\Tests\Core;
4
5
use Coco\SourceWatcher\Core\Database\Connections\Connector;
6
use Coco\SourceWatcher\Core\Database\Connections\SqliteConnector;
7
use Coco\SourceWatcher\Core\IO\Inputs\FileInput;
8
use Coco\SourceWatcher\Core\IO\Outputs\DatabaseOutput;
9
use Coco\SourceWatcher\Core\Pipeline;
10
use Coco\SourceWatcher\Core\SourceWatcher;
11
use Coco\SourceWatcher\Core\SourceWatcherException;
12
use Coco\SourceWatcher\Core\StepLoader;
13
use PHPUnit\Framework\TestCase;
14
15
/**
16
 * Class SourceWatcherTest
17
 * @package Coco\SourceWatcher\Tests\Core
18
 */
19
class SourceWatcherTest extends TestCase
20
{
21
    /**
22
     * @var SourceWatcher
23
     */
24
    private SourceWatcher $sourceWatcher;
25
26
    /**
27
     *
28
     */
29
    protected function setUp () : void
30
    {
31
        $this->sourceWatcher = new SourceWatcher();
32
    }
33
34
    /**
35
     *
36
     */
37
    protected function tearDown () : void
38
    {
39
        unset( $this->sourceWatcher );
40
    }
41
42
    /**
43
     *
44
     */
45
    public function testGetStepLoaderAndPipeline () : void
46
    {
47
        $stepLoader = $this->sourceWatcher->getStepLoader();
48
        $this->assertNotNull( $stepLoader );
49
        $this->assertInstanceOf( StepLoader::class, $stepLoader );
50
51
        $pipeline = $this->sourceWatcher->getPipeline();
52
        $this->assertNotNull( $stepLoader );
53
        $this->assertInstanceOf( Pipeline::class, $pipeline );
54
    }
55
56
    /**
57
     * @throws SourceWatcherException
58
     */
59
    public function testExtract () : void
60
    {
61
        $sourceWatcher = $this->sourceWatcher->extract( "Csv", new FileInput( __DIR__ . "/../../samples/data/csv/csv1.csv" ), [ "columns" => array( "name", "email" ) ] );
62
        $this->assertNotNull( $sourceWatcher );
63
        $this->assertInstanceOf( SourceWatcher::class, $sourceWatcher );
64
    }
65
66
    /**
67
     * @throws SourceWatcherException
68
     */
69
    public function testExtractException () : void
70
    {
71
        $this->expectException( SourceWatcherException::class );
72
        $this->expectExceptionMessage( "The extractor NonExistent can't be found." );
73
74
        $this->sourceWatcher->extract( "NonExistent", $this->createMock( FileInput::class ), [] );
75
    }
76
77
    /**
78
     * @throws SourceWatcherException
79
     */
80
    public function testTransform () : void
81
    {
82
        $sourceWatcher = $this->sourceWatcher->transform( "RenameColumns", [ "columns" => array( "email" => "email_address" ) ] );
83
        $this->assertNotNull( $sourceWatcher );
84
        $this->assertInstanceOf( SourceWatcher::class, $sourceWatcher );
85
    }
86
87
    /**
88
     * @throws SourceWatcherException
89
     */
90
    public function testTransformException () : void
91
    {
92
        $this->expectException( SourceWatcherException::class );
93
        $this->expectExceptionMessage( "The transformer NonExistent can't be found." );
94
95
        $this->sourceWatcher->transform( "NonExistent", [] );
96
    }
97
98
    /**
99
     * @throws SourceWatcherException
100
     */
101
    public function testLoad () : void
102
    {
103
        $sourceWatcher = $this->sourceWatcher->load( "Database", new DatabaseOutput( $this->createMock( Connector::class ) ) );
104
        $this->assertNotNull( $sourceWatcher );
105
        $this->assertInstanceOf( SourceWatcher::class, $sourceWatcher );
106
    }
107
108
    /**
109
     * @throws SourceWatcherException
110
     */
111
    public function testLoadException () : void
112
    {
113
        $this->expectException( SourceWatcherException::class );
114
        $this->expectExceptionMessage( "The loader NonExistent can't be found." );
115
116
        $this->sourceWatcher->load( "NonExistent", $this->createMock( DatabaseOutput::class ) );
117
    }
118
119
    /**
120
     * @throws SourceWatcherException
121
     */
122
    public function testRun () : void
123
    {
124
        $connector = new SqliteConnector();
125
        $connector->setPath( __DIR__ . "/../../samples/data/sqlite/people-db.sqlite" );
126
        $connector->setTableName( "people" );
127
128
        $this->assertNull(
129
            $this->sourceWatcher
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->sourceWatcher->ex...put($connector))->run() targeting Coco\SourceWatcher\Core\SourceWatcher::run() 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...
130
                ->extract( "Csv", new FileInput( __DIR__ . "/../../samples/data/csv/csv1.csv" ), [ "columns" => array( "name", "email" ) ] )
131
                ->transform( "RenameColumns", [ "columns" => array( "email" => "email_address" ) ] )
132
                ->load( "Database", new DatabaseOutput( $connector ) )
133
                ->run()
134
        );
135
    }
136
}
137