1

I have a new 'drupal-clean' civibuild site which works fine in the browser, yet when I try to run civicrm phpunit tests, I get a mysql connection error, "DB Error: connect failed". How can I avoid this and run tests successfully?

Background: I've used civibuild happily for some years now, and have run civicrm tests on this environment in the past, though not within the past few months.

Steps I've taken to help ensure I'm really starting from scratch (actual copy-paste output from terminal, just now):

10:57 $ cd /opt/buildkit

10:57 $ git remote -v
origin  git@github.com:twomice/civicrm-buildkit.git (fetch)
origin  git@github.com:twomice/civicrm-buildkit.git (push)
upstream    https://github.com/civicrm/civicrm-buildkit.git (fetch)
upstream    https://github.com/civicrm/civicrm-buildkit.git (push)

10:59 $ git fetch upstream

10:59 $ git checkout upstream/master
HEAD is now at 4b3be16... Merge pull request #572 from seamuslee001/contact_layout_download

10:59 $ ./bin/civi-download-tools
WARNING: The following data-files are not owned by your user, which may lead to permission issues. You may need to delete or chown them.
$ find /home/as/.cache ! -user as
find: ‘/home/as/.cache/shotwell’: Permission denied
/home/as/.cache/pip
[... EDITED OUT: lots of files under /home/as/.cache/pip ...]
[[Composer binary (/opt/buildkit/bin/composer) already exists. Skipping.]]
[[composer dependencies already installed. Skipping.]]
[[npm dependencies already installed. Skipping.]]
[[hub (/opt/buildkit/extern/hub) already exists. Skipping.]]
WARNING: Failed to find recommended PHP extension "imap".
WARNING: Failed to find recommended PHP extension "soap".

11:02 $ civibuild destroy drupal-clean
WARNING: Failed to find recommended PHP extension "imap".
WARNING: Failed to find recommended PHP extension "soap".
[[Load saved options from /opt/buildkit/build/drupal-clean.sh]]
Are you sure you want destroy "/opt/buildkit/build/drupal-clean"? [y/N] y
chmod: changing permissions of '/opt/buildkit/build/drupal-clean/web/sites/default/files/civicrm/persist/contribute/dyn': Operation not permitted
[ ... EDITED OUT: lots more similar permission errors ...]

11:06 $ sudo chown -R as:as /opt/buildkit/build/drupal-clean/web/sites/default/

11:06 $ civibuild destroy drupal-clean
WARNING: Failed to find recommended PHP extension "imap".
WARNING: Failed to find recommended PHP extension "soap".
[[Load saved options from /opt/buildkit/build/drupal-clean.sh]]
Are you sure you want destroy "/opt/buildkit/build/drupal-clean"? [y/N] y
Skip (root=/home/as/.amp/canary, name=, dsn=mysql://canary_jfliz:RZTEqGwHenB5hvw6@127.0.0.1:3306/canary_jfliz?new_link=true)
Skip (root=/opt/buildkit/build/drupal-demo-upgrade, name=cms, dsn=mysql://drupaldemo_xi1bz:p9sSXFAoQWtQWBXq@127.0.0.1:3306/drupaldemo_xi1bz?new_link=true)
Skip (root=/opt/buildkit/build/drupal-demo-upgrade, name=civi, dsn=mysql://drupaldemo_durf6:5BFZ8k7DFqz1Vhl9@127.0.0.1:3306/drupaldemo_durf6?new_link=true)
Skip (root=/opt/buildkit/build/drupal-demo-upgrade, name=test, dsn=mysql://drupaldemo_fwg09:gHQTx18KUAP0mWlu@127.0.0.1:3306/drupaldemo_fwg09?new_link=true)
Skip (root=/opt/buildkit/build/wp-demo, name=cms, dsn=mysql://wpdemocms_vg6e1:JNKQtnQuLoPjy1he@127.0.0.1:3306/wpdemocms_vg6e1?new_link=true)
Skip (root=/opt/buildkit/build/wp-demo, name=civi, dsn=mysql://wpdemocivi_lti76:L8Z5oSsVNIWJ6o5H@127.0.0.1:3306/wpdemocivi_lti76?new_link=true)
Skip (root=/opt/buildkit/build/wp-demo, name=test, dsn=mysql://wpdemotest_e9znx:Wy0GXjWUR8Uzh1Aw@127.0.0.1:3306/wpdemotest_e9znx?new_link=true)
Skip (root=/opt/buildkit/build/universe, name=cms, dsn=mysql://universecm_4nnv1:hu1xzZuDmOjHKWvI@127.0.0.1:3306/universecm_4nnv1?new_link=true)
Skip (root=/opt/buildkit/build/universe, name=civi, dsn=mysql://universeci_7xjxh:0hoMsYdDASKViX4B@127.0.0.1:3306/universeci_7xjxh?new_link=true)
Skip (root=/opt/buildkit/build/universe, name=test, dsn=mysql://universete_sus8o:7AZhYqfN3pKmmASM@127.0.0.1:3306/universete_sus8o?new_link=true)
Destroy (root=/opt/buildkit/build/drupal-clean/web, name=cms, dsn=mysql://drupalclea_f3qli:aYrs9Zbz58LC6vfI@localhost:/drupalcleancms_w6ifm?new_link=true)
Destroy (root=/opt/buildkit/build/drupal-clean/web, name=civi, dsn=mysql://drupalclea_q2x49:kPQax5KCbBSpSiMX@localhost:/drupalcleancivi_dy8w0?new_link=true)
Destroy (root=/opt/buildkit/build/drupal-clean/web, name=test, dsn=mysql://drupalclea_178yz:zMEh3p6ooZDzpfYc@localhost:/drupalcleantest_vm9nd?new_link=true)
Destroyed 3 instance(s)

11:06 $ ls /opt/buildkit/build
drupal-demo-upgrade  drupal-demo-upgrade.sh  universe  universe.sh  wp-demo  wp-demo.sh

11:07 $ civibuild create drupal-clean
[ ... EDITED OUT: lots of civibuild output ... ]
[[Show site summary (drupal-clean/default)]]
 - CMS_ROOT: /opt/buildkit/build/drupal-clean/web
 - CMS_URL: http://drupal-clean.amp.l
 - CMS_DB_DSN: mysql://drupalclea_ybzuc:BaoDsQTs4EJo4yB7@localhost:/drupalcleancms_9r44i?new_link=true
 - CIVI_DB_DSN: mysql://drupalclea_4wr9l:yuaXYepeH6OIb6j5@localhost:/drupalcleancivi_irtdh?new_link=true
 - TEST_DB_DSN: mysql://drupalclea_m87tm:UMIBQhCy9l2cMU5V@localhost:/drupalcleantest_c5gl6?new_link=true
 - ADMIN_USER: admin
 - ADMIN_PASS: Ah0ejAJFXnxN
 - DEMO_USER: demo
 - DEMO_PASS: demo
[[General notes]]
 - You may need to restart httpd.
 - You may need to add the hostname and IP to /etc/hosts or DNS.

At this point I log into the new Drupal site at http://drupal-clean.amp.l, I visit CiviCRM, and all appears to be working well.

Back at the command line now, I try to run phpunit:

11:15 $ cd /opt/buildkit/build/drupal-clean/web/sites/all/modules/civicrm

11:17 $ env CIVICRM_UF=UnitTests phpunit5 ./tests/phpunit/CRM/AllTests.php
Parsing schema description /opt/buildkit/build/drupal-clean/web/sites/all/modules/civicrm/xml/schema/Schema.xml
Extracting database information
Extracting table information
Installing drupalcleantest_c5gl6 schema
<p>Initialization Error</p><p><pre>Array
(
    [callback] =&gt; Array
        (
            [0] =&gt; CRM_Core_Error
            [1] =&gt; handle
        )

    [code] =&gt; -24
    [message] =&gt; DB Error: connect failed
    [mode] =&gt; 16
    [debug_info] =&gt;  [nativecode=mysqli_connect() expects parameter 5 to be integer, string given]
    [type] =&gt; DB_Error
    [user_info] =&gt;  [nativecode=mysqli_connect() expects parameter 5 to be integer, string given]
    [to_string] =&gt; [db_error: message=&quot;DB Error: connect failed&quot; code=-24 mode=callback callback=CRM_Core_Error::handle prefix=&quot;&quot; info=&quot; [nativecode=mysqli_connect() expects parameter 5 to be integer, string given]&quot;]
)
</pre></p><p></p><p>Initialization Error</p><p><pre>Array
(
    [callback] =&gt; Array
        (
            [0] =&gt; CRM_Core_Error
            [1] =&gt; handle
        )

    [code] =&gt; -24
    [message] =&gt; DB Error: connect failed
    [mode] =&gt; 16
    [debug_info] =&gt;  [nativecode=mysqli_connect() expects parameter 5 to be integer, string given]
    [type] =&gt; DB_Error
    [user_info] =&gt;  [nativecode=mysqli_connect() expects parameter 5 to be integer, string given]
    [to_string] =&gt; [db_error: message=&quot;DB Error: connect failed&quot; code=-24 mode=callback callback=CRM_Core_Error::handle prefix=&quot;&quot; info=&quot; [nativecode=mysqli_connect() expects parameter 5 to be integer, string given]&quot;]
)
</pre></p><p></p>

Question: Am I doing something wrong? Is this a bug in civibuild or elsewhere? How can I get around this?

  • 1
    It might not be relevant but core tests all run with phpunit7 now. Also I note the TEST_DB_DSN doesn't specify a port (localhost:) and parameter 5 is port. I don't use buildkit much ('cuz windows) but I believe it runs mysql on another port so you'd need to specify that somewhere? What does cv.json have? Although it's also not specified for the others but you said it runs ok for web use so not sure. – Demerit Oct 14 at 17:09
  • 1
    Yeah, the localhost: DSN looks fishy. FWIW, I've had issues before where a DSN works in one SAPI (e.g. web-requests) but fails in another SAPI (e.g. cli), which was cleared by making the DSN more precise. Maybe double-check amp config and make then DSN look like the others (eg 127.0.0.1:3306). – Tim Otten Oct 15 at 20:03
  • Yes, the missing port in the DSN from amp config was the problem. By re-running amp config, this time specifying a port in the DSN, and then destroying and rebuilding the drupal-clean build site, tests are running now without this error. If someone wants to make an answer, I'll accept it. Thanks! – TwoMice Oct 16 at 17:41
0

The problem was a missing port specification as evidenced by the localhost: with a colon but no port, and evidenced further since port is parameter 5 to mysqli_connect() as in the error. amp config needed re-running and specifying a port.

| improve this answer | |

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.