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 Dec 4, 2024
1 parent 896c2e6 commit 608d5c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,5 +462,15 @@ function laravel_or_fail($app, ?string $caller = null): Application
return $app;
}

if (\is_null($caller)) {
$caller = transform(debug_backtrace()[1], function ($debug) {
if (isset($debug['class']) && isset($debug['function'])) {
return sprintf('%s::%s', $debug['class'], $debug['function']);
}

return $debug['function'];
});
}

throw Exceptions\ApplicationNotAvailableException::make($caller ?? debug_backtrace()[1]['function']);
}
13 changes: 13 additions & 0 deletions tests/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Orchestra\Testbench\Tests;

use Illuminate\Foundation\Application;
use Orchestra\Testbench\Exceptions\ApplicationNotAvailableException;
use Orchestra\Testbench\TestCase;
use PHPUnit\Runner\Version;

use function Orchestra\Testbench\laravel_or_fail;
use function Orchestra\Testbench\laravel_version_compare;
use function Orchestra\Testbench\phpunit_version_compare;

Expand All @@ -24,4 +26,15 @@ public function it_can_compare_phpunit_version()
$this->assertSame(0, phpunit_version_compare(Version::id()));
$this->assertTrue(phpunit_version_compare(Version::id(), '=='));
}

/**
* @test
*/
public function it_can_throw_application_not_available_application_when_app_is_not_laravel()
{
$this->expectException(ApplicationNotAvailableException::class);
$this->expectExceptionMessage(sprintf('Application is not available to run [%s]', __METHOD__));

laravel_or_fail(null);
}
}

0 comments on commit 608d5c0

Please sign in to comment.