#2902311: add __toString() to the entity Query class introduced a test that is checking SQL syntax produced by Drupal\Core\Database\Query\Select. Contrib drivers overriding that method may fail tests. I suggest we just skip the test if not run against one of the core's provided db drivers.

Example: https://travis-ci.org/mondrake/drudbal/jobs/620001853?utm_medium=notific...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Status: Active » Needs review
FileSize
1.09 KB
mondrake’s picture

daffie’s picture

Status: Needs review » Reviewed & tested by the community

I am working on a full support database driver for MongoDB (https://gitlab.com/daffie/drumongous and https://gitlab.com/daffie/mongodb). And MongoDB does not do SQL. For me this issue is a absolute need.
The patch looks good to me. To RTBC.

alexpott’s picture

@daffie how is this patch an absolute need? How are you choosing which core tests to run? Maybe a better solution than hardcoding driver names is to make this a different test.

daffie’s picture

"Absolute need" is maybe a little bit to much, but MongoDB does not do SQL strings. Also the way entities are stored in MongoDB is different, so the resulting query will be different. The test-result for a MongoDB database driver will be different. Maybe we should only run the test for relational databases. @alexpott: If you have a better idea, then please say so. Better ideas are always welcome. :)

alexpott’s picture

@daffie well what we should do here is identify tests that a custom/contrib driver should run - how are we currently identifying them? I don't think we are at all and I don't think it is realistic to say run all the tests in core. There's going to be more than this one that fails for good reasons on a MongoDB database driver.

daffie’s picture

There's going to be more than this one that fails for good reasons on a MongoDB database driver.

@alexpott: You are absolutly right. It is just that @mondrake created this issue and it is part of the problem with support in core for contrib database drivers/extensions.
A number of contributers like to work on extending the database abstraction layer with more capabilities and others (like me) like to work on contrib database drivers for other then the by core supported databases.
In the ideas queue we have an issue for that and I have proposed a plan how to add support for contrib database drivers/extensions in core. See #2846366-17: Improve Drupal's Database Abstraction Layer Extensibility and Capabilities.
In a later stage we could create a system where contrib database driver/extensions can override core tests with there own implementation for specific tests. In that way core tests stay clean of contrib specific exceptions.

mondrake’s picture

My 2 cents - a developer of a contrib db driver needs to ensure that Drupal installs and runs successfully with it. From this perspective, running the core tests 'under' the driver is a good sign that the driver works - and they come for free :). Sure thing, you do not need to run *all* the tests, but at least those in the @groups Database, Entity, Installer, file, views are probably on the critical path - if something fails in one of these, it's likely the Drupal installation would be compromised. This surely applies for SQL backends, where ideally the driver will be self-contained in a subdirectory of drivers/lib/Drupal/Driver/Database/. For non-SQL databases the problem is, I guess, more articulated.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php
@@ -1205,6 +1206,10 @@ public function testConditionOnRevisionMetadataKeys() {
+    if (!in_array(Database::getConnection()->driver(), ['mysql', 'sqlite', 'pgsql'])) {
+      $this->markTestSkipped("This test only runs for Drupal core database drivers");
+    }

So i'm not really a fan of this. It feels fragile. Imagine we add a mariadb specific driver to core.

I think we need to back to the drawing board and come up with a less fragile way of producing a test suite for contrib / custom db drivers.

longwave’s picture

As we can never know ahead of time which tests are going to be problematic for custom database drivers, should the driver itself be responsible for declaring a list of test classes (or perhaps methods) that should be skipped when running the full test suite? The driver can then provide its own version of those skipped tests if they need modifying to run on that driver.

daffie’s picture

A typical solution for what @alexpott wants will result in a system with hooks or plugins. Both require that the custom database driver has module like capabilities.

alexpott’s picture

@daffie I don't think it does. I think it involves tagging tests and test methods with additional @group so that we can agree what tests/methods need to be db agnostic and provide a good coverage for a contrib / custom db driver. Or we can go the other way... and add a group to tests we know are SQL database specific and then contrib / custom drivers can use --exclude-group.

mondrake’s picture

Without knowing whether it's possible - how about another annotation, say @db_driver, where you will whitelist the drivers for which to run the test? Then if the annotation is missing, tests are always run; if it is present, it is run only if the running driver is one of the whitelisted ones. This would also fit with some tests in core that are driver specific, see for example:

Drupal\KernelTests\Core\Database\ConnectionTest::testPostgresqlReservedWords --> only PostgreSQL
Drupal\KernelTests\Core\Database\ConnectionTest::testMultipleStatementsForNewPhp --> only MySQL

daffie’s picture

mondrake’s picture

Apart from the discussions from #10 onwards (that should get a separate issue IMHO), the original issue may be resolved in a more db-driver agnostic way by building a dynamic query to compare its SQL statement against the one generated by the EntityQuery, instead of forcing comparison vs the hardcoded SQL statement. See details in patch. No interdiff, different approach.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

I like the new approach.
It all looks good to me.
It is all very good documented.
It should also work for contrib database drivers.
For me it is RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed deaf132106 to 9.0.x and b0b039da19 to 8.9.x. Thanks!

Doesn't merge to 8.8.x so I've not bothered backporting.

  • alexpott committed deaf132 on 9.0.x
    Issue #3098426 by mondrake, daffie: EntityQueryTest::testToString fails...

  • alexpott committed b0b039d on 8.9.x
    Issue #3098426 by mondrake, daffie: EntityQueryTest::testToString fails...
mondrake’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.