Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There are several fakes used in migrate module's tests which could be used in other unit tests.
e.g. writing a unit test for saveBookLink() in currently problematic as it is expecting a database insert to happen, and it would be good to make use of \Drupal\migrate\Tests\FakeInsert.
If we move them (not sure where they should go?) then it would be possible to write more unit tests for code which relies on a database connection.
Comment | File | Size | Author |
---|---|---|---|
#3 | 2225473-move-db-fakes-from-migrate-diff-M.txt | 12 KB | mcjim |
#2 | 2225473-move-db-fakes-from-migrate.patch | 84.89 KB | mcjim |
#1 | FakeConnection-testSaveBookLink-example-do-not-test.patch | 3.22 KB | mcjim |
Comments
Comment #1
mcjim CreditAttribution: mcjim commentedHere's some example code for how it could be useful.
Comment #2
mcjim CreditAttribution: mcjim commentedFirst pass at a patch following suggestions from chx.
Relevant files have been moved from migrate into a fake driver directory /core/lib/Drupal/Core/Database/Driver/fake.
All migrate unit tests still run.
Not sure if we need the Install/Tasks.php file. The installer is not picking the fake driver up regardless.
Comment #3
mcjim CreditAttribution: mcjim commentedPatch created with diff -M.
Comment #4
mcjim CreditAttribution: mcjim commentedTried removing the Install/Tasks.php file and the installer is fine.
There's a check for Install/Tasks.php in drupal_get_database_types() in install.inc.
Comment #5
dawehnerLove it!!
Comment #6
tstoecklerNote that #2209307: Convert database drivers into a regular extension type would allow to remove that hack. We would have .info.yml files for database drivers then and could easily add a hidden: true at that point.
Comment #7
catchCommitted/pushed to 8.x, thanks!
Comment #9
sunHm. What is the implied meaning of "fake" ?
Was it meant to say "mock" ?
Or was it meant to say "memory" ?
Briefly glancing over the code, it appears to be a "mock", not "memory" — i.e., there's no "fake" storage, and you cannot run actual queries against it. Is that correct?
Can we rename the driver to have a clear/concise name, please?
Comment #11
dawehnerI think we dropped those fake DB connections in the meantime as they have been problematic.