Passed
Pull Request — master (#1)
by Harry
02:04
created

file_exists()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of graze/sprout.
4
 *
5
 * Copyright (c) 2017 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\Seed\Mysql;
15
16
use Graze\ParallelProcess\Pool;
17
use Graze\ParallelProcess\Table;
18
use Graze\Sprout\Config\ConnectionConfigInterface;
19
use Graze\Sprout\Test\TestCase;
20
use Mockery;
21
use Symfony\Component\Process\Process;
22
23
/**
24
 * @runTestsInSeparateProcesses
25
 * @preserveGlobalState disabled
26
 */
27
class MysqlTableSeederTest extends TestCase
28
{
29
    // our standards don't handle sub functions properly, until this is fixed
30
    // @codingStandardsIgnoreStart
31
    public function testSeed()
32
    {
33
        $process = Mockery::mock('overload:' . Process::class);
34
35
        $process->shouldReceive('setCommandLine')
36
                ->with('mysql -h\'some-host\' -u\'some-user\' -p\'some-pass\' --default-character-set=utf8 \'some-schema\' < \'some-file\'')
37
                ->once();
38
39
        $config = Mockery::mock(ConnectionConfigInterface::class);
40
        $config->shouldReceive('getHost')
41
               ->andReturn('some-host');
42
        $config->shouldReceive('getUser')
43
               ->andReturn('some-user');
44
        $config->shouldReceive('getPassword')
45
               ->andReturn('some-pass');
46
47
        $pool = Mockery::mock(Pool::class);
48
49
        $pool->shouldReceive('add')
50
             ->with(
51
                 Mockery::type(Process::class),
52
                 ['seed', 'schema' => 'some-schema', 'table' => 'some-table']
53
             );
54
55
        $tableSeeder = new MysqlTableSeeder($pool, $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\Seed\Mysql\...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

55
        $tableSeeder = new MysqlTableSeeder($pool, /** @scrutinizer ignore-type */ $config);
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\Seed\Mysql\...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

55
        $tableSeeder = new MysqlTableSeeder(/** @scrutinizer ignore-type */ $pool, $config);
Loading history...
56
57
        /**
58
         * @param string $file
59
         *
60
         * @return bool
61
         */
62
        function file_exists($file)
63
        {
64
            TestCase::assertEquals('some-file', $file);
65
            return true;
66
        }
67
68
        $tableSeeder->seed('some-file', 'some-schema', 'some-table');
69
    }
70
    // @codingStandardsIgnoreEnd
71
72
    /**
73
     * @expectedException \InvalidArgumentException
74
     */
75
    public function testFileExistsFailure()
76
    {
77
        $config = Mockery::mock(ConnectionConfigInterface::class);
78
        $pool = Mockery::mock(Pool::class);
79
80
        $tableSeeder = new MysqlTableSeeder($pool, $config);
0 ignored issues
show
Bug introduced by
$pool of type Mockery\MockInterface is incompatible with the type Graze\ParallelProcess\Pool expected by parameter $pool of Graze\Sprout\Seed\Mysql\...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

80
        $tableSeeder = new MysqlTableSeeder(/** @scrutinizer ignore-type */ $pool, $config);
Loading history...
Bug introduced by
$config of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Config\ConnectionConfigInterface expected by parameter $connection of Graze\Sprout\Seed\Mysql\...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

80
        $tableSeeder = new MysqlTableSeeder($pool, /** @scrutinizer ignore-type */ $config);
Loading history...
81
82
        // @codingStandardsIgnoreStart
83
        /**
84
         * @param string $file
85
         *
86
         * @return bool
87
         */
88
        function file_exists($file)
89
        {
90
            TestCase::assertEquals('some-file', $file);
91
            return false;
92
        }
93
94
        // @codingStandardsIgnoreEnd
95
96
        $tableSeeder->seed('some-file', 'some-schema', 'some-table');
97
    }
98
}
99