ทำไม phpunit จึงบอกว่า“ DB Error: connect failed” สำหรับไซต์ 'drupal-clean' ใหม่

Oct 15 2020

ฉันมีไซต์ civibuild 'drupal-clean' ใหม่ซึ่งทำงานได้ดีในเบราว์เซอร์ แต่เมื่อฉันพยายามเรียกใช้การทดสอบ civicrm phpunit ฉันได้รับข้อผิดพลาดในการเชื่อมต่อ mysql "DB Error: connect failed" ฉันจะหลีกเลี่ยงปัญหานี้และเรียกใช้การทดสอบได้อย่างไร

ความเป็นมา: ฉันใช้ civibuild อย่างมีความสุขมาหลายปีแล้วและได้ทำการทดสอบ civicrm กับสภาพแวดล้อมนี้ในอดีตแม้ว่าจะไม่ใช่ภายในสองสามเดือนที่ผ่านมา

ขั้นตอนที่ฉันได้ดำเนินการเพื่อช่วยให้แน่ใจว่าฉันเริ่มต้นใหม่จริงๆ (เอาท์พุทคัดลอกวางจริงจากเทอร์มินัลตอนนี้):

10:57 $ cd /opt/buildkit 10:57 $ git remote -v
origin  [email protected]:twomice/civicrm-buildkit.git (fetch)
origin  [email protected]: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:[email protected]:3306/canary_jfliz?new_link=true) Skip (root=/opt/buildkit/build/drupal-demo-upgrade, name=cms, dsn=mysql://drupaldemo_xi1bz:[email protected]:3306/drupaldemo_xi1bz?new_link=true) Skip (root=/opt/buildkit/build/drupal-demo-upgrade, name=civi, dsn=mysql://drupaldemo_durf6:[email protected]:3306/drupaldemo_durf6?new_link=true) Skip (root=/opt/buildkit/build/drupal-demo-upgrade, name=test, dsn=mysql://drupaldemo_fwg09:[email protected]:3306/drupaldemo_fwg09?new_link=true) Skip (root=/opt/buildkit/build/wp-demo, name=cms, dsn=mysql://wpdemocms_vg6e1:[email protected]:3306/wpdemocms_vg6e1?new_link=true) Skip (root=/opt/buildkit/build/wp-demo, name=civi, dsn=mysql://wpdemocivi_lti76:[email protected]:3306/wpdemocivi_lti76?new_link=true) Skip (root=/opt/buildkit/build/wp-demo, name=test, dsn=mysql://wpdemotest_e9znx:[email protected]:3306/wpdemotest_e9znx?new_link=true) Skip (root=/opt/buildkit/build/universe, name=cms, dsn=mysql://universecm_4nnv1:[email protected]:3306/universecm_4nnv1?new_link=true) Skip (root=/opt/buildkit/build/universe, name=civi, dsn=mysql://universeci_7xjxh:[email protected]:3306/universeci_7xjxh?new_link=true) Skip (root=/opt/buildkit/build/universe, name=test, dsn=mysql://universete_sus8o:[email protected]: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.

ณ จุดนี้ฉันเข้าสู่ไซต์ Drupal ใหม่ที่ http://drupal-clean.amp.lฉันไปที่ CiviCRM และดูเหมือนว่าทั้งหมดจะทำงานได้ดี

กลับไปที่บรรทัดคำสั่งตอนนี้ฉันพยายามเรียกใช้ 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>

คำถาม:ฉันทำอะไรผิดหรือเปล่า? นี่เป็นข้อผิดพลาดใน civibuild หรือที่อื่น ๆ ? ฉันจะหลีกเลี่ยงสิ่งนี้ได้อย่างไร?

คำตอบ

Demerit Oct 17 2020 at 02:27

ปัญหาคือข้อมูลจำเพาะของพอร์ตที่ขาดหายไปตามหลักฐานที่localhost:มีเครื่องหมายโคลอน แต่ไม่มีพอร์ตและมีหลักฐานเพิ่มเติมเนื่องจากพอร์ตเป็นพารามิเตอร์ 5 ถึง mysqli_connect () เช่นเดียวกับข้อผิดพลาด amp configจำเป็นต้องรันใหม่และระบุพอร์ต