Skip to content

Commit

Permalink
[11.x] Allows deleting CreatesApplication trait (#49554)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nunomaduro authored Jan 3, 2024
1 parent 8e226b3 commit d30807f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/Illuminate/Foundation/Testing/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Carbon\CarbonImmutable;
use Illuminate\Console\Application as Artisan;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Bootstrap\HandleExceptions;
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
use Illuminate\Foundation\Http\Middleware\TrimStrings;
Expand Down Expand Up @@ -71,11 +73,16 @@ abstract class TestCase extends BaseTestCase
/**
* Creates the application.
*
* Needs to be implemented by subclasses.
*
* @return \Symfony\Component\HttpKernel\HttpKernelInterface
* @return \Illuminate\Foundation\Application
*/
abstract public function createApplication();
public function createApplication()
{
$app = require Application::inferBaseDirectory().'/bootstrap/app.php';

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

return $app;
}

/**
* Setup the test environment.
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Testing/Concerns/RunsInParallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Testing\Concerns;

use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\ParallelTesting;
use Illuminate\Testing\ParallelConsoleOutput;
use RuntimeException;
Expand Down Expand Up @@ -176,8 +177,7 @@ protected function createApplication()
};

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

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

0 comments on commit d30807f

Please sign in to comment.