Passed
Push — master ( d6d91c...5e7603 )
by Jean Paul
06:39
created

DatabaseLoaderTest::testInsertRowWithNoOutput()   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
 * @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
        $connectorMock = $this->createMock( Connector::class );
25
26
        $databaseOutput = new DatabaseOutput( $connectorMock );
27
28
        $databaseLoader = new DatabaseLoader();
29
        $databaseLoader->setOutput( $databaseOutput );
30
31
        $this->assertSame( $databaseOutput, $databaseLoader->getOutput() );
32
    }
33
34
    /**
35
     * @throws SourceWatcherException
36
     */
37
    public function testInsertRowWithNoOutput () : void
38
    {
39
        $this->expectException( SourceWatcherException::class );
40
41
        $databaseLoader = new DatabaseLoader();
42
        $databaseLoader->load( new Row( [ "name" => "Jane Doe" ] ) );
43
    }
44
45
    /**
46
     * @throws SourceWatcherException
47
     */
48
    public function testInsertRowWithNonDatabaseOutput () : void
49
    {
50
        $this->expectException( SourceWatcherException::class );
51
52
        $databaseLoader = new DatabaseLoader();
53
        $databaseLoader->setOutput( $this->createMock( Output::class ) );
54
        $databaseLoader->load( new Row( [ "name" => "Jane Doe" ] ) );
55
    }
56
57
    /**
58
     * @throws SourceWatcherException
59
     */
60
    public function testInsertRowWithDatabaseOutputWithoutConnector () : void
61
    {
62
        $this->expectException( SourceWatcherException::class );
63
64
        $databaseLoader = new DatabaseLoader();
65
        $databaseLoader->setOutput( new DatabaseOutput() );
66
        $databaseLoader->load( new Row( [ "name" => "Jane Doe" ] ) );
67
    }
68
}
69