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') |
|
|
|
|
57
|
|
|
->andReturns(true); |
58
|
|
|
|
59
|
|
|
$tableSeeder = new MysqlTableSeeder($pool, $config, $fileSystem); |
|
|
|
|
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); |
|
|
|
|
77
|
|
|
|
78
|
|
|
$tableSeeder->seed('some-file', 'some-schema', 'some-table'); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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.