WordPress

wp cli — Błąd podczas nawiązywania połączenia z bazą danych podczas uruchamiania phpunit

  • 24 kwietnia, 2020
  • 4 min read
wp cli — Błąd podczas nawiązywania połączenia z bazą danych podczas uruchamiania phpunit


Śledzę, aby uruchomić testy jednostkowe dla wtyczek.

Tworzę nową wtyczkę.

$ wp scaffold plugin hello-plugin-1
Success: Created plugin files.
Success: Created test files.

Uruchomić install-wp-tests.sh.

$ cd wp-content/plugins/hello-plugin-1
$ ./bin/install-wp-tests.sh wordpress_test_1 root root localhost latest
+ install_wp
+ '[' -d /var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress/ ']'
+ return
+ install_test_suite
++ uname -s
+ [[ Darwin == \D\a\r\w\i\n ]]
+ local ioption=-i.bak
+ '[' '!' -d /var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress-tests-lib ']'
+ '[' '!' -f wp-tests-config.php ']'
+ download  /var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress-tests-lib/wp-tests-config.php
++ which curl
+ '[' /usr/bin/curl ']'
+ curl -s 
++ echo /var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress/
++ sed 's:/\+$::'
+ WP_CORE_DIR=/var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress/
+ sed -i.bak 's:dirname( __FILE__ ) . '\''/src/'\'':'\''/var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress//'\'':' /var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress-tests-lib/wp-tests-config.php
+ sed -i.bak s/youremptytestdbnamehere/wordpress_test_1/ /var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress-tests-lib/wp-tests-config.php
+ sed -i.bak s/yourusernamehere/root/ /var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress-tests-lib/wp-tests-config.php
+ sed -i.bak s/yourpasswordhere/root/ /var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress-tests-lib/wp-tests-config.php
+ sed -i.bak 's|localhost|localhost|' /var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress-tests-lib/wp-tests-config.php
+ install_db
+ '[' false = true ']'
+ PARTS=(${DB_HOST//\:/ })
+ local PARTS
+ local DB_HOSTNAME=localhost
+ local DB_SOCK_OR_PORT=
+ local EXTRA=
+ '[' -z localhost ']'
++ echo
++ grep -e '^[0-9]\{1,\}$'
+ '[' ']'
+ '[' -z ']'
+ '[' -z localhost ']'
+ EXTRA=' --host=localhost --protocol=tcp'
+ mysqladmin create wordpress_test_1 --user=root --password=root --host=localhost --protocol=tcp
mysqladmin: [Warning] Using a password on the command line interface can be insecure.

Uruchomić phpunit i dostałem ten błąd połączenia DB.

$ phpunit
PHP Warning:  mysqli_real_connect(): (HY000/2002): No such file or directory in /private/var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress/wp-includes/wp-db.php on line 1626
PHP Stack trace:
PHP   1. {main}() /private/var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress-tests-lib/includes/install.php:0
PHP   2. require_once() /private/var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress-tests-lib/includes/install.php:29
PHP   3. require_wp_db() /private/var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress/wp-settings.php:126
PHP   4. wpdb->__construct() /private/var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress/wp-includes/load.php:426
PHP   5. wpdb->db_connect() /private/var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress/wp-includes/wp-db.php:631
PHP   6. mysqli_real_connect() /private/var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress/wp-includes/wp-db.php:1626

wp_die called
Message : <p><code>No such file or directory</code></p>
<h1>Error establishing a database connection</h1>
<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can&#8217;t contact the database server at <code>localhost</code>. This could mean your host&#8217;s database server is down.</p>
<ul>
<li>Are you sure you have the correct username and password?</li>
<li>Are you sure you have typed the correct hostname?</li>
<li>Are you sure the database server is running?</li>
</ul>
<p>If you&#8217;re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href=" Support Forums</a>.</p>

Title : 

Czy musimy skonfigurować DB w wp-config.php W /var/folders/qd/y3hp2mb90gx36d5swtxcndhh0000gn/T/wordpress zanim uruchomię phpunit? Próbowałem tego i nie działało. Jakiś pomysł, co poszło nie tak?

Warto przeczytać!  Jak dodać stronę postu z przycisku bez ponownego ładowania

biegnę WP-CLI 2.4.0 I PHPUnit 7.5.9.


Źródło