stevebaker1984's avatar

Updating table values - test cases fail

Hello, i've got a migration to update the names of some fields, however when i try to run the test cases they fail because the migration runs before the seeder so it comes back null trying to find negativekWh in this case, is there a way to maek the seeder run only on unittest before the new migration runs


        $negative = \App\Models\ReadingType::where('name', 'NegativekWh')->first();
        $negative->update([
            'name' => 'kWh - Export',
        ]);

Managed to do this by putting the changes in a seperate seeder file for the test cases, however on production seeders dont get ran so i'd need a migration to do the same? But then im back to test cases failing

0 likes
5 replies
Tray2's avatar

Normally you don't seed the database per se, you just create the data you need for the test, nothing more, nothing less.

stevebaker1984's avatar

sadly someone before me wrote the test cases, its on the back end of a todo list so im stuck with how it is at the moment.

However the order of things would still be an issue for someone downloading the repo to set up a new machine for example, the update migration would try to run before the seeder starts and fail because theres no data

stevebaker1984's avatar

@Tray2 sorry, the testing does use a separate database itself, I meant for if someone were to need to run the migrations from fresh ( to setup a new local environment etc) then it would fail

Tray2's avatar

@stevebaker1984 Just make a simple shell script that logs in and creates the database for you, and have them run that first, then it isn't a problem

Please or to participate in this conversation.