Skip to content

fix: DB Seeder may use wrong DB connection during testing - #8447

Merged
kenjis merged 1 commit into
codeigniter4:developfrom
kenjis:fix-DatabaseTestTrait-SQLite3-memory-seeder-bug
Jan 24, 2024
Merged

kenjis merged 1 commit into
codeigniter4:developfrom
kenjis:fix-DatabaseTestTrait-SQLite3-memory-seeder-bug

Conversation

@kenjis

@kenjis kenjis commented Jan 24, 2024

Copy link
Copy Markdown
Member

Description
The shared migration holds an old DB connection.
If SQLite3 :memory: is used, a new DB connection is a connection to a new database.

Before:

$ vendor/bin/phpunit tests/system/Database/Live/TransactionDBDebugTrueTest.php 
PHPUnit 9.6.16 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.15
Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml

.EEEE                                                                5 / 5 (100%)

Time: 00:00.136, Memory: 18.00 MB

There were 4 errors:

1) CodeIgniter\Database\Live\TransactionDBDebugTrueTest::testTransStartTransException
CodeIgniter\Database\Exceptions\DatabaseException: SQLite3::exec(): no such table: db_user

After:

$ vendor/bin/phpunit tests/system/Database/Live/TransactionDBDebugTrueTest.php 
PHPUnit 9.6.16 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.15
Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml

.....                                                                    5 / 5 (100%)

Time: 00:00.296, Memory: 18.00 MB

OK (5 tests, 16 assertions)

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

The shared migration holds an old DB connection.
If SQLite3 `:memory:` is used, a new DB connection is a connection to a new database.
@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Jan 24, 2024
@kenjis
kenjis merged commit 3d8b04b into codeigniter4:develop Jan 24, 2024
@kenjis
kenjis deleted the fix-DatabaseTestTrait-SQLite3-memory-seeder-bug branch January 24, 2024 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants