Problem/Motivation
These functions in the simpletest module deal with the TestDatabase:
- simpletest_insert_asssert()
- simpletest_last_test_get()
- simpletest_log_read()
- simpletest_schema()
If we want to turn the simpletest module into a contrib module, we'll need to make sure their behavior is still in core so the test runner can use them.
Proposed resolution
Move the behavior of these functions to be methods on the Drupal\Core\Test\TestDatabase class.
Deprecate the functions for removal.
The special case is simpletest_schema(), which is an implementation of hook_schema(). This function is used by both the simpletest module (in a hook context) and the run-tests.sh script (not in a hook context).
Since it's used this way, it can also be a method on TestDatabase, which is then called by simpletest_schema().
Since simpletest_schema() is a hook, it won't be deprecated.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | interdiff.txt | 450 bytes | mile23 |
| #24 | 3074043_24.patch | 20.67 KB | mile23 |
| #22 | interdiff.txt | 1.43 KB | mile23 |
| #22 | 3074043_22.patch | 20.67 KB | mile23 |
| #16 | interdiff.txt | 2.17 KB | mile23 |
Comments
Comment #2
mile23Postponed on decisions made in #3057420: [meta] How to deprecate Simpletest with minimal disruption
Comment #3
mile23Early try.
Still mainly waiting on consensus from #3057420: [meta] How to deprecate Simpletest with minimal disruption so this will go back to being postponed after the testbot starts.
Comment #4
mile23Comment #5
mile23Unpostponing based on #3057420-17: [meta] How to deprecate Simpletest with minimal disruption
Comment #6
mile23Draft change record: https://www.drupal.org/node/3075252
Updating deprecation messages, adding deprecation test.
Comment #8
mile23Removed the deprecation test because there is no way to mock
TestDatabase. Like, at all. :-)Fixing that problem is not in scope here, but it is why these deprecated functions do not have any tests.
Comment #9
volegerCS line length issue
Return type missing
Fix indentation
Param type missing
An empty line before @return missing
CS issue with deprecation message
CS issue with an error message
The same here
Comment #10
mile23Thanks, @voleger.
Addressed CS issues in #9.
Comment #11
voleger+1 for RTBC
Comment #12
mondrakeThis is no longer a
hook_schemaimplementation, and I think we should now overcome 'simpletest' being part of the method name - how about justgetSchema?Comment #13
mondrakeI'd also love these to become dynamic queries instead (i.e.
$connection->select(...)etc.) but I guess that's an obsessions of mine only and it would be out-of-scope here anyway.Comment #14
mile23#12: Fair point on the docblock. I think
simpletestSchema()is a good name because it's the simpletest schema. But let's call ittestingSchema().getSchema()might imply a few other APIs.#13: Yes, a bit out of scope, but you're welcome to file a follow-up and I'll even review it. :-)
Comment #15
mondrakeThanks.
These look like leaks from another patch.
I wonder whether moving these methods to
TestDatabasedoesn't require also some tests to be added toTestDatabaseTest?Comment #16
mile23In an ideal world I'd be able to test the new methods. But because
TestDatabaseis almost entirely static, we can't mock anything and we'd end up changing test results. It's the same reason we can't write a deprecation test for the functions we're deprecating.I expanded
TestDatabaseTesta little bit, for a single test case, but that's as far as we can go.We should make a follow-up to refactor this stuff so it's testable. Right now the focus is deprecating the functions.
Comment #17
mile23And there's the follow-up.
Comment #18
mondrakeFiled #3075648: Refactor TestDatabase::lastTestGet to use dynamic queries as followup to #13/#14.
There's a small CS issue that could also be fixed on commit.
Comment #19
larowlanWe have a chance to rework this here. I doubt this is what we'd design if we did it from scratch. While we're touching it - should we make this a value object return? We can juggle back to the array format it in the old function for BC reasons.
An API is forever and all that.
should we be adding deprecation tests for these?
Comment #20
mile23We can't add deprecation tests because
TestDatabaseis static, and would write to our test results. That's why there's a followup: #3075608: Introduce TestRun objects and refactor TestDatabase to be testableComment #21
larowlanShould we mark all the methods as @internal if we hope to get rid of them then?
Comment #22
mile23It's a can of worms, because we clearly need to refactor how this works for maintainability. But we've been trying to get that done for a few years now. @mondrake just filed #3075648: Refactor TestDatabase::lastTestGet to use dynamic queries and I filed #3075608: Introduce TestRun objects and refactor TestDatabase to be testable, we've reworked the schema a little in #2905007: Allow run-tests.sh to report skipped/incomplete PHPUnit tests, @alexpott wants to force the DB to always lock in #2946439: TestDatabase should always lock, etc.
In fact that last one is your best chance to see refactoring and deprecation before 9.0.0. (For instance:
TestDatabasealready had too many responsibilities before we added these methods: Finding the results database in config and also managing locks.)I think marking all the new methods as internal is an excellent idea.
Sigh. Still no official CS for
@internal.Comment #23
mondrakeThis is doing the moves, and we have follow-ups for the refactors. RTBC (there's a small CS 'Expected 1 blank line after function; 2 found' issue but easily fixable at commit). RTBC
Comment #24
mile23CS issue from #23. Leaving RTBC for minor CS change.
Comment #25
larowlanComment #27
larowlanCommitted 0041ba0 and pushed to 8.8.x. Thanks!
Published change record