Support from Acquia helps fund testing for Drupal Acquia logo

Comments

linclark’s picture

Status: Active » Needs review
FileSize
16.74 KB

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

Status: Needs review » Needs work

The last submitted patch, 2003392-refactor-serializer-tests.patch, failed testing.

linclark’s picture

Status: Needs work » Needs review
FileSize
16.85 KB

Just added an "as" to the use statement.

damiankloip’s picture

Status: Needs review » Needs work

The code looks great - Just ...

+++ b/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.phpundefined
@@ -51,46 +43,58 @@
+  protected function getMockSerializer($normalizers, $encoders) {
...
+  protected function enableLanguage() {
...
+  protected function createTranslatableTextField() {

@@ -99,44 +103,29 @@ function setUp() {
+  protected function createEntityReferenceField() {

+++ b/core/modules/serialization/lib/Drupal/serialization/Tests/EntityResolverTest.phpundefined
@@ -6,7 +6,11 @@
+class EntityResolverTest extends HalNormalizerTestBase {

@@ -91,9 +73,21 @@ function testUuidEntityResolver() {
+  protected function getMockSerializer($normalizers, $encoders) {

+++ b/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.phpundefined
@@ -18,13 +24,40 @@
+  protected function getMockSerializer($normalizers, $encoders) {
...
+  protected function createTextField() {

These need docblocks.

+++ b/core/modules/serialization/lib/Drupal/serialization/Tests/SerializationTest.phpundefined
@@ -36,7 +39,7 @@ public static function getInfo() {
-    $this->serializer = drupal_container()->get('serializer');
+    $this->serializer = \Drupal::service('serializer');
   }
 
   /**

I think we should use $this->container->get('blah') now.

linclark’s picture

Status: Needs work » Needs review
FileSize
4.07 KB
17.49 KB

Just getting back to this now, thanks for the review! I've made the changes.

linclark’s picture

Rerolled.

linclark’s picture

Whoops, removed a necessary dependency.

damiankloip’s picture

+++ b/core/modules/hal/lib/Drupal/hal/Tests/DenormalizeTest.phpundefined
@@ -22,6 +22,12 @@ public static function getInfo() {
+  public function setUp() {
+    parent::setUp();
+    $this->enableLanguage();
+    $this->createTranslatableTextField();
+  }

I think this setUp method could move the the base class too?

damiankloip’s picture

Status: Needs review » Reviewed & tested by the community

Hmm, maybe not. As not all tests will want this additional stuff set up. I think this patch is good.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/hal/lib/Drupal/hal/Tests/NormalizerTestBase.phpundefined
@@ -51,18 +43,58 @@
+  /**
+   * Creates a mock serializer for testing.
+   *
+   * @param array $normalizers
+   *   The array of normalizers to instantiate the serializer with.
+   * @param array $encoders
+   *   The array of encoders to instantiate the serializer with.
+   *
+   * @return \Symfony\Component\Serializer\Serializer
+   *   The mock serializer.
+   */

I think this documentation should move to Drupal\serialization\Tests\NormalizerTestBase

+++ b/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.phpundefined
@@ -63,7 +63,7 @@ protected function setUp() {
-    $this->serializer = $this->container->get('serializer');
+    $this->serializer = $this->serializer;

This change looks odd - can't we just remove the line?

+++ b/core/modules/serialization/lib/Drupal/serialization/Tests/NormalizerTestBase.phpundefined
@@ -16,15 +22,48 @@
+  /**
+   * {@inheritdoc}
+   */

This class is extending DrupalUnitTestBase so this can't use @inheritdoc - this is related to the first code snippet and comment in the review

damiankloip’s picture

Status: Needs work » Needs review
FileSize
2.44 KB
0 bytes

Good points Alex. Let's make those changes.

damiankloip’s picture

FileSize
17.17 KB

Needed quite a reroll.

jhedstrom’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

Patch in #12 no longer applies.

kerby70’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
18.2 KB
33.12 KB

Reroll attached.

Status: Needs review » Needs work

The last submitted patch, 14: refactor_the_serialization_tests-2003392-14.patch, failed testing.

damiankloip’s picture

Thanks for getting this going again, forgot about this one!

A couple of quick points:

  1. +++ b/core/modules/serialization/src/Tests/EntityResolverTest.php
    @@ -7,51 +7,16 @@
    +class EntityResolverTest extends HalNormalizerTestBase {
    

    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.

  2. +++ b/core/modules/serialization/src/Tests/NormalizerTestBase.php
    @@ -18,14 +24,55 @@
    +    $this->installSchema('system', array('url_alias', 'variable'));
    

    We can remove 'variable' from here. This is likely causing a few of the fails :)

kerby70’s picture

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

kerby70’s picture

Removing patch got some core dev update changes in it.

kerby70’s picture

Removing the system.variable reference attached.

Wim Leers’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Needs work » Needs review
FileSize
18.57 KB

Rebased against 8.1.

Status: Needs review » Needs work

The last submitted patch, 20: refactor_the_serialization_tests-2003392-20.patch, failed testing.

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

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now 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.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Wim Leers’s picture

Assigned: Unassigned » Wim Leers

Let's get this going again.

Oh… ha… ha… ha… I last touched this exactly one year ago.

Wim Leers’s picture

And these things can be removed with just as many tests passing.

Wim Leers’s picture

Assigned: Wim Leers » Unassigned
Issue tags: +Needs issue summary update

It'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.

The last submitted patch, 26: refactor_the_serialization_tests-2003392-26.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 27: refactor_the_serialization_tests-2003392-27.patch, failed testing.

damiankloip’s picture

Issue summary: View changes

I'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.

Wim Leers’s picture

Does 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 in NormalizeTest and DenormalizeTest 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.

damiankloip’s picture

I'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.

Wim Leers’s picture

I just don't like the continuous coupling between serialization and REST I guess...

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

Wim Leers’s picture

Status: Needs work » Closed (outdated)

Per @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.