DsgnWrks-Instagram-Importer icon indicating copy to clipboard operation
DsgnWrks-Instagram-Importer copied to clipboard

Instructions for running tests locally

Open nfriedly opened this issue 6 years ago • 15 comments

Hey, I noticed the dockerunit.json file, which I'm guessing is for local testing, but I feel like I'm not sufficiently in-the-loop with php to know what the current standards are.

Would you be willing to write up some instructions for how to test this locally?

Even just a couple of commands + links to external documentation would be helpful.

nfriedly avatar Oct 22 '18 19:10 nfriedly

Good question. 1st, the dockerunit file file is no longer used, so should be deleted.

To run tests locally, first, you need to run this script to install the test framework: https://github.com/jtsternberg/DsgnWrks-Instagram-Importer/blob/master/tests/bin/install-wp-tests.sh

Then you should be able to run the phphunit command in the root of this repo. If you don’t have phpunit, you’ll need to install it: https://phpunit.de/ Let me know if you need more direction.

jtsternberg avatar Oct 22 '18 19:10 jtsternberg

Cool, I'll give it a shot sometime soon and then send a PR to add this to the readme.

nfriedly avatar Oct 22 '18 20:10 nfriedly

Great! in keeping w/ the github recommendations, let's instead put the instructions in a CONTRIBUTING.md file, and link to that from the readme.

jtsternberg avatar Oct 22 '18 20:10 jtsternberg

Hey, I created a branch called testing-instructions, and I feel like I have things set up correctly, but wordpress always complains about the database.

I tried a few different things: global vs local install of phpunit, MySQL vs MariaDB, etc, but nothing seemed to make any difference.

As far as I can tell, install-wp-tests.sh never creates a wp-config.php and so I'm guessing that wp-tests-config.php is supposed to manage that (?)

I'll attach my /tmp/wordpress-tests-lib/wp-tests-config.php file, but it looks correct to me. wp-tests-config.php.zip

Any other ideas what I'm missing? I could go ahead and create a wp-config.php, but I feel like that's not the right answer since Travis CI doesn't seem to need it.

Here's some logs:

MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ php -v
PHP 7.1.16 (cli) (built: Mar 31 2018 02:59:59) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ mysql --version
mysql  Ver 15.1 Distrib 10.3.10-MariaDB, for osx10.13 (x86_64) using readline 5.1
MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ ./vendor/bin/phpunit --version
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.

MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ ./tests/bin/install-wp-tests.sh wpdb root ''
+ install_wp
+ '[' /tmp/wordpress/ == '' ']'
+ mkdir -p /tmp/wordpress/
+ '[' latest == latest ']'
+ local ARCHIVE_NAME=latest
+ download https://wordpress.org/latest.tar.gz /tmp/wordpress.tar.gz
++ which curl
+ '[' /usr/bin/curl ']'
+ curl -s https://wordpress.org/latest.tar.gz
+ tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C /tmp/wordpress/
+ download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php /tmp/wordpress//wp-content/db.php
++ which curl
+ '[' /usr/bin/curl ']'
+ curl -s https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
+ install_test_suite
++ uname -s
+ [[ Darwin == \D\a\r\w\i\n ]]
+ local 'ioption=-i .bak'
+ '[' /tmp/wordpress-tests-lib == '' ']'
+ mkdir -p /tmp/wordpress-tests-lib
+ svn co --quiet https://develop.svn.wordpress.org/tags/4.9.8/tests/phpunit/includes/ /tmp/wordpress-tests-lib/includes
+ cd /tmp/wordpress-tests-lib
+ download https://develop.svn.wordpress.org/tags/4.9.8/wp-tests-config-sample.php /tmp/wordpress-tests-lib/wp-tests-config.php
++ which curl
+ '[' /usr/bin/curl ']'
+ curl -s https://develop.svn.wordpress.org/tags/4.9.8/wp-tests-config-sample.php
+ sed -i .bak 's:dirname( __FILE__ ) . '\''/src/'\'':'\''/tmp/wordpress/'\'':' /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak 's:define( '\''WP_DEBUG'\'', true );:define( '\''WP_DEBUG'\'', true ); define( '\''WP_DEBUG_LOG'\'', true );:' /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak s/youremptytestdbnamehere/wpdb/ /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak s/yourusernamehere/root/ /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak s/yourpasswordhere// /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak 's|localhost|localhost|' /tmp/wordpress-tests-lib/wp-tests-config.php
+ install_db
+ 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'
+ mysql --user=root --password= --host=localhost --protocol=tcp -e 'DROP DATABASE IF EXISTS wpdb'
+ mysqladmin create wpdb --user=root --password= --host=localhost --protocol=tcp
MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ ./vendor/bin/phpunit

wp_die called
Message : <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 that you have typed the correct hostname?</li>
<li>Are you sure that 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="https://wordpress.org/support/">WordPress Support Forums</a>.</p>

Title : 

Also, one unrelated question about these two sections:

https://github.com/jtsternberg/DsgnWrks-Instagram-Importer/blob/afef8f8dbff2573f7a6cd69cf1c8a71f27716be7/tests/bin/install-wp-tests.sh#L45-L48

https://github.com/jtsternberg/DsgnWrks-Instagram-Importer/blob/afef8f8dbff2573f7a6cd69cf1c8a71f27716be7/tests/bin/install-wp-tests.sh#L72-L75

Am I missing something, or is that supposed to be a != (or something else?)

nfriedly avatar Oct 24 '18 10:10 nfriedly

Reviewing now

jtsternberg avatar Oct 26 '18 13:10 jtsternberg

Ok, I pushed some updates to the testing-instructions branch. Please pull those down, and re-run composer install. Once that's complete, try running tests/bin/phpunit (or php tests/bin/phpunit). Both of those should be run from the root of the plugin repo.

Let me know how that goes.

jtsternberg avatar Oct 29 '18 15:10 jtsternberg

So, with the updated branch, I get less output from phpunit, but it still fails :/

MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ ./tests/bin/install-wp-tests.sh wpdb root
+ install_wp
+ '[' /tmp/wordpress/ == '' ']'
+ mkdir -p /tmp/wordpress/
+ '[' latest == latest ']'
+ local ARCHIVE_NAME=latest
+ download https://wordpress.org/latest.tar.gz /tmp/wordpress.tar.gz
++ which curl
+ '[' /usr/bin/curl ']'
+ curl -s https://wordpress.org/latest.tar.gz
+ tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C /tmp/wordpress/
+ download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php /tmp/wordpress/wp-content/db.php
++ which curl
+ '[' /usr/bin/curl ']'
+ curl -s https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
+ '[' '!' -d /tmp/wordpress/tests/data/themedir1/dummy-theme/ ']'
+ install_test_suite
+ CONFIG=/tmp/wordpress-tests-lib/wp-tests-config.php
++ uname -s
+ [[ Darwin == \D\a\r\w\i\n ]]
++ which sed
+ [[ /usr/bin/sed == \/\u\s\r\/\b\i\n\/\s\e\d ]]
+ local 'ioption=-i .bak'
+ '[' /tmp/wordpress-tests-lib == '' ']'
+ '[' -d /tmp/wordpress-tests-lib/includes ']'
+ rm -rf /tmp/wordpress-tests-lib/includes
+ mkdir -p /tmp/wordpress-tests-lib
+ svn co --quiet https://develop.svn.wordpress.org/tags/4.9.8/tests/phpunit/includes/ /tmp/wordpress-tests-lib/includes
+ cd /tmp/wordpress-tests-lib
+ download https://develop.svn.wordpress.org/tags/4.9.8/wp-tests-config-sample.php /tmp/wordpress-tests-lib/wp-tests-config.php
++ which curl
+ '[' /usr/bin/curl ']'
+ curl -s https://develop.svn.wordpress.org/tags/4.9.8/wp-tests-config-sample.php
+ sed -i .bak 's:dirname( __FILE__ ) . '\''/src/'\'':'\''/tmp/wordpress/'\'':' /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak 's:define( '\''WP_DEBUG'\'', true );:define( '\''WP_DEBUG'\'', true ); define( '\''WP_DEBUG_DISPLAY'\'', false ); define( '\''WP_DEBUG_LOG'\'', true );:' /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak s/youremptytestdbnamehere/wpdb/ /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak s/yourusernamehere/root/ /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak s/yourpasswordhere// /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak 's|localhost|localhost|' /tmp/wordpress-tests-lib/wp-tests-config.php
+ install_db
+ 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'
+ mysql --user=root --password= --host=localhost --protocol=tcp -e 'DROP DATABASE IF EXISTS wpdb'
mysql: [Warning] Using a password on the command line interface can be insecure.
+ mysqladmin create wpdb --user=root --password= --host=localhost --protocol=tcp
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
+ mysql --user=root --password= --host=localhost --protocol=tcp -e 'set global net_buffer_length=1000000;set global max_allowed_packet=1000000000;'
mysql: [Warning] Using a password on the command line interface can be insecure.
MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ ./vendor/bin/phpunit

wp_die called
MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ phpunit

wp_die called

nfriedly avatar Oct 30 '18 13:10 nfriedly

Ok, can you try running these exactly?

This should remove any previous test installs

rm -rf /tmp/wordpress/

This should reinstall it, and the DB for testing

bash ./tests/bin/install-wp-tests.sh wordpress_test root ''

And when that completes:

This should run phpunit from the script setup by composer

php ./tests/bin/phpunit

(not ./vendor/bin/phpunit)

It might still not work, but want to be sure we're on the same page.

jtsternberg avatar Oct 30 '18 14:10 jtsternberg

Oh, also, related to your question about the logic in those lines for the installer, I just pushed an update to properly check if those directories exist.

jtsternberg avatar Oct 30 '18 14:10 jtsternberg

No change as far as I can tell:

MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 5 (delta 2), reused 5 (delta 2), pack-reused 0
Unpacking objects: 100% (5/5), done.
From github.com:jtsternberg/DsgnWrks-Instagram-Importer
   25fe429..cb9aba2  testing-instructions -> origin/testing-instructions
Updating 25fe429..cb9aba2
Fast-forward
 tests/bin/install-wp-tests.sh | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ rm -rf /tmp/wordpress/
MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ bash ./tests/bin/install-wp-tests.sh wordpress_test root ''
+ install_wp
+ '[' -d /tmp/wordpress/ ']'
+ mkdir -p /tmp/wordpress/
+ '[' latest == latest ']'
+ local ARCHIVE_NAME=latest
+ download https://wordpress.org/latest.tar.gz /tmp/wordpress.tar.gz
++ which curl
+ '[' /usr/bin/curl ']'
+ curl -s https://wordpress.org/latest.tar.gz
+ tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C /tmp/wordpress/
+ download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php /tmp/wordpress/wp-content/db.php
++ which curl
+ '[' /usr/bin/curl ']'
+ curl -s https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
+ '[' '!' -d /tmp/wordpress/tests/data/themedir1/dummy-theme/ ']'
+ mkdir -p /tmp/wordpress/tests/data/themedir1/dummy-theme/
+ install_test_suite
+ CONFIG=/tmp/wordpress-tests-lib/wp-tests-config.php
++ uname -s
+ [[ Darwin == \D\a\r\w\i\n ]]
++ which sed
+ [[ /usr/bin/sed == \/\u\s\r\/\b\i\n\/\s\e\d ]]
+ local 'ioption=-i .bak'
+ '[' -d /tmp/wordpress-tests-lib ']'
+ rm -rf /tmp/wordpress-tests-lib
+ '[' -d /tmp/wordpress-tests-lib/includes ']'
+ mkdir -p /tmp/wordpress-tests-lib
+ svn co --quiet https://develop.svn.wordpress.org/tags/4.9.8/tests/phpunit/includes/ /tmp/wordpress-tests-lib/includes
+ cd /tmp/wordpress-tests-lib
+ download https://develop.svn.wordpress.org/tags/4.9.8/wp-tests-config-sample.php /tmp/wordpress-tests-lib/wp-tests-config.php
++ which curl
+ '[' /usr/bin/curl ']'
+ curl -s https://develop.svn.wordpress.org/tags/4.9.8/wp-tests-config-sample.php
+ sed -i .bak 's:dirname( __FILE__ ) . '\''/src/'\'':'\''/tmp/wordpress/'\'':' /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak 's:define( '\''WP_DEBUG'\'', true );:define( '\''WP_DEBUG'\'', true ); define( '\''WP_DEBUG_DISPLAY'\'', false ); define( '\''WP_DEBUG_LOG'\'', true );:' /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak s/youremptytestdbnamehere/wordpress_test/ /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak s/yourusernamehere/root/ /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak s/yourpasswordhere// /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak 's|localhost|localhost|' /tmp/wordpress-tests-lib/wp-tests-config.php
+ install_db
+ 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'
+ mysql --user=root --password= --host=localhost --protocol=tcp -e 'DROP DATABASE IF EXISTS wordpress_test'
mysql: [Warning] Using a password on the command line interface can be insecure.
+ mysqladmin create wordpress_test --user=root --password= --host=localhost --protocol=tcp
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
+ mysql --user=root --password= --host=localhost --protocol=tcp -e 'set global net_buffer_length=1000000;set global max_allowed_packet=1000000000;'
mysql: [Warning] Using a password on the command line interface can be insecure.
MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ php ./tests/bin/phpunit

wp_die called

nfriedly avatar Oct 30 '18 14:10 nfriedly

What if you run the tests in the file explicitly? php ./tests/bin/phpunit ./tests/test-dsgnwrks-instagram-importer.php

jtsternberg avatar Oct 30 '18 14:10 jtsternberg

MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ php ./tests/bin/phpunit ./tests/test-dsgnwrks-instagram-importer.php

wp_die called

nfriedly avatar Oct 30 '18 15:10 nfriedly

Ugh. I'm not sure. Maybe look into this? https://github.com/wp-cli/wp-cli/issues/1340#issuecomment-77376192

(e.g. bash ./tests/bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1)

jtsternberg avatar Oct 30 '18 15:10 jtsternberg

Nope :/

Although good find!

MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ bash ./tests/bin/install-wp-tests.sh wordpress_test root '' '127.0.0.1'
+ install_wp
+ '[' -d /tmp/wordpress/ ']'
+ rm -rf /tmp/wordpress/
+ mkdir -p /tmp/wordpress/
+ '[' latest == latest ']'
+ local ARCHIVE_NAME=latest
+ download https://wordpress.org/latest.tar.gz /tmp/wordpress.tar.gz
++ which curl
+ '[' /usr/bin/curl ']'
+ curl -s https://wordpress.org/latest.tar.gz
+ tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C /tmp/wordpress/
+ download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php /tmp/wordpress/wp-content/db.php
++ which curl
+ '[' /usr/bin/curl ']'
+ curl -s https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
+ '[' '!' -d /tmp/wordpress/tests/data/themedir1/dummy-theme/ ']'
+ mkdir -p /tmp/wordpress/tests/data/themedir1/dummy-theme/
+ install_test_suite
+ CONFIG=/tmp/wordpress-tests-lib/wp-tests-config.php
++ uname -s
+ [[ Darwin == \D\a\r\w\i\n ]]
++ which sed
+ [[ /usr/bin/sed == \/\u\s\r\/\b\i\n\/\s\e\d ]]
+ local 'ioption=-i .bak'
+ '[' -d /tmp/wordpress-tests-lib ']'
+ rm -rf /tmp/wordpress-tests-lib
+ '[' -d /tmp/wordpress-tests-lib/includes ']'
+ mkdir -p /tmp/wordpress-tests-lib
+ svn co --quiet https://develop.svn.wordpress.org/tags/4.9.8/tests/phpunit/includes/ /tmp/wordpress-tests-lib/includes
+ cd /tmp/wordpress-tests-lib
+ download https://develop.svn.wordpress.org/tags/4.9.8/wp-tests-config-sample.php /tmp/wordpress-tests-lib/wp-tests-config.php
++ which curl
+ '[' /usr/bin/curl ']'
+ curl -s https://develop.svn.wordpress.org/tags/4.9.8/wp-tests-config-sample.php
+ sed -i .bak 's:dirname( __FILE__ ) . '\''/src/'\'':'\''/tmp/wordpress/'\'':' /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak 's:define( '\''WP_DEBUG'\'', true );:define( '\''WP_DEBUG'\'', true ); define( '\''WP_DEBUG_DISPLAY'\'', false ); define( '\''WP_DEBUG_LOG'\'', true );:' /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak s/youremptytestdbnamehere/wordpress_test/ /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak s/yourusernamehere/root/ /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak s/yourpasswordhere// /tmp/wordpress-tests-lib/wp-tests-config.php
+ sed -i .bak 's|localhost|127.0.0.1|' /tmp/wordpress-tests-lib/wp-tests-config.php
+ install_db
+ PARTS=(${DB_HOST//\:/ })
+ local PARTS
+ local DB_HOSTNAME=127.0.0.1
+ local DB_SOCK_OR_PORT=
+ local EXTRA=
+ '[' -z 127.0.0.1 ']'
++ echo
++ grep -e '^[0-9]\{1,\}$'
+ '[' ']'
+ '[' -z ']'
+ '[' -z 127.0.0.1 ']'
+ EXTRA=' --host=127.0.0.1 --protocol=tcp'
+ mysql --user=root --password= --host=127.0.0.1 --protocol=tcp -e 'DROP DATABASE IF EXISTS wordpress_test'
mysql: [Warning] Using a password on the command line interface can be insecure.
+ mysqladmin create wordpress_test --user=root --password= --host=127.0.0.1 --protocol=tcp
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
+ mysql --user=root --password= --host=127.0.0.1 --protocol=tcp -e 'set global net_buffer_length=1000000;set global max_allowed_packet=1000000000;'
mysql: [Warning] Using a password on the command line interface can be insecure.
MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ php ./tests/bin/phpunit

wp_die called

I'll get some VM's running and try it out on windows or Linux sometime soon.

nfriedly avatar Oct 30 '18 17:10 nfriedly

Ugh. I'm not sure. Maybe look into this? wp-cli/wp-cli#1340 (comment)

(e.g. bash ./tests/bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1)

Thank You so much it is working for me

imrantushar avatar Sep 17 '21 18:09 imrantushar