Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Jan 24, 2024

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
62 checks passed
@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