Problem/Motivation

ConfigEntityImportTest makes no HTTP requests but is a functional test.

Proposed resolution

Convert it to a kernel test.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

claudiu.cristea created an issue. See original summary.

claudiu.cristea’s picture

Status: Active » Needs review
FileSize
8.61 KB

Patch.

jibran’s picture

Patch looks great just minor nit pick.

+++ b/core/modules/system/tests/src/Kernel/Entity/ConfigEntityImportTest.php
@@ -1,41 +1,48 @@
+    $this->container->get('theme_installer')->install(['bartik']);

Use \Drupal::service() please.

claudiu.cristea’s picture

Issue summary: View changes

@jibran

Use \Drupal::service() please.

Actually, it seems that using $this->container->get() is the way to go for Kernel tests. I had a discussion in #testing channel, see the https://drupal.slack.com/archives/C223PR743/p1552894588175000 thread, specifically @alexpott's comments:

So in Kernel tests $this->container is guaranteed to be updated if the container is rebuilt. In BrowserTestBase tests it is not.

Also see the @alexpott's comment in the issue #2066993-57: Use \Drupal consistently in tests.

I don't mind to change but I think is correct as it is now in the patch.

claudiu.cristea’s picture

Manuel Garcia’s picture

Looks good, just a couple of questions:

  1. +++ b/core/modules/system/tests/src/Kernel/Entity/ConfigEntityImportTest.php
    @@ -1,41 +1,48 @@
    +    $this->installConfig(['action', 'block', 'filter', 'image']);
    +    $this->container->get('theme_installer')->install(['bartik']);
    +    $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
    

    Why not use setUp() for this?

  2. +++ b/core/modules/system/tests/src/Kernel/Entity/ConfigEntityImportTest.php
    @@ -258,7 +266,16 @@ public function assertConfigUpdateImport($name, $original_data, $custom_data) {
    +  /**
    +   * {@inheritdoc}
    +   */
    +  protected function copyConfig(StorageInterface $source_storage, StorageInterface $target_storage) {
    +    // Ensure the 'system.site' config.
    +    $source_storage->write('system.site', ['uuid' => (new Php())->generate()]);
    +    parent::copyConfig($source_storage, $target_storage);
    

    This method seems unnecessary, can we just do it in setUp() with the above?

Lendude’s picture

Status: Needs review » Needs work

Moving back to needs work for #6, which sounds reasonable to me.

claudiu.cristea’s picture

@Lendude, yes #6.2 is OK but I disagree with #6.1. When you have a single test it's optional to use ::setUp(). Normally, there you put reusable code. I think both ways are correct. Also there's no clear demarcation between what is setup and what is the actual test.

claudiu.cristea’s picture

Status: Needs work » Needs review
Issue tags: -Testing system, -Performance, -tests convert, -functional2kernel
FileSize
8.45 KB
1.5 KB

Fixed #6.2.

Manuel Garcia’s picture

@claudiu.cristea re #6.1 - I don't really feel strongly about it was more of a question since the original test used setUp(). I agree it's fine not using setUp() here, and we can always add it back in should we ever need to.

Thanks for addressing #6,2, changes look good. RTBC++

claudiu.cristea’s picture

@Manuel Garcia, thank you. Then you can RTBC it :)

Manuel Garcia’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: 3041081-9.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Reviewed & tested by the community

Random, not related, failure.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/system/tests/src/Kernel/Entity/ConfigEntityImportTest.php
    @@ -96,19 +107,19 @@ protected function doFilterFormatUpdate() {
    -    $this->assertIdentical(72, $filters['filter_url']['settings']['filter_url_length']);
    +    $this->assertEquals(72, $filters['filter_url']['settings']['filter_url_length']);
    

    assertSame() strict config typing is important.

  2. +++ b/core/modules/system/tests/src/Kernel/Entity/ConfigEntityImportTest.php
    @@ -129,21 +140,21 @@ protected function doImageStyleUpdate() {
    -    $this->assertIdentical(100, $effects[$effect_id]['data']['height']);
    +    $this->assertEquals(100, $effects[$effect_id]['data']['height']);
    

    assertSame()

  3. +++ b/core/modules/system/tests/src/Kernel/Entity/ConfigEntityImportTest.php
    @@ -187,14 +198,14 @@ protected function doThirdPartySettingsUpdate() {
    -    $this->assertIdentical([], $entity->getThirdPartyProviders());
    +    $this->assertEmpty($entity->getThirdPartyProviders());
    

    I'd prefer assertSame and empty array - assertEmpty() will pass for quite a few types and strcit config typing is important.

  4. +++ b/core/modules/system/tests/src/Kernel/Entity/ConfigEntityImportTest.php
    @@ -187,14 +198,14 @@ protected function doThirdPartySettingsUpdate() {
    -    $this->assertIdentical(1, $entity->getThirdPartySetting('config_test', 'integer'));
    +    $this->assertEquals(1, $entity->getThirdPartySetting('config_test', 'integer'));
    

    This should be assertSame()

claudiu.cristea’s picture

Status: Needs work » Needs review
FileSize
2 KB
8.45 KB

Fixed strict type comparing.

Manuel Garcia’s picture

Status: Needs review » Reviewed & tested by the community

#15 has been addressed, back to RTBC :)

alexpott’s picture

Creditting @Manuel Garcia and @alexpott as we made material patch reviews.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed bd59fbc64a to 8.8.x and 3957adbf5b to 8.7.x. Thanks!

As a test only change backported to 8.7.x - I discussed backporting test-only changes with @catch (as a release manager).

diff --git a/core/modules/system/tests/src/Kernel/Entity/ConfigEntityImportTest.php b/core/modules/system/tests/src/Kernel/Entity/ConfigEntityImportTest.php
index 2f10f66bbb..bd3e967976 100644
--- a/core/modules/system/tests/src/Kernel/Entity/ConfigEntityImportTest.php
+++ b/core/modules/system/tests/src/Kernel/Entity/ConfigEntityImportTest.php
@@ -3,7 +3,6 @@
 namespace Drupal\Tests\system\Kernel\Entity;
 
 use Drupal\Component\Uuid\Php;
-use Drupal\Core\Config\StorageInterface;
 use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
 use Drupal\filter\Entity\FilterFormat;
 use Drupal\image\Entity\ImageStyle;

Removed unused use on commit.

  • alexpott committed bd59fbc on 8.8.x
    Issue #3041081 by claudiu.cristea, Manuel Garcia, alexpott: Convert...

  • alexpott committed 3957adb on 8.7.x
    Issue #3041081 by claudiu.cristea, Manuel Garcia, alexpott: Convert...

Status: Fixed » Closed (fixed)

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