I don't exactly know what Core plans to do here, but EntityUnitTestBase
extends the old KernelTestBase
(\Drupal\simpletest\KernelTestBase
), which is deprecated and scheduled to be removed by 8.2.0. Thus, in extension, EntityUnitTestBase
should probably be considered deprecated as well – normally, it would not be a problem if that class just were changed to extend the new KernelTestBase
(\Drupal\KernelTests\KernelTestBase
) at some point, but in the case of tests this unfortunately would mean we'd need to move all our tests to different directories and namespaces as well, due to Drupal's separation between Simpletest and PHPUnit tests.
In Core, there is #2456477: Convert deprecated \Drupal\simpletest\KernelTestBase tests to KernelTestBaseNG for the migration, but it seems dormant for the moment. I've now asked there what contrib modules should do. Postponing this issue to wait for an answer there.
Remaining work:
\Drupal\search_api\Tests\Processor\ProcessorTestBase
is still uses EntityUnitTestBase
and it should use the new KernelTestBase
.
Comment | File | Size | Author |
---|---|---|---|
#17 | 2642728-17--remove_EntityUnitTestBase_usage.patch | 12.44 KB | drunken monkey |
Comments
Comment #2
borisson_Changing this issue to NR, to enable the testbot to test this. There will be errors that come back from the tests:
I can't figure out where those come from yet.
I took the opportunity of moving the files to make a couple of other changes to the tests:
assertEqual
toassertEquals
. Those calls are deprecated as well (there is a bc layer inAssertLegacyTrait
, but we can just change our code). - that is a about 80% of this patch I think.ExampleContentTrait
inCliTest
andCustomDataTypesTest
The
LanguageIntegrationUnitTest
(renamed toLanguageIntegrationTest
) hadEntityLanguageTestBase
as base class, that was 3 layers on top of the old kernel test base. I moved that too but I'm not sure if that'll just work. Still getting the error mentioned for that class as well.Comment #5
borisson_I fixed this, we needed to install all required modules (incl. 'user', 'system' & 'entity_test').
The attached patch fixes:
LanguageIntegrationTest
now runs as well, I extracted the needed code fromEntityLanguageTestBase
. ThisThere should be 2 tests that still fail, "Drupal\search_api_db\Tests\BackendTest" and "Drupal\Tests\search_api\Kernel\CustomDataTypesTest". Both fail with the same error: "Error: Class name must be a valid object or a string". Figuring out how to fix that now.
Comment #8
borisson_The BackendTest was not discovered correctly. That should be fixed now. All tests should be green as well.
Comment #9
drunken monkeyThanks for your work on this!
However, the issue was postponed for a reason, I would really have preferred waiting for feedback in the Core issue.
However, now that the patch is almost done and already passing, I guess we might as well just go with it.
That's what I was talking about in #2642248: Depend explicitly on the User module? – it seems the parameter converter service will always be loaded, so now all our kernel tests require the user module as well.
Although it also might be possible to just insert a mock service, either for
user.shared_tempstore
or even directly fordrupal.proxy_original_service.paramconverter.search_api
itself.Well, they are in the sense that they are now PHP Unit tests. And I think it's good to have a reminder of that in the class name, to easily distinguish them.
This is especially true for
LanguageIntegrationUnitTest
– there already is aLanguageIntegrationTest
in our module, so removing theUnit
from the other one is pretty confusing. (Although that probably has the different problem that having both "integration" and "unit" in the class name is rather bizarre in and of itself. So maybeLanguageUnitTest
instead, orLanguageKernelTest
.)Or maybe just change
Unit
toKernel
in the class names?Also, changing
assertEqual()
calls toassertEquals()
is of course correct and important, but please be aware that this has a different parameter order than we were mostly using in the old tests:assertEquals($expected, $actual, …)
! That means you should also switch the parameters for most of the calls. (Luckily, should be possible with a regex, but probably still have to be reviewed individually.) Otherwise, the messages for test failures will be confusing.Otherwise the patch looks great, thanks! (Although you can be lucky I'm not as strict as you are regarding unrelated changes. :P)
Comment #10
borisson_It might be, but I don't think it slows our tests down to be explicit about this dependency. The fewer objects we have to mock, the better.
Changed to
LanguageKernelTest
as suggested, because this is probably the only one where the difference in name actually makes sense, for the other tests I disagree that this is important to have the namespace duplicated in the name and probably even counterproductive.I also fixed the sequence of the arguments for all
assertEquals
calls in the classes we already touched, I did this by hand because it was already correct in some instances and my regex-fu was insufficient.Comment #12
drunken monkeyLooks all good, thanks again for your work!
Committed!
Comment #13
drunken monkeyJust stumbled across it while glancing over #2638116: Clean up caching of Index class method results (especially fields): it seems we didn't port
\Drupal\search_api\Tests\Processor\ProcessorTestBase
here. Any reason, why, or did we just both overlook that?Comment #14
borisson_I figure we overlooked that, let's port that one as well.
Comment #15
borisson_Let's tag this as a novice issue, it's should fairly easy to resolve, and the previously committed patch is a good example of what to do.
Comment #16
borisson_Not as easy as expected.
Comment #17
drunken monkeyGreat job, thanks!
Due to #2638116: Clean up caching of Index class method results (especially fields), this required a re-roll, though.
Also, I refactored
ContentAccessTest
a bit to use a method for creating a user. Seems a bit cleaner and avoids duplicating code.Comment #18
borisson_That looks great, and the testbot agrees. Woo!
Comment #19
drunken monkeyGreat. Committed.
Thanks again!