Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Jan 23, 2024
1 parent bf9a44b commit ba72607
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 48 deletions.
31 changes: 5 additions & 26 deletions src/Concerns/CreatesApplication.php
Expand Up @@ -36,6 +36,7 @@
trait CreatesApplication
{
use InteractsWithWorkbench;
use WithLaravelBootstrapFile;

/**
* Get Application's base path.
Expand Down Expand Up @@ -251,33 +252,11 @@ protected function getBasePath()
* @internal
*
* @param string $filename
* @return string
*/
protected function getDefaultApplicationBootstrapFile(string $filename): string
{
return default_skeleton_path(join_paths('bootstrap', $filename));
}

/**
* Get application bootstrap file path (if exists).
*
* @internal
*
* @param string $filename
* @return string|null
* @return string|false
*/
protected function getApplicationBootstrapFile(string $filename): ?string
protected function getDefaultApplicationBootstrapFile(string $filename): string|false
{
$bootstrapFile = (string) realpath(join_paths($this->getBasePath(), 'bootstrap', $filename));
$defaultBootstrapFile = (string) realpath($this->getDefaultApplicationBootstrapFile($filename));

if ($defaultBootstrapFile === $bootstrapFile) {
return static::usesTestingConcern(WithWorkbench::class) && is_file($workbenchFile = workbench_path(join_paths('bootstrap', $filename)))
? (string) realpath($workbenchFile)
: null;
}

return is_file($bootstrapFile) ? $bootstrapFile : null;
return realpath(default_skeleton_path(join_paths('bootstrap', $filename)));
}

/**
Expand Down Expand Up @@ -334,7 +313,7 @@ final protected function resolveDefaultApplication()
*/
protected function resolveApplication()
{
static::$cacheApplicationBootstrapFile ??= ($this->getApplicationBootstrapFile('app.php') ?? false);
static::$cacheApplicationBootstrapFile ??= $this->getApplicationBootstrapFile('app.php');

if (\is_string(static::$cacheApplicationBootstrapFile)) {
$APP_BASE_PATH = $this->getBasePath();
Expand Down
57 changes: 57 additions & 0 deletions src/Concerns/WithLaravelBootstrapFile.php
@@ -0,0 +1,57 @@
<?php

namespace Orchestra\Testbench\Concerns;

use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\Foundation\Application as Testbench;

use function Illuminate\Filesystem\join_paths;
use function Orchestra\Testbench\workbench_path;

trait WithLaravelBootstrapFile
{
use InteractsWithTestCase;

/**
* Get application bootstrap file path (if exists).
*
* @internal
*
* @param string $filename
* @return string|false
*/
protected function getApplicationBootstrapFile(string $filename): string|false
{
$bootstrapFile = realpath(join_paths($this->getBasePath(), 'bootstrap', $filename));
$defaultBootstrapFile = $this->getDefaultApplicationBootstrapFile($filename);

if (is_string($defaultBootstrapFile) && $defaultBootstrapFile === $bootstrapFile) {
if (static::usesTestingConcern(WithWorkbench::class) || $this instanceof Testbench) {
return is_file($workbenchFile = workbench_path(join_paths('bootstrap', $filename))) ? (string) realpath($workbenchFile) : false;
}

return false;
}

return $bootstrapFile;
}

/**
* Get base path.
*
* @internal
*
* @return string
*/
abstract protected function getBasePath();

/**
* Get the default application bootstrap file path (if exists).
*
* @internal
*
* @param string $filename
* @return string|false
*/
abstract protected function getDefaultApplicationBootstrapFile(string $filename): string|false;
}
22 changes: 0 additions & 22 deletions src/Foundation/Application.php
Expand Up @@ -251,28 +251,6 @@ protected function getPackageBootstrappers($app)
return Arr::wrap($bootstrappers);
}

/**
* Get application bootstrap file path (if exists).
*
* @internal
*
* @param string $filename
* @return string|null
*/
protected function getApplicationBootstrapFile(string $filename): ?string
{
$bootstrapFile = (string) realpath(join_paths($this->getBasePath(), 'bootstrap', $filename));
$defaultBootstrapFile = (string) realpath($this->getDefaultApplicationBootstrapFile($filename));

if ($defaultBootstrapFile === $bootstrapFile) {
return is_file($workbenchFile = workbench_path(join_paths('bootstrap', $filename)))
? (string) realpath($workbenchFile)
: null;
}

return is_file($bootstrapFile) ? $bootstrapFile : null;
}

/**
* Resolve application resolving callback.
*
Expand Down
2 changes: 2 additions & 0 deletions src/TestCase.php
Expand Up @@ -107,6 +107,8 @@ protected function setUpTheTestEnvironmentTraitToBeIgnored(string $use): bool
Concerns\InteractsWithWorkbench::class,
Concerns\Testing::class,
Concerns\WithFactories::class,
Concerns\WithLaravelBootstrapFile::class,
Concerns\WithLaravelMigrations::class,
Concerns\WithWorkbench::class,
]);
}
Expand Down

0 comments on commit ba72607

Please sign in to comment.