Passed
Push — master ( 7d22f9...1460f7 )
by Jean Paul
01:51
created

testInsertRowWithDatabaseOutputWithMockConnector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
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
 *
16
 * @package Coco\SourceWatcher\Tests\Core\Loaders
17
 */
18
class DatabaseLoaderTest extends TestCase
19
{
20
    private string $janeDoe;
21
22
    public function setUp () : void
23
    {
24
        $this->janeDoe = "Jane Doe";
25
    }
26
27
    /**
28
     * This unit test is testing the getOutput and setOutput methods of the Loader abstract class.
29
     */
30
    public function testSetAndGetOutput () : void
31
    {
32
        $databaseOutput = new DatabaseOutput( $this->createMock( Connector::class ) );
33
34
        $databaseLoader = new DatabaseLoader();
35
        $databaseLoader->setOutput( $databaseOutput );
36
37
        $this->assertSame( $databaseOutput, $databaseLoader->getOutput() );
38
    }
39
40
    /**
41
     * @throws SourceWatcherException
42
     */
43
    public function testInsertRowWithNoOutput () : void
44
    {
45
        $this->expectException( SourceWatcherException::class );
46
47
        $databaseLoader = new DatabaseLoader();
48
        $databaseLoader->load( new Row( [ "name" => $this->janeDoe ] ) );
49
    }
50
51
    /**
52
     * @throws SourceWatcherException
53
     */
54
    public function testInsertRowWithNonDatabaseOutput () : void
55
    {
56
        $this->expectException( SourceWatcherException::class );
57
58
        $databaseLoader = new DatabaseLoader();
59
        $databaseLoader->setOutput( $this->createMock( Output::class ) );
60
        $databaseLoader->load( new Row( [ "name" => $this->janeDoe ] ) );
61
    }
62
63
    /**
64
     * @throws SourceWatcherException
65
     */
66
    public function testInsertRowWithDatabaseOutputWithoutConnector () : void
67
    {
68
        $this->expectException( SourceWatcherException::class );
69
70
        $databaseLoader = new DatabaseLoader();
71
        $databaseLoader->setOutput( new DatabaseOutput() );
72
        $databaseLoader->load( new Row( [ "name" => $this->janeDoe ] ) );
73
    }
74
75
    /**
76
     * @throws SourceWatcherException
77
     */
78
    public function testInsertRowWithDatabaseOutputWithMockConnector () : void
79
    {
80
        $databaseLoader = new DatabaseLoader();
81
        $databaseLoader->setOutput( new DatabaseOutput( $this->createMock( Connector::class ) ) );
82
83
        $this->assertNull( $databaseLoader->load( new Row( [ "name" => $this->janeDoe ] ) ) );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $databaseLoader->load(ne...e' => $this->janeDoe))) targeting Coco\SourceWatcher\Core\...\DatabaseLoader::load() 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...
84
    }
85
}
86