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] => Array
(
[0] => CRM_Core_Error
[1] => handle
)
[code] => -24
[message] => DB Error: connect failed
[mode] => 16
[debug_info] => [nativecode=mysqli_connect() expects parameter 5 to be integer, string given]
[type] => DB_Error
[user_info] => [nativecode=mysqli_connect() expects parameter 5 to be integer, string given]
[to_string] => [db_error: message="DB Error: connect failed" code=-24 mode=callback callback=CRM_Core_Error::handle prefix="" info=" [nativecode=mysqli_connect() expects parameter 5 to be integer, string given]"]
)
</pre></p><p></p><p>Initialization Error</p><p><pre>Array
(
[callback] => Array
(
[0] => CRM_Core_Error
[1] => handle
)
[code] => -24
[message] => DB Error: connect failed
[mode] => 16
[debug_info] => [nativecode=mysqli_connect() expects parameter 5 to be integer, string given]
[type] => DB_Error
[user_info] => [nativecode=mysqli_connect() expects parameter 5 to be integer, string given]
[to_string] => [db_error: message="DB Error: connect failed" code=-24 mode=callback callback=CRM_Core_Error::handle prefix="" info=" [nativecode=mysqli_connect() expects parameter 5 to be integer, string given]"]
)
</pre></p><p></p>
Question: Am I doing something wrong? Is this a bug in civibuild or elsewhere? How can I get around this?
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 '20 at 17:09localhost:
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-checkamp config
and make then DSN look like the others (eg127.0.0.1:3306
). – Tim Otten Oct 15 '20 at 20:03amp config
was the problem. By re-runningamp config
, this time specifying a port in the DSN, and then destroying and rebuilding thedrupal-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 '20 at 17:41