6

I've test classes based on KernelTestBase.

Previously everything was working smoothly, now I came back to the project and I'm hit by this error:

Install profile will be a mandatory parameter in Drupal 9.0.

Drupal version: 8.3.5 PHPUnit version: 4.8.35

phpunit.xml:

<phpunit bootstrap="web/core/tests/bootstrap.php" colors="true"
         beStrictAboutTestsThatDoNotTestAnything="true"
         beStrictAboutOutputDuringTests="true"
         beStrictAboutChangesToGlobalState="true"
         checkForUnintentionallyCoveredCode="false">
<!-- TODO set printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter" once
 https://youtrack.jetbrains.com/issue/WI-24808 is resolved. Drupal provides a
 result printer that links to the html output results for functional tests.
 Unfortunately, this breaks the output of PHPStorm's PHPUnit runner. However, if
 using the command line you can add
 - -printer="\Drupal\Tests\Listeners\HtmlOutputPrinter" to use it (note there
 should be no spaces between the hyphens).
-->
  <php>
    <!-- Set error reporting to E_ALL. -->
    <ini name="error_reporting" value="32767"/>
    <!-- Do not limit the amount of memory tests take to run. -->
    <ini name="memory_limit" value="-1"/>
    <!-- Example SIMPLETEST_BASE_URL value: http://localhost -->
    <env name="SIMPLETEST_BASE_URL" value=""/>
    <!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix -->
    <env name="SIMPLETEST_DB" value="mysql://vagrant:vagrant@localhost/vagrant"/>
    <!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->
    <env name="BROWSERTEST_OUTPUT_DIRECTORY" value=""/>
  </php>
  <testsuites>
    <testsuite name="mymod">
      <file>web/modules/custom/mymod/tests/src/Kernel/FooTest.php</file>
    </testsuite>
    <!-- etc -->
  </testsuites>
  <listeners>
    <listener class="\Drupal\Tests\Listeners\DrupalStandardsListener">
    </listener>
  </listeners>
  <!-- Filter for coverage reports. -->
  <filter>
    <whitelist>
      <directory>./web/core/includes</directory>
      <directory>./web/core/lib</directory>
      <directory>./web/core/modules</directory>
      <directory>./web/core/modules</directory>
      <directory>./web/core/sites</directory>
      <!-- By definition test classes have no tests. -->
      <exclude>
        <directory suffix="Test.php">./</directory>
        <directory suffix="TestBase.php">./</directory>
      </exclude>
     </whitelist>
  </filter>
</phpunit>

Test class:

class FooTest extends KernelTestBase {

  protected static $modules = ['foo'];

  public function testFoo() {
    self::assertEquals(2, 2);
  }

}

I'm launching it from PHPStorm via:

vagrant:///Users/drupality/Develop/drupal/myproj/usr/bin/php /home/vagrant/.phpstorm_helpers/phpunit.php --group foo --configuration /var/www/myproj/site/phpunit.xml --filter "/::testFoo( .*)?$/" Drupal\Tests\foo\Kernel\FooTest /var/www/myproj/site/web/modules/custom/myproj/tests/src/Kernel/FooTest.php

UPDATE

I've updated PHPUnit to 5.7.21 (newest supported by PHPStorm) but still no success.

  • The error seems to be triggered from here: api.drupal.org/api/drupal/… - what test are you running? – Kevin Aug 9 '17 at 13:30
  • @Kevin added code snippet. – Codium Aug 9 '17 at 14:36
  • No idea. That's how it was when I opened it. Anyway... that just looks like a unit test. Are you running this from CLI? How about defining $modules and $profile members? – Kevin Aug 9 '17 at 14:39
  • Why the downvotes? Seems like a legit question to me? – Gun5m0k3 Aug 9 '17 at 14:44
  • 1
    Does it @Gun5m0k3? What's the question? ;) – Clive Aug 9 '17 at 14:59
2

Your problem is that your test and/or code is relying on a deprecated feature.

In Drupal 8.3, there was a push to have deprecated featured generate E_USER_DEPRECATED messages, eg in Drupal\Core\Config\ExtensionInstallStorage:

  public function __construct(StorageInterface $config_storage, $directory = self::CONFIG_INSTALL_DIRECTORY, $collection = StorageInterface::DEFAULT_COLLECTION, $include_profile = TRUE, $profile = NULL) {
    parent::__construct($directory, $collection);
    $this->configStorage = $config_storage;
    $this->includeProfile = $include_profile;
    if (is_null($profile)) {
      @trigger_error('Install profile will be a mandatory parameter in Drupal 9.0.', E_USER_DEPRECATED);
    }
    $this->installProfile = $profile ?: \Drupal::installProfile();
  }

This is to provide early warning to developers to update their code.

If the code is hit in a phpunit test (which includes unit tests, kernel tests, and functional tests using BrowserTestBase), anything from trigger_error will generate a fail.

So, you either need to fix your code, or you can cause the test to not fail by using the @expectedDeprecation annotation on the test method until you can fix it.

  • Going by memory here, will fill out with references if I remember to. – mpdonadio Aug 9 '17 at 15:10
  • so the unit test code is not raising it (error cause is somewhere else)? I'm dealing with legacy code, don't know the full code base yet. – Codium Aug 9 '17 at 17:11
  • @drupality More than likely the test is using a module that uses that relies on this. However, none of the existing KTB tests in core suppress this error. Not sure that is going on in your case where the installation profile is needed and not passed in. – mpdonadio Aug 9 '17 at 17:28
  • thanks, but even with this annotation, still same error :/ – Codium Aug 9 '17 at 18:09
  • Could you post the modified version of your test that uses the @expectedDeprecation annotation? Just to be sure we are following the same steps. Thanks! – Stefanos Petrakis Aug 13 '17 at 10:34
0

I had this issue. To get rid of some I could just do this in my setUp method:

 $this->setInstallProfile('testing');

In others though I had to override the register method of the parent class:

  /**
   * {@inheritdoc}
   */
  public function register(ContainerBuilder $container) {
    parent::register($container);
    $this->container->setParameter('install_profile', 'testing');
  }

Obviously, like much of Drupal 8, it would be nice if this were documented somewhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.