diff --git a/README.md b/README.md index c699767..e7ab139 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,6 @@ use Laravel\BrowserKitTesting\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase { - use CreatesApplication; - public $baseUrl = 'http://localhost'; // ... diff --git a/src/TestCase.php b/src/TestCase.php index d202711..e902d6c 100755 --- a/src/TestCase.php +++ b/src/TestCase.php @@ -2,7 +2,9 @@ namespace Laravel\BrowserKitTesting; +use Illuminate\Contracts\Console\Kernel; use Illuminate\Database\Eloquent\Model; +use Illuminate\Foundation\Application; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -12,6 +14,7 @@ use Illuminate\Support\Facades\Facade; use Mockery; use PHPUnit\Framework\TestCase as BaseTestCase; +use RuntimeException; abstract class TestCase extends BaseTestCase { @@ -55,11 +58,22 @@ 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() + { + if (method_exists(Application::class, 'inferBaseDirectory')) { + $app = require Application::inferBaseDirectory().'/bootstrap/app.php'; + + $app->make(Kernel::class)->bootstrap(); + + return $app; + } + + throw new RuntimeException( + 'Unable to guess application base directory. Please use the [Tests\CreatesApplication] trait.', + ); + } /** * Setup the test environment.