Problem/Motivation

There is a weird line that get's outputted often
sh: 1: -t: not found

This is because the test mail collector is not configured in kernel test base tests and Drupal is trying to use sendmail!

Proposed resolution

Configure test mail collector for KernelTestBase tests
Move mail asserts into a trait so the tests can use it
Test this

Remaining tasks

User interface changes

None

API changes

None - test API only changes.

Data model changes

None

Comments

isntall created an issue. See original summary.

isntall’s picture

I was testing out the new containers that don't use phpenv and this issue still showed up.

elachlan’s picture

Could you attach the console output around the failure from docker?

elachlan’s picture

Output I found in one of the error logs:

22:17:49 Drupal\migrate_drupal\Tests\d6\CckMigrationBuilderTest         3 passes                                      
22:17:50 sh: 1: -t: not found
22:17:51 Drupal\action\Tests\Migrate\d6\MigrateActionConfigsTest        5 passes 
elachlan’s picture

This is from a different test. It is close to the output in the previous test.

23:12:09 Drupal\migrate_drupal\Tests\d6\CckMigrationBuilderTest         3 passes                                      
23:12:09 Drupal\menu_ui\Tests\MenuLanguageTest                         47 passes                                      
23:12:09 Drupal\menu_ui\Tests\MenuUninstallTest                         2 passes                                      
23:12:10 sh: 1: -t: not found
23:12:10 Drupal\locale\Tests\LocaleConfigTranslationTest              149 passes                                      
23:12:10 Drupal\locale\Tests\LocalePluralFormatTest                   242 passes                                      
23:12:10 Drupal\action\Tests\Migrate\d6\MigrateActionConfigsTest        5 passes                                      
23:12:12 Drupal\aggregator\Tests\Migrate\d6\MigrateAggregatorConfigsT  11 passes                                      

elachlan’s picture

\drupal\vendor\behat\mink-goutte-driver\.travis.yml

Has the following:

before_script:
  - export WEB_FIXTURES_HOST=http://localhost:8000

  # Start a webserver for web fixtures. Force using PHP 5.6 to be able to run it on PHP 5.3 and HHVM jobs too
  - ~/.phpenv/versions/5.6/bin/php -S localhost:8000 -t vendor/behat/mink/driver-testsuite/web-fixtures > /dev/null 2>&1 &
Mixologic’s picture

This is very likely related to the following:
http://axiac.ro/blog/2013/06/sh-1-t-not-found/

A quick look inside one of the containers shows the following:

root@2d48ed06f3d8:/# php -i |grep sendmail
sendmail_from => no value => no value
sendmail_path =>  -t -i  =>  -t -i 
Path to sendmail =>  -t -i 
root@2d48ed06f3d8:/# 

So the next question is, what, from inside of the testrunners, is trying to send mail, but only sometimes?

alexpott’s picture

Title: odd stdout not found » Odd stdout not found in test output
Project: DrupalCI: Test Runner » Drupal core
Version: » 8.0.x-dev
Component: Code » simpletest.module
Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new1.67 KB

This is caused by Drupal\migrate_drupal\Tests\d6\EntityContentBaseTest - it is a KernelTestBase test.

elachlan’s picture

Status: Needs review » Reviewed & tested by the community

"sh: 1: -t: not found" was not found in the test output! :)

Mixologic’s picture

Nice find Alex. Looks like we see it on occasion whenever something inadvertently sends mail.

Also, slightly disturbing that sendmail_path is essentially a shell vector. Yet another reason one should never allow their webserver process to have too many permissions.

dawehner’s picture

+1 to always use the test mail collector, its what you always want. In case you want something else, you can still switch over.
I guess the odd message is not visible on the old testbase, because you have a different error handler?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 8: 2609680-8.patch, failed testing.

elachlan’s picture

Status: Needs work » Reviewed & tested by the community

Patch is now back to green.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

We still need tests for this in both KernelTestBaseTests

mile23’s picture

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new14.83 KB

This combines #2675202: Add an AssertMailTrait to allow mail testing in Kernel tests as suggested there. With this, then all tests that choose to use the new trait will be able to assert email results. Setting NR, although tests are still needed.

alexpott’s picture

Issue tags: -Needs tests
StatusFileSize
new8.94 KB
new18.82 KB

Added a test and fixed some coding standards. I don't think the deprecated KernelTestBase should be tested because there is massive work on to remove all the usages of this.

alexpott’s picture

WebTestBase has existing test coverage in Drupal\simpletest\Tests\MailCaptureTest... the test added here is a verbatim copy of that and just a couple of changes for phpunit style assertions.

alexpott’s picture

Title: Odd stdout not found in test output » Add an AssertMailTrait to allow mail testing in Kernel tests and fix odd stdout not found in test output
Issue summary: View changes
dawehner’s picture

Nice work!

  1. +++ b/core/tests/Drupal/KernelTests/Core/Test/AssertMailTraitTest.php
    @@ -0,0 +1,91 @@
    +      $this->assertMail($field, $value, sprintf('The email was sent and the value for property %s is intact.', $field));
    

    Is there some real value in the sprintf here?

  2. +++ b/core/tests/Drupal/KernelTests/Core/Test/AssertMailTraitTest.php
    @@ -0,0 +1,91 @@
    +    // Test different ways of getting filtered emails via drupalGetMails().
    ...
    +    // drupalGetMails-filter correctly returns all emails with a given
    

    these docs still refer to the old function names.

alexpott’s picture

StatusFileSize
new3.98 KB
new18.96 KB

thanks for the review @dawehner patch fixes all of that

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Cool

  • catch committed e01b1cc on 8.2.x
    Issue #2609680 by alexpott, jhedstrom: Add an AssertMailTrait to allow...

  • catch committed de21ee2 on 8.1.x
    Issue #2609680 by alexpott, jhedstrom: Add an AssertMailTrait to allow...

  • catch committed 7784c35 on 8.0.x
    Issue #2609680 by alexpott, jhedstrom: Add an AssertMailTrait to allow...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to all three 8.x branches, thanks!

catch’s picture

Er adding review credit post-commit.

arla’s picture

Status: Fixed » Active

Why was this copied from WebTestBase but changed from a normal config set to an override? That goes against the accompanying comment statement "some tests expect to be able to test mail system implementations" because now they cannot.

How about changing to a config set like in WebTestBase?

alexpott’s picture

@Arla they can just set the global and be done - no?

alexpott’s picture

Status: Active » Closed (fixed)

Also I don't think re-opening the issue is necessary - if we want to change this we can open another issue and add comments here to point people to it.