MysqlTableSeederTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testFileExistsFailure() 0 12 1
A testSeed() 0 32 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\Db\Mysql;
15
16
use Graze\ParallelProcess\Pool;
17
use Graze\Sprout\Config\ConnectionConfigInterface;
18
use Graze\Sprout\Db\Mysql\MysqlTableSeeder;
19
use Graze\Sprout\Test\TestCase;
20
use League\Flysystem\AdapterInterface;
21
use Mockery;
22
use Symfony\Component\Process\Process;
23
24
/**
25
 * @runTestsInSeparateProcesses
26
 * @preserveGlobalState disabled
27
 */
28
class MysqlTableSeederTest extends TestCase
29
{
30
    public function testSeed()
31
    {
32
        $process = Mockery::mock('overload:' . Process::class);
33
34
        $process->shouldReceive('setCommandLine')
35
                ->with('(echo \'SET AUTOCOMMIT=0; SET FOREIGN_KEY_CHECKS=0;\'; cat \'some-file\'; echo \'SET AUTOCOMMIT=1; SET FOREIGN_KEY_CHECKS=1;\') | mysql -h\'some-host\' -u\'some-user\' -p\'some-pass\' --max_allowed_packet=512M --default-character-set=utf8 \'some-schema\'')
36
                ->once();
37
38
        $config = Mockery::mock(ConnectionConfigInterface::class);
39
        $config->shouldReceive('getHost')
40
               ->andReturn('some-host');
41
        $config->shouldReceive('getUser')
42
               ->andReturn('some-user');
43
        $config->shouldReceive('getPassword')
44
               ->andReturn('some-pass');
45
46
        $pool = Mockery::mock(Pool::class);
47
48
        $pool->shouldReceive('add')
49
             ->with(
50
                 Mockery::type(Process::class),
51
                 ['seed', 'schema' => 'some-schema', 'table' => 'some-table']
52
             );
53
54
        $fileSystem = Mockery::mock(AdapterInterface::class);
55
        $fileSystem->allows()
56
                   ->has('some-file')
0 ignored issues
show
Bug introduced by
The method has() 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

56
                   ->/** @scrutinizer ignore-call */ has('some-file')

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 has() 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

56
                   ->/** @scrutinizer ignore-call */ has('some-file')
Loading history...
57
                   ->andReturns(true);
58
59
        $tableSeeder = new MysqlTableSeeder($pool, $config, $fileSystem);
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\Db\Mysql\My...leSeeder::__construct(). ( Ignorable by Annotation )

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

59
        $tableSeeder = new MysqlTableSeeder($pool, /** @scrutinizer ignore-type */ $config, $fileSystem);
Loading history...
Bug introduced by
$fileSystem of type Mockery\MockInterface is incompatible with the type League\Flysystem\AdapterInterface expected by parameter $fileSystem of Graze\Sprout\Db\Mysql\My...leSeeder::__construct(). ( Ignorable by Annotation )

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

59
        $tableSeeder = new MysqlTableSeeder($pool, $config, /** @scrutinizer ignore-type */ $fileSystem);
Loading history...
Bug introduced by
$pool of type Mockery\MockInterface is incompatible with the type Graze\ParallelProcess\Pool expected by parameter $pool of Graze\Sprout\Db\Mysql\My...leSeeder::__construct(). ( Ignorable by Annotation )

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

59
        $tableSeeder = new MysqlTableSeeder(/** @scrutinizer ignore-type */ $pool, $config, $fileSystem);
Loading history...
60
61
        $tableSeeder->seed('some-file', 'some-schema', 'some-table');
62
    }
63
64
    /**
65
     * @expectedException \InvalidArgumentException
66
     */
67
    public function testFileExistsFailure()
68
    {
69
        $config = Mockery::mock(ConnectionConfigInterface::class);
70
        $pool = Mockery::mock(Pool::class);
71
        $fileSystem = Mockery::mock(AdapterInterface::class);
72
        $fileSystem->allows()
73
                   ->has('some-file')
74
                   ->andReturns(false);
75
76
        $tableSeeder = new MysqlTableSeeder($pool, $config, $fileSystem);
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\Db\Mysql\My...leSeeder::__construct(). ( Ignorable by Annotation )

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

76
        $tableSeeder = new MysqlTableSeeder($pool, /** @scrutinizer ignore-type */ $config, $fileSystem);
Loading history...
Bug introduced by
$pool of type Mockery\MockInterface is incompatible with the type Graze\ParallelProcess\Pool expected by parameter $pool of Graze\Sprout\Db\Mysql\My...leSeeder::__construct(). ( Ignorable by Annotation )

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

76
        $tableSeeder = new MysqlTableSeeder(/** @scrutinizer ignore-type */ $pool, $config, $fileSystem);
Loading history...
Bug introduced by
$fileSystem of type Mockery\MockInterface is incompatible with the type League\Flysystem\AdapterInterface expected by parameter $fileSystem of Graze\Sprout\Db\Mysql\My...leSeeder::__construct(). ( Ignorable by Annotation )

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

76
        $tableSeeder = new MysqlTableSeeder($pool, $config, /** @scrutinizer ignore-type */ $fileSystem);
Loading history...
77
78
        $tableSeeder->seed('some-file', 'some-schema', 'some-table');
79
    }
80
}
81