|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Tests\Core; |
|
4
|
|
|
|
|
5
|
|
|
use Coco\SourceWatcher\Core\Database\Connections\Connector; |
|
6
|
|
|
use Coco\SourceWatcher\Core\IO\Inputs\FileInput; |
|
7
|
|
|
use Coco\SourceWatcher\Core\IO\Outputs\DatabaseOutput; |
|
8
|
|
|
use Coco\SourceWatcher\Core\Pipeline; |
|
9
|
|
|
use Coco\SourceWatcher\Core\SourceWatcher; |
|
10
|
|
|
use Coco\SourceWatcher\Core\SourceWatcherException; |
|
11
|
|
|
use Coco\SourceWatcher\Core\StepLoader; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
|
|
14
|
|
|
class SourceWatcherTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
private SourceWatcher $sourceWatcher; |
|
17
|
|
|
|
|
18
|
|
|
protected function setUp () : void |
|
19
|
|
|
{ |
|
20
|
|
|
$this->sourceWatcher = new SourceWatcher(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
protected function tearDown () : void |
|
24
|
|
|
{ |
|
25
|
|
|
unset( $this->sourceWatcher ); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testGetStepLoaderAndPipeline () : void |
|
29
|
|
|
{ |
|
30
|
|
|
$stepLoader = $this->sourceWatcher->getStepLoader(); |
|
31
|
|
|
$this->assertNotNull( $stepLoader ); |
|
32
|
|
|
$this->assertInstanceOf( StepLoader::class, $stepLoader ); |
|
33
|
|
|
|
|
34
|
|
|
$pipeline = $this->sourceWatcher->getPipeline(); |
|
35
|
|
|
$this->assertNotNull( $stepLoader ); |
|
36
|
|
|
$this->assertInstanceOf( Pipeline::class, $pipeline ); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @throws SourceWatcherException |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testExtract () : void |
|
43
|
|
|
{ |
|
44
|
|
|
$sourceWatcher = $this->sourceWatcher->extract( "Csv", new FileInput( __DIR__ . "/../data/csv/csv1.csv" ), [ "columns" => array( "name", "email" ) ] ); |
|
45
|
|
|
$this->assertNotNull( $sourceWatcher ); |
|
46
|
|
|
$this->assertInstanceOf( SourceWatcher::class, $sourceWatcher ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testExtractException () : void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->expectException( SourceWatcherException::class ); |
|
52
|
|
|
|
|
53
|
|
|
$this->sourceWatcher->extract( "NonExistent", $this->createMock( FileInput::class ), [] ); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @throws SourceWatcherException |
|
58
|
|
|
*/ |
|
59
|
|
|
public function testTransform () : void |
|
60
|
|
|
{ |
|
61
|
|
|
$sourceWatcher = $this->sourceWatcher->transform( "RenameColumns", [ "columns" => array( "email" => "email_address" ) ] ); |
|
62
|
|
|
$this->assertNotNull( $sourceWatcher ); |
|
63
|
|
|
$this->assertInstanceOf( SourceWatcher::class, $sourceWatcher ); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testTransformException () : void |
|
67
|
|
|
{ |
|
68
|
|
|
$this->expectException( SourceWatcherException::class ); |
|
69
|
|
|
|
|
70
|
|
|
$this->sourceWatcher->transform( "NonExistent", [] ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @throws SourceWatcherException |
|
75
|
|
|
*/ |
|
76
|
|
|
public function testLoad () : void |
|
77
|
|
|
{ |
|
78
|
|
|
$sourceWatcher = $this->sourceWatcher->load( "Database", new DatabaseOutput( $this->createMock( Connector::class ) ) ); |
|
79
|
|
|
$this->assertNotNull( $sourceWatcher ); |
|
80
|
|
|
$this->assertInstanceOf( SourceWatcher::class, $sourceWatcher ); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function testLoadException () : void |
|
84
|
|
|
{ |
|
85
|
|
|
$this->expectException( SourceWatcherException::class ); |
|
86
|
|
|
|
|
87
|
|
|
$this->sourceWatcher->load( "NonExistent", $this->createMock( DatabaseOutput::class ) ); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|