2

Almost all Laravel projects hosted on Github use use Illuminate\Contracts\Console\Kernel; Console Kernel to create an application/ for bootstrapping the whole app for testing using vendor/bin/phpunit

For example this is the Voten laravel application https://github.com/voten-co/voten/blob/master/tests/CreatesApplication.php

<?php

namespace Tests;

use Illuminate\Contracts\Console\Kernel;

trait CreatesApplication
{
    /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
    public function createApplication()
    {
        $app = require __DIR__.'/../bootstrap/app.php';

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

        return $app;
    }
}

I wonder why we don't use the use Illuminate\Contracts\Http\Kernel;

Is that because vendor/bin/phpunit starts normally within the commandline, so it's a requirement to use the Console Kernel instead of the Http one? I have searched online for the reason why is it like, but I didn't find an answer.

I know the difference between the two Kernels and when each one is being used. Here is a good answer about the difference between the two of them How to use Console Kernel is Laravel PHP?

I am sure there is a good reason for using Console Kernel for testing! But I don't why, can anyone explain that for me?

And is it possible then to use the Http Kernel instead of the Console kernel?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.