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
|
<?php
namespace Illuminate\Tests\Foundation\Testing;
use Illuminate\Contracts\Console\Kernel as ConsoleKernelContract;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Foundation\Testing\Concerns\InteractsWithConsole;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\RefreshDatabaseState;
use Mockery as m;
use Orchestra\Testbench\Concerns\ApplicationTestingHooks;
use Orchestra\Testbench\Foundation\Application as Testbench;
use PHPUnit\Framework\TestCase;
use function Orchestra\Testbench\package_path;
class RefreshDatabaseTest extends TestCase
{
use ApplicationTestingHooks;
use InteractsWithConsole;
use RefreshDatabase;
public $dropViews = false;
public $dropTypes = false;
protected function setUp(): void
{
RefreshDatabaseState::$migrated = false;
$this->setUpTheApplicationTestingHooks();
$this->withoutMockingConsoleOutput();
}
protected function tearDown(): void
{
$this->tearDownTheApplicationTestingHooks();
RefreshDatabaseState::$migrated = false;
}
protected function refreshApplication()
{
$this->app = Testbench::create(
basePath: package_path('vendor/orchestra/testbench-core/laravel'),
);
}
public function testRefreshTestDatabaseDefault()
{
$this->app->instance(ConsoleKernelContract::class, $kernel = m::spy(ConsoleKernel::class));
$kernel->shouldReceive('call')
->once()
->with('migrate:fresh', [
'--drop-views' => false,
'--drop-types' => false,
'--seed' => false,
]);
$this->refreshTestDatabase();
}
public function testRefreshTestDatabaseWithDropViewsOption()
{
$this->dropViews = true;
$this->app->instance(ConsoleKernelContract::class, $kernel = m::spy(ConsoleKernel::class));
$kernel->shouldReceive('call')
->once()
->with('migrate:fresh', [
'--drop-views' => true,
'--drop-types' => false,
'--seed' => false,
]);
$this->refreshTestDatabase();
}
public function testRefreshTestDatabaseWithDropTypesOption()
{
$this->dropTypes = true;
$this->app->instance(ConsoleKernelContract::class, $kernel = m::spy(ConsoleKernel::class));
$kernel->shouldReceive('call')
->once()
->with('migrate:fresh', [
'--drop-views' => false,
'--drop-types' => true,
'--seed' => false,
]);
$this->refreshTestDatabase();
}
}
|