Download the PHP package inpsyde/wp-tests-starter without Composer

On this page you can find all versions of the php package inpsyde/wp-tests-starter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wp-tests-starter

WP Tests Starter

Note: You're reading the documentation for the development branch towards version 2.0.0. You'll find the documentation for version 1.0 at the branch version-1

Wp Tests starter is a library that assist you in setting up integration tests for your plugin or library with WordPress core using the official wordpress-develop repository. The main difference to unit tests is that you don't need (and typically don't want) to mock any WordPress function. Instead, you have a fully booted WordPress core in place with an actual connection to a database server.

So if you're mapping your objects to WordPress posts in a ORM-style way your integration test would look like this:

No mocks required. Just WordPress working inside a PHPUnit test case.

Installation

In order to use Wp Tests Starter you need: a PHP environment with Composer and a MySQL server with a dedicated test database. This database should be completely ephemeral, so do not use any database that contains important data. You'll also need the following four Composer packages installed as dev dependencies:

As the last one is not available on packagist.org, you'll have to add the repo manually to your composer.json file by adding:

Now you can run

composer require --dev inpsyde/wp-tests-starter yoast/phpunit-polyfills wordpress/wordpress phpunit/phpunit

Note that this will take a while as Composer will analyze the entire WordPress repository on GitHub. (Once a composer.lock is in place it will go faster on the next install run)

Setup your tests

To set up your PHPUnit tests you need two files in place: phpunit.xml.dist and a boostrap.php which gets loaded by PHPUnit before your actual tests are executed. The shown examples of these two files assume a directory structure of your library like this:

├ src/
|  └ MyModule.php
├ tests/
|  ├integration/
|  |  └ MyModuleTest.php
|  └boostrap.php
├ vendor/
├ composer.json
└ phpunit.xml.dist

The following example of the phpunit.xml.dist file tells PHPUnit where the test files resides and contains the database credentials as an environment variable:

The tests/boostrap.php finally loads Wp Tests Starter and WordPress:

These files just show a short way to run integration tests with WP Tests Starter. You have several other configuration options available through the methods of the WpTestsStarter object.

Run PHPUnit

With this configuration in place you can run PHPUnit to execute all test classes in tests/integration with

vendor/bin/phpunit

On every run, WP Starter will write the configuration to vendor/wordpress/wordpress/wp-config.php and load the WordPress internal bootstrap script which ensures installation of the database tables for example.

Configuration

DB Url

In order to not have to maintain several environment variables you can pass all databse credentials and options via a single parameter like this:

mysql://user:password@localhost:3306/test_db?table_prefix=wp_tests_&charset=utf8mb4&collation=utf8_general_ci

This URL can be passed to WpTestsStarter either by constructor parameter or by useDbUrl() method:

The URL example above would turn into the following WordPress constants and globals:

Basically all the values of this URL are optional but keep in mind that you want to have a complete configuration for WordPress. Alternatively you can use explicit values:

License

This repository is a free software, and is released under the terms of the GNU General Public License version 2 or (at your option) any later version. See LICENSE for complete license.

Back to top


All versions of wp-tests-starter with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package inpsyde/wp-tests-starter contains the following files

Loading the files please wait ....