1

I'm trying to get up and running with drupal php functional testing. However there seems to be something wrong with my phpunit.xml cofiguration. When running the test i get the following error:

PHPUnit 9.5.25 #StandWithUkraine

Testing /Applications/MAMP/htdocs/dl-staging/web/modules/custom
E                                                                   1 / 1 (100%)R

Time: 00:04.717, Memory: 12.00 MB

There was 1 error:

1) Drupal\Tests\dl_micro_mas\FunctionalJavascript\QITest::testQuotesInvoices
Drupal\Core\Installer\Exception\InstallerException: Resolve all issues below to continue the installation. For help configuring your database server, see the <a href="https://www.drupal.org/docs/8/install">installation handbook</a>, or contact your hosting provider.<ul><li>Database <em class="placeholder">dl_test/</em> not found. The server reports the following message when attempting to create the database: <em class="placeholder">SQLSTATE[HY000]: General error: 1007 Can&#039;t create database &#039;dl_test&#039;; database exists</em>.</li><li>Failed to <strong>CREATE</strong> a test table on your database server with the command <em class="placeholder">CREATE TABLE {drupal_install_test} (id int NOT NULL PRIMARY KEY)</em>. The server reports the following message: <em class="placeholder">SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected: CREATE TABLE &quot;test21167818drupal_install_test&quot; (id int NOT NULL PRIMARY KEY); Array
(
)
</em>.<p>Are you sure the configured username has the necessary permissions to create tables in the database?</p></li></ul>

So this implies that phpunit doesn't have access to the database. However, i'm using the exact same database user login as on my drupal site.

This is my phpunit.xml file

<?xml version="1.0" encoding="UTF-8"?>
<!-- For how to customize PHPUnit configuration, see core/tests/README.md. -->
<!-- TODO set checkForUnintentionallyCoveredCode="true" once https://www.drupal.org/node/2626832 is resolved. -->
<!-- PHPUnit expects functional tests to be run with either a privileged user
 or your current system user. See core/tests/README.md and
 https://www.drupal.org/node/2116263 for details.
-->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="web/core/tests/bootstrap.php" colors="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" beStrictAboutChangesToGlobalState="true" failOnWarning="true" printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter" cacheResult="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
  <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="http://www.website.build:8888"/>
    <!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix -->
    <env name="SIMPLETEST_DB" value="mysql://root:root@localhost:8889/dl_test/"/>
    <!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/browser_output -->
    <env name="BROWSERTEST_OUTPUT_DIRECTORY" value="browser_output"/>
    <!-- To have browsertest output use an alternative base URL. For example if
     SIMPLETEST_BASE_URL is an internal DDEV URL, you can set this to the
     external DDev URL so you can follow the links directly.
    -->
    <env name="BROWSERTEST_OUTPUT_BASE_URL" value=""/>
    <!-- To disable deprecation testing completely uncomment the next line. -->
    <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
    <!-- Example for changing the driver class for mink tests MINK_DRIVER_CLASS value: 'Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver' -->
    <env name="MINK_DRIVER_CLASS" value=""/>
    <!-- Example for changing the driver args to mink tests MINK_DRIVER_ARGS value: '["http://127.0.0.1:8510"]' -->
    <env name="MINK_DRIVER_ARGS" value=""/>
    <!-- Example for changing the driver args to webdriver tests MINK_DRIVER_ARGS_WEBDRIVER value: '["chrome", { "chromeOptions": { "w3c": false } }, "http://localhost:4444/wd/hub"]' For using the Firefox browser, replace "chrome" with "firefox" -->
    <env name="MINK_DRIVER_ARGS_WEBDRIVER" value=""/>
  </php>
  <listeners>
    <listener class="\Drupal\Tests\Listeners\DrupalListener">
    </listener>
  </listeners>
  <!-- Filter for coverage reports. -->
</phpunit>

So what is wrong here? The database exists and the user exists. I'm out of ideas...

kevinius
  • 4,232
  • 7
  • 48
  • 79
  • Need to establish the "default database". In the mysql commandline tool, it would be via "use ...". In some APIs, it would be "changedb(...)" – Rick James Oct 14 '22 at 17:50

0 Answers0