jtsternberg / DsgnWrks-Instagram-Importer

Backup your instagram photos & display your instagram archive. Supports importing to custom post-types & adding custom taxonomies.
http://wordpress.org/extend/plugins/dsgnwrks-instagram-importer/
33 stars 17 forks source link

Instructions for running tests locally #49

Open nfriedly opened 5 years ago

nfriedly commented 5 years ago

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.

jtsternberg commented 5 years ago

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.

nfriedly commented 5 years ago

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

jtsternberg commented 5 years ago

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.

nfriedly commented 5 years ago

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?)

jtsternberg commented 5 years ago

Reviewing now

jtsternberg commented 5 years ago

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.

nfriedly commented 5 years ago

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
jtsternberg commented 5 years ago

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 commented 5 years ago

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.

nfriedly commented 5 years ago

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
jtsternberg commented 5 years ago

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

nfriedly commented 5 years ago
MLREM1712156:DsgnWrks-Instagram-Importer nathan.friedly$ php ./tests/bin/phpunit ./tests/test-dsgnwrks-instagram-importer.php

wp_die called
jtsternberg commented 5 years ago

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)

nfriedly commented 5 years ago

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.

imrantushar commented 3 years ago

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