TableDumperFactoryTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 54
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testLogging() 0 20 1
A testMysqlReturnsMysqlTableDumper() 0 14 1
A testUnknownThrowsException() 0 11 1
1
<?php
2
/**
3
 * This file is part of graze/sprout.
4
 *
5
 * Copyright © 2018 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/sprout/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/sprout
12
 */
13
14
namespace Graze\Sprout\Test\Unit\Dump;
15
16
use Graze\ParallelProcess\Pool;
17
use Graze\Sprout\Config\ConnectionConfigInterface;
18
use Graze\Sprout\Db\Mysql\MysqlTableDumper;
19
use Graze\Sprout\Dump\TableDumperFactory;
20
use Graze\Sprout\Dump\TableDumperInterface;
21
use Graze\Sprout\Test\TestCase;
22
use Mockery;
23
use Psr\Log\LoggerInterface;
24
25
class TableDumperFactoryTest extends TestCase
26
{
27
    public function testMysqlReturnsMysqlTableDumper()
28
    {
29
        $pool = Mockery::mock(Pool::class);
30
31
        $config = Mockery::mock(ConnectionConfigInterface::class);
32
        $config->shouldReceive('getDriver')
33
               ->andReturn('mysql');
34
35
        $dumperFactory = new TableDumperFactory($pool);
0 ignored issues
show
Bug introduced by
$pool of type Mockery\MockInterface is incompatible with the type Graze\ParallelProcess\Pool expected by parameter $processPool of Graze\Sprout\Dump\TableD...rFactory::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        $dumperFactory = new TableDumperFactory(/** @scrutinizer ignore-type */ $pool);
Loading history...
36
37
        $tableDumper = $dumperFactory->getDumper($config);
0 ignored issues
show
Bug introduced by
$config of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Config\ConnectionConfigInterface expected by parameter $connection of Graze\Sprout\Dump\TableDumperFactory::getDumper(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        $tableDumper = $dumperFactory->getDumper(/** @scrutinizer ignore-type */ $config);
Loading history...
38
39
        $this->assertInstanceOf(TableDumperInterface::class, $tableDumper);
40
        $this->assertInstanceOf(MysqlTableDumper::class, $tableDumper);
41
    }
42
43
    /**
44
     * @expectedException \InvalidArgumentException
45
     */
46
    public function testUnknownThrowsException()
47
    {
48
        $pool = Mockery::mock(Pool::class);
49
50
        $config = Mockery::mock(ConnectionConfigInterface::class);
51
        $config->shouldReceive('getDriver')
52
               ->andReturn('pgsql');
53
54
        $dumperFactory = new TableDumperFactory($pool);
0 ignored issues
show
Bug introduced by
$pool of type Mockery\MockInterface is incompatible with the type Graze\ParallelProcess\Pool expected by parameter $processPool of Graze\Sprout\Dump\TableD...rFactory::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

54
        $dumperFactory = new TableDumperFactory(/** @scrutinizer ignore-type */ $pool);
Loading history...
55
56
        $dumperFactory->getDumper($config);
0 ignored issues
show
Bug introduced by
$config of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Config\ConnectionConfigInterface expected by parameter $connection of Graze\Sprout\Dump\TableDumperFactory::getDumper(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
        $dumperFactory->getDumper(/** @scrutinizer ignore-type */ $config);
Loading history...
57
    }
58
59
    public function testLogging()
60
    {
61
        $logger = Mockery::mock(LoggerInterface::class);
62
        $pool = Mockery::mock(Pool::class);
63
        $config = Mockery::mock(ConnectionConfigInterface::class);
64
        $config->shouldReceive('getDriver')
65
               ->andReturn('mysql');
66
67
        $dumperFactory = new TableDumperFactory($pool);
0 ignored issues
show
Bug introduced by
$pool of type Mockery\MockInterface is incompatible with the type Graze\ParallelProcess\Pool expected by parameter $processPool of Graze\Sprout\Dump\TableD...rFactory::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
        $dumperFactory = new TableDumperFactory(/** @scrutinizer ignore-type */ $pool);
Loading history...
68
        $dumperFactory->setLogger($logger);
0 ignored issues
show
Bug introduced by
$logger of type Mockery\MockInterface is incompatible with the type Psr\Log\LoggerInterface expected by parameter $logger of Graze\Sprout\Dump\TableDumperFactory::setLogger(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

68
        $dumperFactory->setLogger(/** @scrutinizer ignore-type */ $logger);
Loading history...
69
70
        $logger->allows()
71
               ->debug(
0 ignored issues
show
Bug introduced by
The method debug() does not exist on Mockery\Expectation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
               ->/** @scrutinizer ignore-call */ debug(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method debug() does not exist on Mockery\ExpectationInterface. It seems like you code against a sub-type of Mockery\ExpectationInterface such as Mockery\CompositeExpectation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
               ->/** @scrutinizer ignore-call */ debug(
Loading history...
72
                   "getDumper: using mysql dumper for driver: mysql",
73
                   ['driver' => 'mysql']
74
               );
75
76
        $tableDumper = $dumperFactory->getDumper($config);
0 ignored issues
show
Bug introduced by
$config of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Config\ConnectionConfigInterface expected by parameter $connection of Graze\Sprout\Dump\TableDumperFactory::getDumper(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

76
        $tableDumper = $dumperFactory->getDumper(/** @scrutinizer ignore-type */ $config);
Loading history...
77
78
        $this->assertInstanceOf(TableDumperInterface::class, $tableDumper);
79
    }
80
}
81