Skip to content

Commit 397deee

Browse files
committed
fix test
1 parent 5d390b9 commit 397deee

File tree

7 files changed

+15
-96
lines changed

7 files changed

+15
-96
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
}
3737
},
3838
"scripts": {
39-
"test": "vendor/bin/phpunit"
39+
"test": "vendor/bin/phpunit",
40+
"post-autoload-dump": [
41+
"@php ./vendor/bin/testbench package:discover --ansi"
42+
]
4043
},
4144
"minimum-stability": "stable",
4245
"extra": {

src/Console/MakeCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public function handle(): void
2828
* @param $name
2929
* @param $table
3030
* @param $create
31-
* @return string
31+
* @return string|null
3232
* @throws \Exception
3333
*/
34-
protected function writeMigration($name, $table, $create): string
34+
protected function writeMigration($name, $table, $create): ?string
3535
{
3636
$file = $this->creator->create(
3737
$name, $this->getMigrationPath(), $table, $create

src/Console/PatchCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ public function handle(): int
3939
protected function prepareDatabase(): void
4040
{
4141
if (! $this->migrator->repositoryExists()) {
42-
$this->call('patcher:install', array_filter([
43-
'--database' => $this->option('database'),
44-
]));
42+
$this->call('patcher:install');
4543
}
4644
}
4745

src/Patcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function patch(string $file, int $batch, bool $pretend): void
8484
* @return void
8585
* @throws \Throwable
8686
*/
87-
protected function runPatch($migration, string $method): void
87+
protected function runPatch(object $migration, string $method): void
8888
{
8989
$connection = $this->resolveConnection(
9090
$migration->getConnection()

tests/Command/PatcherInstallCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function tearDown(): void
1818
m::close();
1919
}
2020

21-
public function testFireCallsRepositoryToInstall()
21+
public function testFireCallsRepositoryToInstall(): void
2222
{
2323
$command = new InstallCommand($repo = m::mock(MigrationRepositoryInterface::class));
2424

@@ -29,7 +29,7 @@ public function testFireCallsRepositoryToInstall()
2929
$this->runCommand($command, ['--database' => 'foo']);
3030
}
3131

32-
protected function runCommand(Command $command, $options = [])
32+
protected function runCommand(Command $command, $options = []): int
3333
{
3434
return $command->run(new ArrayInput($options), new NullOutput());
3535
}

tests/Command/PatcherMakeCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testBasicCreateDumpsAutoload(): void
3232
$this->runCommand($command, ['name' => 'fix_foo']);
3333
}
3434

35-
public function testBasicCreateGivesCreatorProperArguments()
35+
public function testBasicCreateGivesCreatorProperArguments(): void
3636
{
3737
$command = new MakeCommand(
3838
$creator = m::mock(PatcherCreator::class),
@@ -45,7 +45,7 @@ public function testBasicCreateGivesCreatorProperArguments()
4545
$this->runCommand($command, ['name' => 'fix_foo']);
4646
}
4747

48-
public function testBasicCreateGivesCreatorProperArgumentsWhenNameIsStudlyCase()
48+
public function testBasicCreateGivesCreatorProperArgumentsWhenNameIsStudlyCase(): void
4949
{
5050
$command = new MakeCommand(
5151
$creator = m::mock(PatcherCreator::class),

tests/Command/PatcherRunCommandTest.php

Lines changed: 3 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
namespace Dentro\Patcher\Tests\Command;
44

55
use Illuminate\Contracts\Events\Dispatcher;
6-
use Illuminate\Database\Events\SchemaLoaded;
76
use Illuminate\Foundation\Application;
87
use Dentro\Patcher\Console\PatchCommand;
98
use Dentro\Patcher\Patcher;
109
use PHPUnit\Framework\TestCase;
11-
use stdClass;
1210
use Symfony\Component\Console\Input\ArrayInput;
1311
use Symfony\Component\Console\Output\NullOutput;
1412
use 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

Comments
 (0)