Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Aug 11, 2023
1 parent c389d6c commit bd4cede
Showing 1 changed file with 43 additions and 16 deletions.
59 changes: 43 additions & 16 deletions laravel/bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
<?php

use Orchestra\Testbench\Dusk\Console\Commander;

$APP_KEY = $_SERVER['APP_KEY'] ?? $_ENV['APP_KEY'] ?? 'AckfSECXIvnK5r28GVIWUAxmbBSjTsmF';
$DB_CONNECTION = $_SERVER['DB_CONNECTION'] ?? $_ENV['DB_CONNECTION'] ?? 'testing';

$config = ['env' => ['APP_KEY="'.$APP_KEY.'"', 'DB_CONNECTION="'.$DB_CONNECTION.'"'], 'providers' => []];

$app = (new Commander($config, realpath(__DIR__.'/../../')))->laravel();

unset($APP_KEY, $DB_CONNECTION, $config);

if (file_exists(__DIR__.'/../routes/testbench.php')) {
$router = $app->make('router');

require __DIR__.'/../routes/testbench.php';
}
use function Orchestra\Testbench\default_environment_variables;
use Orchestra\Testbench\Foundation\Application;
use Orchestra\Testbench\Foundation\Bootstrap\LoadEnvironmentVariablesFromArray;
use Orchestra\Testbench\Foundation\Config;
use Orchestra\Testbench\Workbench\Bootstrap\StartWorkbench;

/**
* Create Laravel application.
*
* @param string $workingPath
* @return \Illuminate\Foundation\Application
*/
$createApp = function (string $workingPath) {
$config = Config::loadFromYaml($workingPath);

$hasEnvironmentFile = file_exists("{$workingPath}/.env");

return Application::create(
$config['laravel'],
function ($app) use ($config, $hasEnvironmentFile) {
(new StartWorkbench($config))->bootstrap($app);

if ($hasEnvironmentFile === false) {
(new LoadEnvironmentVariablesFromArray(
! empty($config['env']) ? $config['env'] : default_environment_variables()
))->bootstrap($app);
}
},
['load_environment_variables' => $hasEnvironmentFile, 'extra' => $config->getExtraAttributes()],
);
};

$app = $createApp(realpath(__DIR__.'/../'));

unset($createApp);

/** @var \Illuminate\Routing\Router $router */
$router = $app->make('router');

collect(glob(__DIR__.'/../routes/testbench-*.php'))
->each(function ($routeFile) use ($app, $router) {
require $routeFile;
});

return $app;

0 comments on commit bd4cede

Please sign in to comment.