'Laravel + phpunit + github actions = Failed asserting that '1' is identical to 1

I'm trying to make CI pipeline and run phpunit tests via GitHub actions.
First of all: tests work fine on my local machine (mac os).
Then, when I do git push my tests don't pass on the GitHub actions server (ubuntu).
I got:

13) Modules\User\Tests\Feature\UserProfileEndpointTest::test_profile_index_endpoint
328
Property [discounts.0.user_id] does not match the expected value.
329
Failed asserting that '1' is identical to 1.

I can see that actual value is converted to string (Idk why)

Here is the code that causes the error:

// some code before assetion
$this->actingAs($user)
            ->get(route('profile.index'))
            ->assertStatus(200)
            ->assertInertia(fn(AssertableInertia $page) => $page
                ->component('User::Profile', false)
                // other assertions
                ->has('discounts')
                ->count('discounts', $user->discounts()->whereDiscountableType('pump_series')->count())
                ->has('discounts.0', fn(AssertableInertia $page) => $page
                    ->has('key')
                    ->has('discountable_id')
                    ->has('discountable_type')
                    ->where('user_id', $user->id)  // <---- exception is thrown here
                    ->has('name')
                    ->has('value')
                    // other assertions
                )
            );

There is no something special or extraordinary and as I said: it works fine on my local machine. But on GitHub-actions server I got certain number of similar errors:

Failed asserting that '548365.0' is identical to 548365.
Failed asserting that '256115.0' is identical to 256115.

and so on... Mb it depends of the platform where tests are running? But I have no idea what to do.
Thanks.



Solution 1:[1]

I have the same problem with running PHP tests on GitHub actions. My tests work fine locally but not in the CI server. I solved it by setting an Eloquent Attribute Casting in the model. The attribute automatically casts to an integer value whenever you query the eloquent model.

class SomeModel extends Model
{
    use HasFactory;

    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'user_id' => 'integer',
    ];
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Karl Hill