1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace Illuminate\Tests\Foundation\Testing;
- use Illuminate\Contracts\Console\Kernel;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Illuminate\Foundation\Testing\RefreshDatabaseState;
- use PHPUnit\Framework\TestCase;
- class RefreshDatabaseTest extends TestCase
- {
- protected $traitObject;
- protected function setUp(): void
- {
- RefreshDatabaseState::$migrated = false;
- $this->traitObject = $this->getMockForTrait(RefreshDatabase::class, [], '', true, true, true, [
- 'artisan',
- 'beginDatabaseTransaction',
- ]);
- $kernelObj = \Mockery::mock();
- $kernelObj->shouldReceive('setArtisan')
- ->with(null);
- $this->traitObject->app = [
- Kernel::class => $kernelObj,
- ];
- }
- private function __reflectAndSetupAccessibleForProtectedTraitMethod($methodName)
- {
- $migrateFreshUsingReflection = new \ReflectionMethod(
- get_class($this->traitObject),
- $methodName
- );
- $migrateFreshUsingReflection->setAccessible(true);
- return $migrateFreshUsingReflection;
- }
- public function testRefreshTestDatabaseDefault()
- {
- $this->traitObject
- ->expects($this->exactly(1))
- ->method('artisan')
- ->with('migrate:fresh', [
- '--drop-views' => false,
- '--drop-types' => false,
- '--seed' => false,
- ]);
- $refreshTestDatabaseReflection = $this->__reflectAndSetupAccessibleForProtectedTraitMethod('refreshTestDatabase');
- $refreshTestDatabaseReflection->invoke($this->traitObject);
- }
- public function testRefreshTestDatabaseWithDropViewsOption()
- {
- $this->traitObject->dropViews = true;
- $this->traitObject
- ->expects($this->exactly(1))
- ->method('artisan')
- ->with('migrate:fresh', [
- '--drop-views' => true,
- '--drop-types' => false,
- '--seed' => false,
- ]);
- $refreshTestDatabaseReflection = $this->__reflectAndSetupAccessibleForProtectedTraitMethod('refreshTestDatabase');
- $refreshTestDatabaseReflection->invoke($this->traitObject);
- }
- public function testRefreshTestDatabaseWithDropTypesOption()
- {
- $this->traitObject->dropTypes = true;
- $this->traitObject
- ->expects($this->exactly(1))
- ->method('artisan')
- ->with('migrate:fresh', [
- '--drop-views' => false,
- '--drop-types' => true,
- '--seed' => false,
- ]);
- $refreshTestDatabaseReflection = $this->__reflectAndSetupAccessibleForProtectedTraitMethod('refreshTestDatabase');
- $refreshTestDatabaseReflection->invoke($this->traitObject);
- }
- }
|