prasit.gebsaap@gmail.com's avatar

Package test passed on local machine test, failed on GitHub action.

My package test using Orchestra Workbench. When I enable this->loadMigrationFrom on local machine test failed, but success on GitHub action. Error message is tables already exists. But if I disable this->loadMigrationFrom, it passed on local machine but failed on GitHub action. The error is tables do not exists. The problem is about package migrations, not test migration. This is my package service provider.

What is might be a problem?

0 likes
2 replies
LaryAI's avatar
Level 58

The issue you're encountering is likely due to the state of the database between test runs. When running tests locally, the database might not be reset properly between tests, causing tables to already exist. On GitHub Actions, the environment is fresh each time, so the tables do not exist initially.

Here are a few steps to ensure that your tests run consistently both locally and on GitHub Actions:

  1. Ensure Database Reset Between Tests: Use the RefreshDatabase trait to ensure that the database is reset between tests. This trait will handle rolling back the database after each test.

  2. Check Migration Loading: Ensure that migrations are loaded correctly and only once. You might be loading migrations multiple times, causing the "tables already exist" error.

  3. Use RefreshDatabase Correctly: Ensure that the RefreshDatabase trait is used correctly to reset the database state.

Here's a revised version of your TestCase class:

Additional Tips:

  1. Check Database Configuration: Ensure that your phpunit.xml or phpunit.xml.dist file is correctly configured to use the testing database.

  2. Clear Cache: Sometimes, cached configurations or migrations can cause issues. Clear the cache before running tests:

    php artisan config:clear
    php artisan cache:clear
    php artisan migrate:reset
    
  3. GitHub Actions Configuration: Ensure that your GitHub Actions workflow is correctly setting up the database. Here is an example of a typical setup:

By following these steps, you should be able to ensure that your tests run consistently both locally and on GitHub Actions.

prasit.gebsaap@gmail.com's avatar

After upgrade Orchestra to 9.41 (latest), now it is work for local machine test and GitHub Action test.

It took me 2 hours try to solve the problem.

Please or to participate in this conversation.