benedmunds / CodeIgniter-Ion-Auth

Simple and Lightweight Auth System for CodeIgniter
http://benedmunds.com/ion_auth/
MIT License
2.35k stars 1.14k forks source link

Codeigniter does not run migration for IonAuth in tests (reopened) #1587

Open dgvirtual opened 1 month ago

dgvirtual commented 1 month ago

I have a test class that should run migrations in all namespaces:

namespace Tests\App\Libraries;

use App\Libraries\InvoicesLib;
use App\Models\InvoicesModel;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use Tests\Support\Database\Seeds\ClientsSeeder;
use Tests\Support\Database\Seeds\IncomeTypesSeeder;
use Tests\Support\Database\Seeds\InvoicesSeeder;
use Tests\Support\Database\Seeds\ServiceTypesSeeder;
use Tests\Support\Database\Seeds\SettingsSeeder;

/**
 * @internal
 */
final class InvoicesLibTest extends CIUnitTestCase
{
    use DatabaseTestTrait;

    protected $DBGroup = 'tests';

    // For Migrations
    protected $migrate     = true;
    protected $migrateOnce = false;
    protected $refresh     = true;
    protected $namespace; // = from all namespaces

All migrations are run except for IonAuth. Therefore I see errors like:

dg@tvenkinys:~/Programavimas/saskaitos$ vendor/bin/phpunit --filter InvoicesLib
PHPUnit 9.6.20 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.6
Configuration: /home/dg/Programavimas/saskaitos/phpunit.xml
Warning:       XDEBUG_MODE=coverage or xdebug.mode=coverage has to be set

EEEEEEEEE                                                           9 / 9 (100%)

Time: 00:06.765, Memory: 14.00 MB

There were 9 errors:

1) Tests\App\Libraries\InvoicesLibTest::testCalculateInvoiceNumber
CodeIgniter\Database\Exceptions\DatabaseException: SQLite3::exec(): no such table: main.users

/home/dg/Programavimas/saskaitos/vendor/codeigniter4/framework/system/Database/BaseConnection.php:647
/home/dg/Programavimas/saskaitos/vendor/codeigniter4/framework/system/Database/BaseBuilder.php:2307
/home/dg/Programavimas/saskaitos/tests/_support/Database/Seeds/ClientsSeeder.php:81
/home/dg/Programavimas/saskaitos/vendor/codeigniter4/framework/system/Database/Seeder.php:145
/home/dg/Programavimas/saskaitos/vendor/codeigniter4/framework/system/Test/DatabaseTestTrait.php:223
/home/dg/Programavimas/saskaitos/vendor/codeigniter4/framework/system/Test/DatabaseTestTrait.php:209
/home/dg/Programavimas/saskaitos/vendor/codeigniter4/framework/system/Test/DatabaseTestTrait.php:190
/home/dg/Programavimas/saskaitos/vendor/codeigniter4/framework/system/Test/DatabaseTestTrait.php:58
/home/dg/Programavimas/saskaitos/vendor/codeigniter4/framework/system/Test/CIUnitTestCase.php:249
/home/dg/Programavimas/saskaitos/tests/app/Libraries/InvoicesLibTest.php:46

Caused by
CodeIgniter\Database\Exceptions\DatabaseException: SQLite3::exec(): no such table: main.users

What could be the cause of it?

also, when I run in an empty project

php spark migrate --all

The ionAuth migration is omitted, while other non App namespace migrations are included (I use only one, Settings).

I have to run

php spark migrate -n IonAuth

to get it to execute.

I am doing these tests on Codeigniter 4.4.8. On earlier versions (before 4.4.1, I would presume) this did work.

dgvirtual commented 1 month ago

[see comments below] Well, nevermind perhaps. I just did a test on another project, that has been upgraded to codeigniter 4.5.3. at least

php spark migrate --all

does invoke migration for IonAuth. That project has no tests configured, but I assume it would also work.

dgvirtual commented 1 month ago

I have upgraded my project to 4.5.3, and though php spark migrate --all now does include IonAuth migration, the tests class fails to run it during initiation.

So I am reopening the issue.