JayBizzle / Laravel-Migrations-Organiser

A Laravel package to help organise migrations
MIT License
110 stars 18 forks source link

Adding Provider into the config/app.php causes test to fail #13

Closed ericadamski closed 7 years ago

ericadamski commented 7 years ago

When we run the tests without the line in the config/app.php file they all pass. As soon as I add in Jaybizzle\MigrationsOrganiser\MigrationsOrganiserServiceProvider::class, phpunit fails not being able to find our migrations.

JayBizzle commented 7 years ago

Which tests are failing?

ericadamski commented 7 years ago

All of our own tests are failing. The error messages says that it cannot find the most recent migration file.

JayBizzle commented 7 years ago

Can you give me an example of a failing test?

ericadamski commented 7 years ago

Every error is similar to this.

// // PHPUnit 5.6.1 by Sebastian Bergmann and contributors.

EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 65 / 97 ( 67%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE                                  97 / 97 (100%)

Time: 15.79 seconds, Memory: 60.00MB

There were 97 errors:

1) Tests\Integration\ApplicantsTest::itListsApplicants
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table: people (SQL: insert into "people" ("name", "email", "password", "remember_token", "updated_at", "created_at") values (Willow Hintz Sr., nitzsche.lucinda@example.net, $2y$10$YA9Bku1X81JpNuJPqyE76.82.M2se64cbA91BK6b6JQ08A8JYvvNm, UBEG8mAwm5, 2016-12-07 13:36:06, 2016-12-07 13:36:06))

/Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:761
/Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:717
/Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:481
/Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:435
/Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php:32
/Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2142
/Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1433
/Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1607
/Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1576
/Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1472
/Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:87
/Users/Sgt-Wikkidoo/MB3/marvel/tests/TestCase.php:23
JayBizzle commented 7 years ago

Hmmm...a possible quick fix could be to run the following command before your tests run...

Artisan::call('migrate:disorganise');

Then, when your tests complete, run...

Artisan::call('migrate:organise');

Let me know if that works

ericadamski commented 7 years ago

I have already tried that, I even went as far as removing the package keeping my migrations all inside one directory and just added the provider and it still fails the same way.

ericadamski commented 7 years ago

Here is what I have the my base test file. There is some code that I didn't include in the setup like creating a user.

protected function setup()
{
    parent::setup();
    \Artisan::call('migrate:disorganise');
}
public static function tearDownAfterClass()
{
    \Artisan::call('migrate:organise', [ '--force' => true ]);
}

It crashes with an error like

// // PHPUnit 5.6.1 by Sebastian Bergmann and contributors.

EEEEEEEEPHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Container/Container.php:762
Stack trace:
#0 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Container/Container.php(643): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(709): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 [internal function]: Illuminate\Foundati in /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 762

Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Container/Container.php:762
Stack trace:
#0 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Container/Container.php(643): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(709): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 [internal function]: Illuminate\Foundati in /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 762
PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Container/Container.php:762
Stack trace:
#0 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Container/Container.php(643): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(709): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/la in /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 762

Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Container/Container.php:762
Stack trace:
#0 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Container/Container.php(643): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(709): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 /Users/Sgt-Wikkidoo/MB3/marvel/vendor/la in /Users/Sgt-Wikkidoo/MB3/marvel/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 762
ericadamski commented 7 years ago

I also cannot seem to run php artisan migrate I get

vagrant@homestead:~/MB3/marvel$ php artisan migrate
Migration table created successfully.
Nothing to migrate.
JayBizzle commented 7 years ago

I also cannot seem to run php artisan migrate I get

And your migrations are organised?

ericadamski commented 7 years ago

Yes.

JayBizzle commented 7 years ago

What version of Laravel?

ericadamski commented 7 years ago

I'm running 5.3.10

ericadamski commented 7 years ago

Same issue when updating to latest (5.3.26)

JayBizzle commented 7 years ago

Ive just tested it on a clean install of Laravel with no issues.

The fact it says you have nothing to migrate when running the command in the CLI has alarm bells ringing, but pretty hard for me to debug without a proper scenario to look at.

If you could make a test app on a repo that i can pull and test with, i will definitely look into this further

korygorsky commented 7 years ago

Hey @JayBizzle, I'm on a team with @ericadamski.

Thanks for taking the time to go back and forth with us.

It appears to be an issue on rollback. We didn't realize it was on rollback because it was happening in our tests where we were using the DatabaseMigrations trait. This initiates a migrate and a rollback on every test and the error was happening in the rollback.

I've been able to create the issue using a fresh install of Laravel. I've created a repo for the issue.

Steps to reproduce

  1. Clone the repo (here: https://github.com/korygorsky/laravel-migrations-organiser-issue-13)
  2. Run composer install in the terminal
  3. No key generation needed as I've included the .env file in the repo
  4. run touch database/database.sqlite in the terminal
  5. run php artisan migrate:organise in the terminal
  6. run php artisan migrate in the terminal
  7. run php artisan migrate:rollback in the terminal
    • You should see the issue on Rollback

My Thoughts

Laravel's rollback method in it's Migrator.php calls your getMigrationFiles method, but its expecting a different format then it receives.

Returned Format from getMigrationFiles in Laravel-Migrations-Organiser
array:2 [
  0 => "2014_10_12_000000_create_users_table"
  1 => "2014_10_12_100000_create_password_resets_table"
]
Returned Format from getMigrationFiles in Built-in Laravel Migrator.php
array:2 [
  "2014_10_12_000000_create_users_table" => "/Users/kory/Sites/TestMigrationOrganise/database/migrations/2014_10_12_000000_create_users_table.php"
  "2014_10_12_100000_create_password_resets_table" => "/Users/kory/Sites/TestMigrationOrganise/database/migrations/2014_10_12_100000_create_password_resets_table.php"
]

I'm taking a look at this to see if I can resolve this with a PR. Let me know if you've run across this before.

korygorsky commented 7 years ago

Submitted PR #14 to solve this issue.

JayBizzle commented 7 years ago

Hey @korygorsky

Thanks for that example repo, these kind of things really help when debugging this kind of stuff. I ran through the steps you mentioned and could indeed replicate the issue.

Great work on the PR, i have now merged that and released v4.0.2

Thanks again!

korygorsky commented 7 years ago

Glad to help out @JayBizzle. Thanks for all your work on this.