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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mcjim’s picture

Here's some example code for how it could be useful.

mcjim’s picture

Status: Active » Needs review
FileSize
84.89 KB

First 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.

mcjim’s picture

Patch created with diff -M.

mcjim’s picture

Tried 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.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Love it!!

tstoeckler’s picture

Note 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.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

  • Commit 56ace1c on 8.x by catch:
    Issue #2225473 by mcjim: Move database fakes out of migrate module so...
sun’s picture

Status: Fixed » Needs work

Hm. 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?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Status: Needs work » Closed (won't fix)

I think we dropped those fake DB connections in the meantime as they have been problematic.