please check the links migration file and do one of
- set the
user_idcolumn to nullable - keep the
user_idcolumn not null and set the default value to something (ex. 0)
Hey there.
Tests passing locally, but failing on Github Actions. I've looked everywhere, don't know why. Thing is, the failing on Github kind of make sense and therefore the passing locally is a bit strange. So I'm running my test using SQLite, with a proper database, not the memory one.
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value="database/database.sqlite"/>
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="TELESCOPE_ENABLED" value="false"/>
</php>
</phpunit>
laravel.yml for Github Action:
name: Laravel
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
laravel-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4.10 # Change to the php version your application is using
extensions: mbstring, bcmath # Install any required php extensions
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Create Database
run: |
mkdir -p database
touch database/database.sqlite
- name: Execute tests (Unit and Feature tests) via PHPUnit
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
run: vendor/bin/phpunit --testdox
Test that fails on Github:
class UserTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function it_should_update_a_user()
{
// With only that line I get the error
$user = User::factory()->create();
}
}
Error thrown:
General error: 1 Cannot add a NOT NULL column with default value NULL (SQL: alter table "links" add column "user_id" integer not null)
So I understand why SQLite would be complaning about that. You can't alter a table with default null columns. Fine. But then why is it passing locally???
Any help you be greatly appreciated.
Please or to participate in this conversation.