-
Notifications
You must be signed in to change notification settings - Fork 41
/
ResetCommandTest.php
executable file
·113 lines (92 loc) · 2.99 KB
/
ResetCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/*
* Copyright (c) Taylor Otwell, Leroy Merlin Brasil
* Copyrights licensed under the MIT License.
* See the accompanying LICENSE file for terms.
*/
namespace MongolidLaravel\Migrations\Commands;
use Illuminate\Console\OutputStyle;
use Illuminate\Foundation\Application;
use Mockery as m;
use MongolidLaravel\Migrations\Migrator;
use MongolidLaravel\TestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
class ResetCommandTest extends TestCase
{
public function testResetCommandCallsMigratorWithProperArguments()
{
// Set
$migrator = m::mock(Migrator::class);
$command = new ResetCommand($migrator);
$app = m::mock(Application::class.'[environment]');
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
// Expectations
$app->expects()
->environment()
->andReturn('development');
$migrator->expects()
->paths()
->andReturn([]);
$migrator->expects()
->setConnection(null);
$migrator->expects()
->repositoryExists()
->andReturn(true);
$migrator->expects()
->setOutput(m::type(OutputStyle::class))
->andReturn($migrator);
$migrator->expects()
->reset([__DIR__.DIRECTORY_SEPARATOR.'migrations']);
// Actions
$command->run(new ArrayInput([]), new NullOutput());
}
public function testResetCommandShouldNotRunWhenRepositoryDoesNotExist()
{
// Set
$migrator = m::mock(Migrator::class);
$command = new ResetCommand($migrator);
$app = m::mock(Application::class.'[environment]');
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
// Expectations
$app->expects()
->environment()
->andReturn('development');
$migrator->expects()
->paths()
->never();
$migrator->expects()
->setConnection(null);
$migrator->expects()
->repositoryExists()
->andReturn(false);
$migrator->expects()
->setOutput(m::type(OutputStyle::class))
->never();
$migrator->expects()
->reset([__DIR__.DIRECTORY_SEPARATOR.'migrations'])
->never();
// Actions
$command->run(new ArrayInput([]), new NullOutput());
}
public function testShouldConfirmToRun()
{
// Set
$migrator = m::mock(Migrator::class);
$command = m::mock(ResetCommand::class.'[confirmToProceed]', [$migrator]);
$app = new Application();
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
// Expectations
$command->expects()
->confirmToProceed()
->andReturn(false);
$migrator->expects()
->paths()
->never();
// Actions
$command->run(new ArrayInput([]), new NullOutput());
}
}