@christophrumpel Are you running any non-Eloquent queries which are not implemented in SQLite by any chance?
PhpUnit hanging with DatabaseMigrations trait
Hey,
since I wanted to change my tests to use sqlite in-memory with the DatabaseMigrations trait phpunit is hanging with nor output or error.
This happens for every test where I use the DatabaseMigrations trait.
database.php:
'connections' => [
...
'testing' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', ':memory:'),
'prefix' => '',
],
...
phpunit.xml: find here: http://laravel.io/bin/0eLx2
(I wasn't able to post the code here, it was stripped every time)
Nope.
I dumped some string to find the location of the problem. Inside the trait everything is working before the artisan migrate command. After that it is over.
No one an idea?
Still no one?
Can you show us your tests?
yes of course, but it happens with every test where I use "DatabaseMigrations" trait.
<?php
use Famulous\Http\Repositories\Recipes\Recipe;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class GetLatestRecipesTest extends TestCase
{
use DatabaseMigrations;
public function testWithCountOne()
{
...
$this->assertEquals(1, $latestRecipes->count());
}
...
I am still stumped. What's your setup? Which version of Laravel, Homestead etc.?
Here some infos:
Homestead: 2.0.7 Laravel: 5.2.14
Here is my TestCase but I think it is as the default one:
<?php
class TestCase extends Illuminate\Foundation\Testing\TestCase
{
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost';
public function setUp()
{
parent::setUp();
}
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__ . '/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
}
Let me know if I can provide some more information. This is so strange. The cursor is blinking like normal when running phpunti, but nothing happens. Have watched it like 15min.
Well firstly I would definitely update homestead, as 2.0.7 is over a year old. There may well be something in there that would fix this.
Ok strange, because homestead update is telling I have the latest version:
==> default: Checking for updates to 'laravel/homestead'
default: Latest installed version: 0.4.1
default: Version constraints:
default: Provider: virtualbox
==> default: Box 'laravel/homestead' (v0.4.1) is running the latest version.
@christophrumpel Are you executing the tests within homestead or in your "local" environment, i.e. where do you execute phpunit? Executing phpunit in your local environment might fail to connect to the database within homestead. See this thread.
Hey, thx but I tried it both. Without the trait the tests are working, or at least I get errors because the tables do not exist which is as expected because I want the trait to migrate the database.
I'm stumped. Can we see your migrations?
Have you tried just running one migration, then building them up to see if any of them are killing it? Move the migrations you don't need into a temp directory etc. then re-introduce them one by one...
I see that you use sqlite as the database driver, do you have the package doctrine/dbal installed?
composer require doctrine/dbal
Documentation: https://laravel.com/docs/5.2/migrations#changing-columns
@bobbybouwmann never knew that! Guess I need to RTM a bit better :D Cheers
@bobbybouwmann hey, yes I got this package. Sqlite was always working. I just changed to use in "in-memory" and to use the Migration trait.
@ifpingram I tried removing alle migrations and putting them in another folder and still I get the same behaviour. The cursor is blinking but nothing happens. I really would love to se an error now!
@christophrumpel I wish I could help you further, but I'm at a loss for other suggestions now :(
@ifpingram Thx anyway. I know I don't have much to offer for further investigation.
Just a little update:
I did not find the problem but I realised it is not about the sqlite in-memory usage. Even if I use a sqlite file, the databaseMigration trait is not working.
I also just tried to call the artisan migrate command directly before every test, but I got the same result. Blinking cursor and no output.
// TestCase File
<?php
class TestCase extends Illuminate\Foundation\Testing\TestCase
{
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost';
public function setUp()
{
parent::setUp();
}
/**
* @before
*/
public function runDatabaseMigrations()
{
$this->artisan('migrate');
}
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__ . '/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
}
PS: migration is working normally when I manually trigger the migrate command from the command line.
Just another little update. On a new project the trait and migrations are working perfectly. Still not feeling closer to the problem...
Just another try. I created a complete new laravel application:
1.) set up testing connection to sqlite and :memory: -> WORKS 2.) user databaseMigration in ExampleTest -> WORKS 3.) Copying my migrations -> ERROR doctrine/dbal missing ( is need because of FK checks with sqlite) 4.) Install doctrine/dbal, run phpunit -> error helper class missing I am using for the FK checks 5.) Copy helper class -> Error because of illuminate html package 6.) install illuminate html -> phpunit hangs up like described in the posts above 7.) removing illuminate html -> still hanging and I cant get it away
I am not sure if I am getting closer to the problem. It is driving me nuts!!! Is there a way to set a reward for the ons who finds the problem? =)
I had almost the exact same problem. I realised that i upgraded from laravel 5.1 to 5.2. So i double check if i forgot something in the upgrade process: https://laravel.com/docs/5.2/upgrade#upgrade-5.2.0.
I forgot to set the new environment variable APP_ENV in the app.php config and behold phpunit worked again. So maybe you got the same problem.
OMG @KoenRijpstra you are totally right. This was the problem. Thx a lot!!
So glad @KoenRijpstra found it, I was feeling for you there @christophrumpel :)
Ths @ifpingram =) This really drove me crazy!=)
UGH thanks soo much @KoenRijpstra, drove me nuts! Could not figure it out.
Please or to participate in this conversation.