<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
californiamountainsnake / laravel-database-test-case example snippets
namespace Tests;
use CaliforniaMountainSnake\LaravelDatabaseTestCase\AbstractDatabaseTestCase;
class DatabaseTestCase extends AbstractDatabaseTestCase
{
/**
* Load custom test dependencies.
*/
protected function initDependencies(): void
{
}
/**
* Get the database connection for the root user.
* You are not MigrationDbConnection(): string
{
return 'mysql';
}
/**
* Get the array with databases connections that will be replaced to the test ones.
* All test databases will be deleted after tests, also in a case of exceptions or errors.
*
* @return string[]
*/
protected function getMockedDbConnections(): array
{
return [
'mysql',
];
}
/**
* Do we need to create temporary databases for the mocked connections before the tests?
* Sometimes you create databases directly in the migrations.
*
* @return bool
*/
protected function isCreateMockedDatabases(): bool
{
return true;
}
/**
* Get the absolute path to the /bootstrap/app.php.
*
* @return string
*/
public function getAppFilePath(): string
{
return __DIR__ . '/../bootstrap/app.php';
}
}
namespace Tests\Feature;
use Illuminate\Support\Facades\DB;
use SebastianBergmann\RecursionContext\InvalidArgumentException;
use Tests\DatabaseTestCase;
class SimpleDatabaseTest extends DatabaseTestCase
{
/**
* @throws InvalidArgumentException
*/
public function testGetUsers(): void
{
$users = DB::table('users')->get()->toArray(); // Gets users from the temp seeded database.
$this->assertTrue(count($users) > 0);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.