forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disconnection after testing with traits for database testing
- Loading branch information
1 parent
4fe214d
commit 71c6653
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Foundation\Testing; | ||
|
||
use Illuminate\Contracts\Console\Kernel as ConsoleKernelContract; | ||
use Illuminate\Database\ConnectionInterface; | ||
use Illuminate\Database\DatabaseManager; | ||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; | ||
use Illuminate\Foundation\Testing\Concerns\InteractsWithConsole; | ||
use Illuminate\Foundation\Testing\DatabaseTruncation; | ||
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 DatabaseTruncationTest extends TestCase | ||
{ | ||
use ApplicationTestingHooks; | ||
use DatabaseTruncation; | ||
use InteractsWithConsole; | ||
|
||
protected function setUp(): void | ||
{ | ||
RefreshDatabaseState::$migrated = false; | ||
|
||
$this->setUpTheApplicationTestingHooks(); | ||
} | ||
|
||
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 testDisconnectionAfterTestCompletion() | ||
{ | ||
$this->app->instance(ConsoleKernelContract::class, m::spy(ConsoleKernel::class)); | ||
$this->app->instance('db', $database = m::mock(DatabaseManager::class)); | ||
|
||
$database->shouldReceive('getConnections')->once()->andReturn([ | ||
'default' => m::mock(ConnectionInterface::class), | ||
'mysql' => m::mock(ConnectionInterface::class), | ||
]); | ||
$database->shouldReceive('purge')->with('default'); | ||
$database->shouldReceive('purge')->with('mysql'); | ||
|
||
$this->truncateDatabaseTables(); | ||
} | ||
} |