Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

abkrim's avatar
Level 13

[SOLVED] Upgrade system to PHP 7.4 fail only test for users

Hi.

I'm desesperate.

Today upgrade my develop system to PHP 7.4. Well after upgrade, run test and I see fails on Users tests.

  1. I run test by folder (models) Domain, Mailboxes. All work fine
  2. Run test for users, and I get error.

Error?

Only user nas a problem, and there're using mysql database, instead sqlite in memory.

A simple test for verify problem

function a_super_admin_can_get_index_users()
    {
        Passport::actingAs(
            factory(User::class)->create(['is_super_admin' => true])
        );

        // factory(User::class, 15)->create();

        $response = $this->get('/api/v1/users');

        dd($response);  // For verify problem

        $response
            ->assertStatus(200)
            ->assertJsonCount(15, $key = 'data');
    }

Response show 28 users there're in Mysql database. Buty my test using sqlite.

Desesperate

0 likes
11 replies
Nakov's avatar

@abkrim are you using the RefreshDatabase trait or any other trait so you start with a fresh database after each test?

abkrim's avatar
Level 13

Are working for last 6 months, using sqlite in memory

On TestCase using

use CreatesApplication, DatabaseMigrations, DatabaseTransactions;

And 25 files of test for Domains, and Mailboxes, working with same configuration. An this test, running several factories without problem.

Only fail Users tests.

Well, now after make changes and reboot machine. error is for all

vendor/bin/phpunit                                                                                                                                                                                

In DatabaseManager.php line 152:
                                     
  Database [sqlite] not configured.                                       

 a tinker                                                                                                                                                                              ✔  
>>> config('database.connections')
=> [
     "mysql" => [
       "driver" => "mysql",
       "url" => null,
       "host" => "192.168.1.40",
       "port" => "3306",
       "database" => "albarid",
       "username" => "albarid",
       "password" => "wdYnvN88y5YvhYREh9VP",
       "unix_socket" => "",
       "charset" => "utf8mb4",
       "collation" => "utf8mb4_unicode_ci",
       "prefix" => "",
       "prefix_indexes" => true,
       "strict" => true,
       "engine" => null,
       "options" => [],
     ],
     "testing" => [
       "driver" => "sqlite",
       "database" => ":memory:",
       "prefix" => "",
       "foreign_key_constraints" => true,
     ],
   ]

Just unisntall php 7.4 and come back to php 7.3, restores all files from last ngith backup and all test work fine.

PHPUnit 8.5.0 by Sebastian Bergmann and contributors.

................................................................. 65 / 77 ( 84%)
............                                                      77 / 77 (100%)

Time: 12 seconds, Memory: 44.00 MB

OK (77 tests, 159 assertions)

Nakov's avatar

@abkrim so do you configure the db using .env.testing file or directly in phpunit.xml?

abkrim's avatar
Level 13

In phpunit.xml

<server name="APP_ENV" value="testing"/>
<server name="DB_CONNECTION" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>

database.php

'testing' => [
            'driver' => 'sqlite',
            'database' => ':memory:',
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],
abkrim's avatar
Level 13

Oh my good...

Just I see a problem and don't understand.

Just added on User model a same code for user pagination (used in Domains and Mailoboxes)

public function __construct(array $attributes = array())
    {
        parent::__construct($attributes);

        $this->perPage = config('albarid.pagination');
    }

Well. If delete this piece of code, work fine.

I don't understand. I'm using this code in all my models and work fine.

abkrim's avatar
Level 13

I did not like your answer, since there is no problem in it. The construct inherits from the father, and it is necessary to me since the assigned value is not fixed in the model, but in the configuration.

In any case, delete the constructor, and limit me to setting the fixed value using its method, and the result is the same.

1) Tests\Feature\Users\UserFeaturesTest::a_super_admin_can_get_index_users
Failed to assert that the response count matched the expected 15
Failed asserting that actual size 43 matches expected size 15.

Once again, when entering the limit, the test fails, and the tes uses mysql instead of sqlite in memory.

Seen this I will open a PR since I think it is a bug,

Thanks for your time.

abkrim's avatar
Level 13

Mistake is TestCase setUp() method add a seeder of Users.. a line add a factory user with 25 items.

abkrim's avatar
Level 13

In my tests I had not taken into account the page, and I placed a line in TestCase in which to capture the tests, a factory of 25 users was made.

By eliminating it, I corrected the problem and then checked that in php 74 everything worked fine.

It is what makes me fall in love with the tests.

Please or to participate in this conversation.