33namespace Dentro \Patcher \Tests \Command ;
44
55use Illuminate \Contracts \Events \Dispatcher ;
6- use Illuminate \Database \Events \SchemaLoaded ;
76use Illuminate \Foundation \Application ;
87use Dentro \Patcher \Console \PatchCommand ;
98use Dentro \Patcher \Patcher ;
109use PHPUnit \Framework \TestCase ;
11- use stdClass ;
1210use Symfony \Component \Console \Input \ArrayInput ;
1311use Symfony \Component \Console \Output \NullOutput ;
1412use Mockery as m ;
@@ -20,12 +18,11 @@ protected function tearDown(): void
2018 m::close ();
2119 }
2220
23- public function testBasicPatchesCallMigratorWithProperArguments ()
21+ public function testBasicPatchesCallMigratorWithProperArguments (): void
2422 {
2523 $ command = new PatchCommand ($ migrator = m::mock (Patcher::class), $ dispatcher = m::mock (Dispatcher::class));
2624 $ app = new ApplicationDatabaseMigrationStub ();
2725 $ command ->setLaravel ($ app );
28- $ migrator ->shouldReceive ('paths ' )->once ()->andReturn ([]);
2926 $ migrator ->shouldReceive ('hasRunAnyMigrations ' )->andReturn (true );
3027 $ migrator ->shouldReceive ('usingConnection ' )->once ()->andReturnUsing (function ($ name , $ callback ) {
3128 return $ callback ();
@@ -38,39 +35,12 @@ public function testBasicPatchesCallMigratorWithProperArguments()
3835 $ this ->runCommand ($ command );
3936 }
4037
41- public function testMigrationsCanBeRunWithStoredSchema ()
42- {
43- $ command = new PatchCommand ($ migrator = m::mock (Patcher::class), $ dispatcher = m::mock (Dispatcher::class));
44- $ app = new ApplicationDatabaseMigrationStub ();
45- $ app ->setBasePath (__DIR__ );
46- $ command ->setLaravel ($ app );
47- $ migrator ->shouldReceive ('paths ' )->once ()->andReturn ([]);
48- $ migrator ->shouldReceive ('hasRunAnyMigrations ' )->andReturn (false );
49- $ migrator ->shouldReceive ('resolveConnection ' )->andReturn ($ connection = m::mock (stdClass::class));
50- $ connection ->shouldReceive ('getName ' )->andReturn ('mysql ' );
51- $ migrator ->shouldReceive ('usingConnection ' )->once ()->andReturnUsing (function ($ name , $ callback ) {
52- return $ callback ();
53- });
54- $ migrator ->shouldReceive ('deleteRepository ' )->once ();
55- $ connection ->shouldReceive ('getSchemaState ' )->andReturn ($ schemaState = m::mock (stdClass::class));
56- $ schemaState ->shouldReceive ('handleOutputUsing ' )->andReturnSelf ();
57- $ schemaState ->shouldReceive ('load ' )->once ()->with (__DIR__ .'/stubs/schema.sql ' );
58- $ dispatcher ->shouldReceive ('dispatch ' )->once ()->with (m::type (SchemaLoaded::class));
59- $ migrator ->shouldReceive ('setOutput ' )->once ()->andReturn ($ migrator );
60- $ migrator ->shouldReceive ('run ' )->once ()->with ([__DIR__ .DIRECTORY_SEPARATOR .'patches ' ], ['pretend ' => false , 'step ' => false ]);
61- $ migrator ->shouldReceive ('getNotes ' )->andReturn ([]);
62- $ migrator ->shouldReceive ('repositoryExists ' )->once ()->andReturn (true );
63-
64- $ this ->runCommand ($ command , ['--schema-path ' => __DIR__ .'/stubs/schema.sql ' ]);
65- }
66-
67- public function testPatchesRepositoryCreatedWhenNecessary ()
38+ public function testPatchesRepositoryCreatedWhenNecessary (): void
6839 {
6940 $ params = [$ migrator = m::mock (Patcher::class), $ dispatcher = m::mock (Dispatcher::class)];
7041 $ command = $ this ->getMockBuilder (PatchCommand::class)->onlyMethods (['call ' ])->setConstructorArgs ($ params )->getMock ();
7142 $ app = new ApplicationDatabaseMigrationStub ();
7243 $ command ->setLaravel ($ app );
73- $ migrator ->shouldReceive ('paths ' )->once ()->andReturn ([]);
7444 $ migrator ->shouldReceive ('hasRunAnyMigrations ' )->andReturn (true );
7545 $ migrator ->shouldReceive ('usingConnection ' )->once ()->andReturnUsing (function ($ name , $ callback ) {
7646 return $ callback ();
@@ -83,58 +53,6 @@ public function testPatchesRepositoryCreatedWhenNecessary()
8353 $ this ->runCommand ($ command );
8454 }
8555
86- public function testTheCommandMayBePretended ()
87- {
88- $ command = new PatchCommand ($ migrator = m::mock (Patcher::class), $ dispatcher = m::mock (Dispatcher::class));
89- $ app = new ApplicationDatabaseMigrationStub (['path.database ' => __DIR__ ]);
90- $ app ->useDatabasePath (__DIR__ );
91- $ command ->setLaravel ($ app );
92- $ migrator ->shouldReceive ('paths ' )->once ()->andReturn ([]);
93- $ migrator ->shouldReceive ('hasRunAnyMigrations ' )->andReturn (true );
94- $ migrator ->shouldReceive ('usingConnection ' )->once ()->andReturnUsing (function ($ name , $ callback ) {
95- return $ callback ();
96- });
97- $ migrator ->shouldReceive ('setOutput ' )->once ()->andReturn ($ migrator );
98- $ migrator ->shouldReceive ('run ' )->once ()->with ([$ app ->basePath ().DIRECTORY_SEPARATOR .'patches ' ], ['pretend ' => true , 'step ' => false ]);
99- $ migrator ->shouldReceive ('repositoryExists ' )->once ()->andReturn (true );
100-
101- $ this ->runCommand ($ command , ['--pretend ' => true ]);
102- }
103-
104- public function testTheDatabaseMayBeSet ()
105- {
106- $ command = new PatchCommand ($ migrator = m::mock (Patcher::class), $ dispatcher = m::mock (Dispatcher::class));
107- $ app = new ApplicationDatabaseMigrationStub ();
108- $ command ->setLaravel ($ app );
109- $ migrator ->shouldReceive ('paths ' )->once ()->andReturn ([]);
110- $ migrator ->shouldReceive ('hasRunAnyMigrations ' )->andReturn (true );
111- $ migrator ->shouldReceive ('usingConnection ' )->once ()->andReturnUsing (function ($ name , $ callback ) {
112- return $ callback ();
113- });
114- $ migrator ->shouldReceive ('setOutput ' )->once ()->andReturn ($ migrator );
115- $ migrator ->shouldReceive ('run ' )->once ()->with ([$ app ->basePath ().DIRECTORY_SEPARATOR .'patches ' ], ['pretend ' => false , 'step ' => false ]);
116- $ migrator ->shouldReceive ('repositoryExists ' )->once ()->andReturn (true );
117-
118- $ this ->runCommand ($ command , ['--database ' => 'foo ' ]);
119- }
120-
121- public function testStepMayBeSet ()
122- {
123- $ command = new PatchCommand ($ migrator = m::mock (Patcher::class), $ dispatcher = m::mock (Dispatcher::class));
124- $ app = new ApplicationDatabaseMigrationStub ();
125- $ command ->setLaravel ($ app );
126- $ migrator ->shouldReceive ('paths ' )->once ()->andReturn ([]);
127- $ migrator ->shouldReceive ('hasRunAnyMigrations ' )->andReturn (true );
128- $ migrator ->shouldReceive ('usingConnection ' )->once ()->andReturnUsing (function ($ name , $ callback ) {
129- return $ callback ();
130- });
131- $ migrator ->shouldReceive ('setOutput ' )->once ()->andReturn ($ migrator );
132- $ migrator ->shouldReceive ('run ' )->once ()->with ([$ app ->basePath ().DIRECTORY_SEPARATOR .'patches ' ], ['pretend ' => false , 'step ' => true ]);
133- $ migrator ->shouldReceive ('repositoryExists ' )->once ()->andReturn (true );
134-
135- $ this ->runCommand ($ command , ['--step ' => true ]);
136- }
137-
13856 protected function runCommand ($ command , $ input = [])
13957 {
14058 return $ command ->run (new ArrayInput ($ input ), new NullOutput );
@@ -150,7 +68,7 @@ public function __construct(array $data = [])
15068 }
15169 }
15270
153- public function environment (...$ environments )
71+ public function environment (...$ environments ): string
15472 {
15573 return 'development ' ;
15674 }
0 commit comments