CaiWuXiTong/tests/CreatesApplication.php

38 lines
998 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Tests;
use Illuminate\Contracts\Console\Kernel;
use RuntimeException;
trait CreatesApplication
{
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$testingConfigCache = __DIR__ . '/../bootstrap/cache/config-testing.php';
putenv('APP_CONFIG_CACHE=' . $testingConfigCache);
$_ENV['APP_CONFIG_CACHE'] = $testingConfigCache;
$_SERVER['APP_CONFIG_CACHE'] = $testingConfigCache;
$app = require __DIR__ . '/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
if (
! $app->environment('testing')
|| config('database.default') !== 'sqlite'
|| config('database.connections.sqlite.database') !== ':memory:'
) {
throw new RuntimeException('测试环境未使用内存 SQLite,已拒绝执行以保护共享数据库。');
}
return $app;
}
}