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
|
<?php
namespace Illuminate\Tests\Database;
use Illuminate\Database\Console\Migrations\ResetCommand;
use Illuminate\Database\Migrations\Migrator;
use Illuminate\Foundation\Application;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
class DatabaseMigrationResetCommandTest extends TestCase
{
protected function tearDown(): void
{
m::close();
}
public function testResetCommandCallsMigratorWithProperArguments()
{
$command = new ResetCommand($migrator = m::mock(Migrator::class));
$app = new ApplicationDatabaseResetStub(['path.database' => __DIR__]);
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
$migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with(null);
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
$migrator->shouldReceive('setOutput')->once()->andReturn($migrator);
$migrator->shouldReceive('reset')->once()->with([__DIR__.DIRECTORY_SEPARATOR.'migrations'], false);
$this->runCommand($command);
}
public function testResetCommandCanBePretended()
{
$command = new ResetCommand($migrator = m::mock(Migrator::class));
$app = new ApplicationDatabaseResetStub(['path.database' => __DIR__]);
$app->useDatabasePath(__DIR__);
$command->setLaravel($app);
$migrator->shouldReceive('paths')->once()->andReturn([]);
$migrator->shouldReceive('setConnection')->once()->with('foo');
$migrator->shouldReceive('repositoryExists')->once()->andReturn(true);
$migrator->shouldReceive('setOutput')->once()->andReturn($migrator);
$migrator->shouldReceive('reset')->once()->with([__DIR__.DIRECTORY_SEPARATOR.'migrations'], true);
$this->runCommand($command, ['--pretend' => true, '--database' => 'foo']);
}
protected function runCommand($command, $input = [])
{
return $command->run(new ArrayInput($input), new NullOutput);
}
}
class ApplicationDatabaseResetStub extends Application
{
public function __construct(array $data = [])
{
foreach ($data as $abstract => $instance) {
$this->instance($abstract, $instance);
}
}
public function environment(...$environments)
{
return 'development';
}
}
|