1
|
|
|
<?php declare( strict_types = 1 ); |
2
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Tests\Core\Loaders; |
4
|
|
|
|
5
|
|
|
use Coco\SourceWatcher\Core\Database\Connections\Connector; |
6
|
|
|
use Coco\SourceWatcher\Core\IO\Outputs\DatabaseOutput; |
7
|
|
|
use Coco\SourceWatcher\Core\IO\Outputs\Output; |
8
|
|
|
use Coco\SourceWatcher\Core\Loaders\DatabaseLoader; |
9
|
|
|
use Coco\SourceWatcher\Core\Row; |
10
|
|
|
use Coco\SourceWatcher\Core\SourceWatcherException; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class DatabaseLoaderTest |
15
|
|
|
* @package Coco\SourceWatcher\Tests\Core\Loaders |
16
|
|
|
*/ |
17
|
|
|
class DatabaseLoaderTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* This unit test is testing the getOutput and setOutput methods of the Loader abstract class. |
21
|
|
|
*/ |
22
|
|
|
public function testSetAndGetOutput () : void |
23
|
|
|
{ |
24
|
|
|
$databaseOutput = new DatabaseOutput( $this->createMock( Connector::class ) ); |
25
|
|
|
|
26
|
|
|
$databaseLoader = new DatabaseLoader(); |
27
|
|
|
$databaseLoader->setOutput( $databaseOutput ); |
28
|
|
|
|
29
|
|
|
$this->assertSame( $databaseOutput, $databaseLoader->getOutput() ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @throws SourceWatcherException |
34
|
|
|
*/ |
35
|
|
|
public function testInsertRowWithNoOutput () : void |
36
|
|
|
{ |
37
|
|
|
$this->expectException( SourceWatcherException::class ); |
38
|
|
|
|
39
|
|
|
$databaseLoader = new DatabaseLoader(); |
40
|
|
|
$databaseLoader->load( new Row( [ "name" => "Jane Doe" ] ) ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @throws SourceWatcherException |
45
|
|
|
*/ |
46
|
|
|
public function testInsertRowWithNonDatabaseOutput () : void |
47
|
|
|
{ |
48
|
|
|
$this->expectException( SourceWatcherException::class ); |
49
|
|
|
|
50
|
|
|
$databaseLoader = new DatabaseLoader(); |
51
|
|
|
$databaseLoader->setOutput( $this->createMock( Output::class ) ); |
52
|
|
|
$databaseLoader->load( new Row( [ "name" => "Jane Doe" ] ) ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @throws SourceWatcherException |
57
|
|
|
*/ |
58
|
|
|
public function testInsertRowWithDatabaseOutputWithoutConnector () : void |
59
|
|
|
{ |
60
|
|
|
$this->expectException( SourceWatcherException::class ); |
61
|
|
|
|
62
|
|
|
$databaseLoader = new DatabaseLoader(); |
63
|
|
|
$databaseLoader->setOutput( new DatabaseOutput() ); |
64
|
|
|
$databaseLoader->load( new Row( [ "name" => "Jane Doe" ] ) ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @throws SourceWatcherException |
69
|
|
|
*/ |
70
|
|
|
public function testInsertRowWithDatabaseOutputWithMockConnector () : void |
71
|
|
|
{ |
72
|
|
|
$databaseLoader = new DatabaseLoader(); |
73
|
|
|
$databaseLoader->setOutput( new DatabaseOutput( $this->createMock( Connector::class ) ) ); |
74
|
|
|
|
75
|
|
|
$this->assertNull( $databaseLoader->load( new Row( [ "name" => "Jane Doe" ] ) ) ); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
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.