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.
Problem/Motivation
The HAL tests create a mock serializer, but the Serialization tests use the DrupalUnitTestBase container. We should make this consistent. I'm pretty sure that explicitly creating the mock is better.
Proposed resolution
Unify the base classes and use a mock container for both.
Comment | File | Size | Author |
---|---|---|---|
#27 | refactor_the_serialization_tests-2003392-27.patch | 18.69 KB | Wim Leers |
#26 | refactor_the_serialization_tests-2003392-26.patch | 18.84 KB | Wim Leers |
#20 | refactor_the_serialization_tests-2003392-20.patch | 18.57 KB | Wim Leers |
#19 | refactor_the_serialization_tests-2003392-19.patch | 18.08 KB | kerby70 |
#14 | interdiff-2003392-12-14.txt | 33.12 KB | kerby70 |
Comments
Comment #1
linclark CreditAttribution: linclark commentedThis is just a first pass, I plan to review it more thoroughly after the weekend.
It uses a mock serializer for all tests except for the one WebTest, which is actually testing that the serializer is correctly processed and added to the container. It changes the hal normalizer test extend the serialization normalizer test, and changes the tested entity type to entity_test_mulrev so that they both test the same type.
Comment #3
linclark CreditAttribution: linclark commentedJust added an "as" to the use statement.
Comment #4
damiankloip CreditAttribution: damiankloip commentedThe code looks great - Just ...
These need docblocks.
I think we should use $this->container->get('blah') now.
Comment #5
linclark CreditAttribution: linclark commentedJust getting back to this now, thanks for the review! I've made the changes.
Comment #6
linclark CreditAttribution: linclark commentedRerolled.
Comment #7
linclark CreditAttribution: linclark commentedWhoops, removed a necessary dependency.
Comment #8
damiankloip CreditAttribution: damiankloip commentedI think this setUp method could move the the base class too?
Comment #9
damiankloip CreditAttribution: damiankloip commentedHmm, maybe not. As not all tests will want this additional stuff set up. I think this patch is good.
Comment #10
alexpottI think this documentation should move to Drupal\serialization\Tests\NormalizerTestBase
This change looks odd - can't we just remove the line?
This class is extending DrupalUnitTestBase so this can't use @inheritdoc - this is related to the first code snippet and comment in the review
Comment #11
damiankloip CreditAttribution: damiankloip commentedGood points Alex. Let's make those changes.
Comment #12
damiankloip CreditAttribution: damiankloip commentedNeeded quite a reroll.
Comment #13
jhedstromPatch in #12 no longer applies.
Comment #14
kerby70 CreditAttribution: kerby70 at Blink Reaction (now part of FFW) commentedReroll attached.
Comment #16
damiankloip CreditAttribution: damiankloip commentedThanks for getting this going again, forgot about this one!
A couple of quick points:
We can't inherit from Hal module in serialization module. I think that is my fault originally...sorry! That was a mistake. We will need to move what we need into NormalizerTestBase maybe, and hal\NormalizerTestBase should extend that. Which I think it already does.
We can remove 'variable' from here. This is likely causing a few of the fails :)
Comment #17
kerby70 CreditAttribution: kerby70 at Blink Reaction (now part of FFW) commentedNo problem, just trying to help.
Removing the system.variable reference attached.
I don't think I am in a good position of understanding to take this much further.
Comment #18
kerby70 CreditAttribution: kerby70 at Blink Reaction (now part of FFW) commentedRemoving patch got some core dev update changes in it.
Comment #19
kerby70 CreditAttribution: kerby70 at Blink Reaction (now part of FFW) commentedRemoving the system.variable reference attached.
Comment #20
Wim LeersRebased against 8.1.
Comment #25
Wim LeersLet's get this going again.
Oh… ha… ha… ha… I last touched this exactly one year ago.
Comment #26
Wim LeersThis massively conflicted with #2737719: EntityResource: Provide comprehensive test coverage: for every entity type, every format, every method's follow-up: #2824576: Delete old REST test coverage: (Read|Create|Update|Delete)Test, deprecate RESTTestBase.
Rebased as well as I could.
Comment #27
Wim LeersAnd these things can be removed with just as many tests passing.
Comment #28
Wim LeersIt's not at all clear to me what exactly this patch is improving. I'm hoping somebody who was around when this issue was first created can shed some light on how to proceed here.
Comment #31
damiankloip CreditAttribution: damiankloip commentedI'm not sure I agree 100% with the issue. In my mind the plan should be to use a mock serializer if the test can also be converted to a unit test maybe? It seems weird to have a kernel test but create our own mock serializer, and not use the serializer from the container when the tests are (likely) using other stuff from the container. Also, issues like #2751325: All serialized values are strings, should be integers/booleans when appropriate were also removing this mock container anyway. So if anything, maybe it makes sense to unify it the other way now, for kernel tests? The reason the issue just mentioned changed this as you essentially have to change the mock serializer to reflect your actual serialization configuration anyway. So you need to keep two things in sync. They also could behave different if they are not added in the same order etc.. too.
Comment #32
Wim LeersDoes that mean this is a won't-fix?
Much of what was in
\Drupal\Tests\hal\Kernel\DenormalizeTest()
has been removed in #2824576: Delete old REST test coverage: (Read|Create|Update|Delete)Test, deprecate RESTTestBase, because it was obsolete thanks to #2737719: EntityResource: Provide comprehensive test coverage: for every entity type, every format, every method. I think we should try to move the remainder of what's inNormalizeTest
andDenormalizeTest
into\Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait::assertNormalizationEdgeCases()
? Then we could remove these tests altogether. If you agree with that, let's close this issue and open a new one for doing that.Comment #33
damiankloip CreditAttribution: damiankloip commentedI'm not sure I agree it should be removed, I think it's valuable testing hal behaviour in the hal module :) Looking at #2824576: Delete old REST test coverage: (Read|Create|Update|Delete)Test, deprecate RESTTestBase I'm not sure I agree that coverage should have been removed there either. I'm not a fan of relying on integration tests in another module for testing all the cases here. It does look convenient though, as there is already the assertNormalizationEdgeCases() method for this type of thing. I just don't like the continuous coupling between serialization and REST I guess...
Also, #2751325: All serialized values are strings, should be integers/booleans when appropriate will remove most of the existing mocked serializer code anyway.
Comment #34
Wim LeersMe neither, but I had to be practical. We need to test different formats being supported by REST. Those tests need to be thorough. OTOH, the HAL module's test coverage was very thin, plus they were kernel tests, not unit tests.
I do agree with you, which is why there is #2845384: Every normalizer must have strict test coverage! That's all about testing all cases of normalizers, in isolation, i.e. in unit tests. They should test all edge cases.
The problem with the HAL tests (the existing ones, but also the ones that were deleted in favor of test coverage added in #2737719: EntityResource: Provide comprehensive test coverage: for every entity type, every format, every method) is that they are testing an unhelpful mish-mash of things. They're semi-integration tests, and very incomplete ones at that, only testing a very small set of entity types, and then only testing the happy path.
Comment #35
Wim LeersPer @damiankloip's comment in #31, who is the Serialization module maintainer and was working on all this when this issue was opened, I'm closing this issue.
Because the original issue scope+intent are not relevant anymore. And that we need to further improve the test coverage in the HAL module is blindingly obvious when you look at the code base. When somebody has the time + energy, they should create a new issue. This old one is merely distracting.