Passed
Push — master ( 5e7603...3491bf )
by Jean Paul
06:49
created

testInsertRowWithNonDatabaseOutput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
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
 * @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" ] ) ) );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $databaseLoader->load(ne...'name' => 'Jane Doe'))) 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...
76
    }
77
}
78