Jesús Amieiro

Running the GlotPress tests

GlotPress has some PHPUnit tests. In this post, I will go to explain how to run it in your local machine.

I am using a local environment, with PHP 7.4, WordPress and GlotPress installed cloning the repo into the /wp-content/plugins/ folder:

cd /wp-content/plugins/
git clone git@github.com:GlotPress/GlotPress.git
cd GlotPress

Install the dependencies:

composer install

If you execute:

composer test
# Alias command for php ./vendor/bin/phpunit

You get an error similar to this one:

Could not find /var/folders/d6/fsr146f96nq_tj4_k0qrr9y40000gn/T/wordpress-tests-lib/includes/functions.php, have you run bin/install-wp-tests.sh ?

Ok, you need to run “bin/install-wp-tests.sh”. First, you have to give execution permissions to this script:

chmod +x bin/install-wp-tests.sh

If you execute this script:

bin/install-wp-tests.sh

You get this error:

usage: bin/install-wp-tests.sh <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]

Ok, you have to pass some parameters to the database:

You need to create a MySQL or a MariaDB database in your system. Once you get it, you use this data with the previous command:

bin/install-wp-tests.sh glotpressdatabase glotpressuser glotpresspass

If all is ok, you will see the script running. It will take some time, because it has to download the WordPress latest version and do another things. May be, you should answer some simple questions.

Now, you can run the tests:

composer test

> @php ./vendor/bin/phpunit
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.28
Configuration: /Users/amieiro/code/wordpress/glotpress/wp-content/plugins/GlotPress-WP/phpunit.xml.dist

...............................................................  63 / 352 ( 17%)
............................................................... 126 / 352 ( 35%)
............................................................... 189 / 352 ( 53%)
............................................................... 252 / 352 ( 71%)
............................................................... 315 / 352 ( 89%)
.....................................                           352 / 352 (100%)

Time: 4.65 seconds, Memory: 44.50 MB

OK (352 tests, 1575 assertions)
Exit mobile version