Skip to content

Commit d30807f

Browse files
authored
[11.x] Allows deleting CreatesApplication trait (#49554)
* Improves application builder * Uses composer instead of `debug_backtrace` * Removes non used import * Allows `CreateApplication` to be optional * Fixes non-bootstrapping app * Fixes coding style
1 parent 8e226b3 commit d30807f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/Illuminate/Foundation/Testing/TestCase.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use Carbon\CarbonImmutable;
66
use Illuminate\Console\Application as Artisan;
7+
use Illuminate\Contracts\Console\Kernel;
78
use Illuminate\Database\Eloquent\Model;
9+
use Illuminate\Foundation\Application;
810
use Illuminate\Foundation\Bootstrap\HandleExceptions;
911
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
1012
use Illuminate\Foundation\Http\Middleware\TrimStrings;
@@ -71,11 +73,16 @@ abstract class TestCase extends BaseTestCase
7173
/**
7274
* Creates the application.
7375
*
74-
* Needs to be implemented by subclasses.
75-
*
76-
* @return \Symfony\Component\HttpKernel\HttpKernelInterface
76+
* @return \Illuminate\Foundation\Application
7777
*/
78-
abstract public function createApplication();
78+
public function createApplication()
79+
{
80+
$app = require Application::inferBaseDirectory().'/bootstrap/app.php';
81+
82+
$app->make(Kernel::class)->bootstrap();
83+
84+
return $app;
85+
}
7986

8087
/**
8188
* Setup the test environment.

src/Illuminate/Testing/Concerns/RunsInParallel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Testing\Concerns;
44

55
use Illuminate\Contracts\Console\Kernel;
6+
use Illuminate\Foundation\Application;
67
use Illuminate\Support\Facades\ParallelTesting;
78
use Illuminate\Testing\ParallelConsoleOutput;
89
use RuntimeException;
@@ -176,8 +177,7 @@ protected function createApplication()
176177
};
177178

178179
return $applicationCreator->createApplication();
179-
} elseif (file_exists($path = getcwd().'/bootstrap/app.php') ||
180-
file_exists($path = getcwd().'/.laravel/app.php')) {
180+
} elseif (file_exists($path = (Application::inferBaseDirectory().'/bootstrap/app.php'))) {
181181
$app = require $path;
182182

183183
$app->make(Kernel::class)->bootstrap();

0 commit comments

Comments
 (0)