Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kim.pepper created an issue. See original summary.

kim.pepper’s picture

Assigned: Unassigned » kim.pepper

Working on this.

kim.pepper’s picture

Added a unit test to cover logic in addMessage() including repeat flag.

Status: Needs review » Needs work

The last submitted patch, 3: 2931598-3.patch, failed testing. View results

jibran’s picture

Status: Needs work » Reviewed & tested by the community

Patch is green. The test looks good. Thanks, for the quick fix.

markhalliwell’s picture

Status: Reviewed & tested by the community » Needs work

I can't believe we all missed this :-/

That being said, we really should flush out a full unit test for Messenger (including all the additions, retrievals, and deletions), not just the repeat code.

almaudoh’s picture

That being said, we really should flush out a full unit test for Messenger (including all the additions, retrievals, and deletions), not just the repeat code.

+1

almaudoh’s picture

Fixed LegacyMessenger also and added tests. Uploaded test-only patch to confirm failing tests. #6 not done yet.

kim.pepper’s picture

Assigned: kim.pepper » Unassigned

Status: Needs review » Needs work

The last submitted patch, 8: 2931598-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kim.pepper’s picture

I moved the unit test to a kernel test and added a bunch of asserts from \Drupal\Tests\system\Functional\Bootstrap\DrupalSetMessageTest::testDrupalSetMessage and \Drupal\system_test\Controller\SystemTestController::drupalSetMessageTest

Perhaps they can be removed now?

I think we have 100% test coverage of the Messenger class now.

markhalliwell’s picture

Status: Needs review » Needs work
+++ b/core/tests/Drupal/KernelTests/Core/Messenger/LegacyMessengerTest.php
@@ -81,4 +81,25 @@ public function testMessages() {
+  public function testRepeatedMessages() {

Minor nit, missing doc

Other than that, this looks much better :D

kim.pepper’s picture

Fixes nit in #12

Also after discussing with @markcarver in slack, added a test that an object implementing MarkupInterface is correctly converted to Markup.

Also discussed removing:

  • \Drupal\Tests\system\Functional\Bootstrap\DrupalSetMessageTest::testDrupalSetMessage
  • \Drupal\system_test\Controller\SystemTestController::drupalSetMessageTest

...but think these should be done in a follow up, as there are some migration tests that depend on these, and I don't want to delay this issue on that.

Also, I managed to stuff up my local git commits, so the interdiff was created using the diff between the two patch files (facepalm).

kim.pepper’s picture

Sam152’s picture

This is looking great, only found some tiny nits.

  1. +++ b/core/tests/Drupal/KernelTests/Core/Messenger/LegacyMessengerTest.php
    @@ -81,4 +83,30 @@ public function testMessages() {
    +  public function testRepeatedMessages() {
    
    +++ b/core/tests/Drupal/KernelTests/Core/Messenger/MessengerTest.php
    @@ -0,0 +1,165 @@
    +   * Tests we don't add duplicates.
    

    Are we using "duplicated" and "repeated" to mean the same thing? Should we pick one?

  2. +++ b/core/tests/Drupal/KernelTests/Core/Messenger/MessengerTest.php
    @@ -0,0 +1,165 @@
    +  public function testRemoveSingleMessage() {
    +
    ...
    +
    +  }
    ...
    +  public function testAddNoDuplicates() {
    +
    ...
    +    $this->assertCount(0, $this->messenger->messagesByType(MessengerInterface::TYPE_ERROR));
    +
    +  }
    ...
    +  public function testAddWithDuplicates() {
    +
    ...
    +
    +  }
    ...
    +  public function testAddMarkup() {
    +
    ...
    +
    +  }
    

    Nit, why are these bookended with newlines? Maybe this is just a style thing and can be ignored.

markhalliwell’s picture

Status: Needs review » Reviewed & tested by the community

#15 are extremely minor nits

Marking RTBC, tests have passed!

kim.pepper’s picture

Thanks @Sam152!

  1. I think the language is understandable enough? "Tests we don't add duplicates" "Tests we do add duplicates with repeat flag."
  2. It passed the phpcs code sniffs, so I guess it's acceptable?
Sam152’s picture

Totally fair on both points! +1 RTBC

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Doesn't apply?

error: core/tests/Drupal/KernelTests/Core/Messenger/LegacyMessengerTest.php: No such file or directory
error: core/tests/Drupal/KernelTests/Core/Messenger/MessengerTest.php: already exists in working directory
markhalliwell’s picture

Status: Needs work » Reviewed & tested by the community

I think maybe you applied the interdiff instead of the patch.

larowlan’s picture

Issue tags: +Needs reroll

Also have to rename LegacyMessengerTest because any test with Legacy in the name generates deprecation notices that PHPUnit 6 can catch but PHPUnit 4 for some reason does not.
#2927806: Use PHPUnit 6 for testing when PHP version >= 7.2

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
larowlan’s picture

Make its class start with the Legacy prefix;

from http://symfony.com/blog/new-in-symfony-2-7-phpunit-bridge

So perhaps we have to name it something that has something in-front of Legacy.

MessagingLegacyTest for example

markhalliwell’s picture

Assigned: Unassigned » markhalliwell
markhalliwell’s picture

Assigned: markhalliwell » Unassigned
Priority: Normal » Major
Status: Needs work » Needs review
FileSize
16.52 KB
5.29 KB

So it turns out that we need to force repeat when merging from LegacyMessenger into the messenger service. I've updated the tests accordingly.

Also, bumping up the priority because this issue is blocking several other issues and breaks expected functionality.

kim.pepper’s picture

Status: Needs review » Reviewed & tested by the community

Addresses #19 and #21 so back to RTBC

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed as a351d72 and pushed to 8.5.x.

  • larowlan committed a351d72 on 8.5.x
    Issue #2931598 by kim.pepper, markcarver, almaudoh, Sam152: Messenger...

Status: Fixed » Closed (fixed)

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