Closed munhing closed 7 years ago
I should be clear that earlier before installer laravel/browser-kit-testing, the DatabaseMigration is working fine. Once i did the modification, the SQLSTATE[HY000] error came back again.
Below is the ViewConcertListingTest.php code for your information:
<?php
namespace Tests\Feature;
use Tests\TestCase;
use App\Concert;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ViewConcertListingTest extends TestCase
{
use DatabaseMigrations;
/** @test */
function user_can_view_a_concert_listing()
{
// Arrange
$concert = Concert::create([
'title' => 'The Red Chord',
'date' => Carbon::parse('December 13, 2016 8:00pm'),
'ticket_price' => 3250,
'additional_information' => 'For tickets, call (555) 555-5555.'
]);
// Act
$this->visit('/concerts/' . $concert->id);
// Assert
$this->see('The Red Chord');
$this->see('December 13, 2016');
$this->see('8:00pm');
$this->see('32.50');
$this->see('For tickets, call (555) 555-5555.');
}
}
Hi @munhing,
Have you read the upgrade notes on Laravel's website? The link above will take you to the upgrade notes and near the bottom it describes how to use Laravel 5.3 testing within Laravel 5.4. I haven't tested it myself yet but fingers crossed this solves your issue.
Hi @munhing,
The new BrowserKit testing sets up traits only if there is in the namespace Laravel\BrowserKitTesting
. You need to import Laravel\BrowserKitTesting\DatabaseMigrations
instead of the old Illuminate\Foundation\Testing\DatabaseMigrations
.
Hey @munhing,
Yesterday I upgraded an app from 5.3 to 5.4 and ran into a similar issue.
You should have the following files:
TestCase.php
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
}
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;
}
}
BrowserKitTesting.php
<?php
use Illuminate\Contracts\Console\Kernel;
use Laravel\BrowserKitTesting\TestCase as BaseTestCase;
abstract class BrowserKitTest extends BaseTestCase
{
/**
* The base URL of the application.
*
* @var string
*/
public $baseUrl = 'http://localhost';
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
return $app;
}
}
Finally, any tests that you want to use the 5.3 way of testing should extend BrowserKitTest
<?php
use Illuminate\Foundation\Testing\DatabaseMigrations;
class OldTest extends BrowserKitTest
{
use DatabaseMigrations;
/**
* @test
*/
public function admin_can_view_a_list_of_clients()
{
$this->visit('/');
$this->see('Laravel');
}
}
Lastly, if you are getting a Class not found
error, be sure and properly setup the psr-4 autoload in composer.json
file.
Hi all,
Thanks for pointing me to the right direction. I managed to get it working already. @flyingearl, thanks for pointing me to the right resources. I followed the instructions in the Testing section.
@ThibaudDauce, that did the trick by importing Laravel\BrowserKitTesting\DatabaseMigrations
in the ViewConcertListingTest.php
@JuanRangel , thanks for the detailed file listing.
From the sounds of it, a couple changes were pushed to 5.4 recently to try and fix these issues.
Run composer update
, and with any luck you should be able to still use the normal Illuminate\Foundation\Testing\DatabaseMigrations
trait in your test.
Hi Adam,
Unfortunately composer update
did not resolve the issue. I still had to swap Illuminate\Foundation\Testing\DatabaseMigrations
with Laravel\BrowserKitTesting\DatabaseMigrations
to make it work.
Since it is working now, it is fine with me. Thanks.
Hi Adam,
I was following your video, 1.3 Getting to Green, but i first encounter the below:
but i resolved it by installing the package from laravel\browser-kit-testing and modified the BaseTestCase file as follows:
However, i receive a new error:
What should i do?