Download the PHP package lipemat/wp-unit without Composer

On this page you can find all versions of the php package lipemat/wp-unit. 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-unit

WP Unit

Packagist

Fork of wp-unit to support bootstrapping an existing database and many other enhancements.

Note: Version 4 has diverged from the original WordPress core tests. More information here.

Original may be cloned from here: git://develop.git.wordpress.org/tests/phpunit

Usage

Install using composer either in you project or in a global location to be used among all projects.

Example phpunit.xml

Example bootstrap.php file

Example wp-tests-config.php

Example unit test /tests/ExampleTest.php

Run the test suite like any other phpunit suite

Excluding PHPUnit From Composer

If you are using an external PHP Unit executable or .phar and do not want phpunit/phpunit to be installed as part of your composer vendor, you may add the following configuration to your composer.json file.

Enhancements

Network Options

Setting a wp_tests_options value may also be used to set a network option. Set test options like normal, and they will automatically replace network option values as well.

Run all scheduled crons

Used for testing crons by running them if they are schedule to run.

Local wp-tests-config.php

You may set up your wp-tests.config.php in the directory of your bootstrap.php and phpunit.xml. Really this can be put anywhere as long as you point to it in your bootstrap.php file.

Bootstrap WP on existing database

Using the bootstrap-no-install.php allows you to test against your current data in the database. Out of the box it supports MySQL transactions to allow tests to set and use data without actually storing it in the database.

  1. Update your wp-tests-config.php file to point to database you want to use.
  2. Change your bootstrap.php to use the bootstrap-no-install.php file like so;

Gotchas:

  1. If you override the WP_UnitTestCase::setUp() method in your test class, be sure to call parent::setUp(). Otherwise, any data you set during tests will persist to the database.
  2. If your database tables are using MyISAM storage engines, data will persist. They may be converted to InnoDB or any other engine which supports transactions.

Global filters which apply to all tests

From within your wp-tests-config.php file add some filters to the $GLOBALS[ 'wp_tests_filters' ]

Turn on mail sending

Set a memory limit

From within your wp-tests.config.php add a custom memory limit.

Allow an outside languages directory

From within your wp-tests.config.php add a custom language directory.

Prevent plugins from breaking mysql transactions

Some third party plugins use their own transactions which cause unpredictable results with the transactions used by wp-unit.

This library automatically accounts for outside transactions.

Support custom ajax methods.

Sometimes you want to use ajax responses to calls which live outside the wp_ajax actions.

This library adds methods to WP_Ajax_UnitTestCase:

  1. _handleAjaxCustom which will turn any callable into an wp_ajax action then call it via _handleAjax.
  2. _getJsonResult call any callable which uses wp_send_json_success or wp_send_json_error and return the result.

Support raw request testing.

Sometimes you want to verify requests are actually going out and not just assert that a method which sends requests is being called.

  1. Extend the WP_Http_Remote_Post_TestCase from your test's class.
  2. All requests will not send but instead be stored in the test's class' properties.
  3. Retrieve sent via $this->get_sent().
  4. Mock raw responses via $this->mock_response.

Support object cache testing

For testing your object cache a helper TestCase is available. Automatically resets for a fresh object cache between tests.

  1. Extend the Object_Cache_TestCase from your test's class.
  2. Interact with $this->object_cache to access your object cache.
  3. Use include helper assertions and utilities.
    1. assertNotCacheExternal - Assert a key is not available in the external cache.
    2. assertCacheExternal - Assert a key is available in the external cache.
    3. assertCachePropertyAndExternal - Assert a value is same in the runtime cache as external cache.
    4. get_cache_key - Get parsed key sent to external cache.

Automatically generate files for Attachment factory.

Many follow-up attachment calls require the attachment to have an actual file attached to it. For example get_the_post_thumbnail_url will always be empty if a file does not exist.

This automatically adds files to the create call via self::factory()->attachment.

Support assertEqualSetsValues on all TestCases

Support testing two arrays of values while accounting for order but ignoring array keys. Useful for testing things like pagination.

Example:

Support assertEqualSetsIndex on all TestCases

Asserts that the keys of two arrays are equal, regardless of the contents, without accounting for the order of elements.

Support mocking final classes.

Includes a utilities library to enable mocking of any final classes.

db/bypass-finals

Enable for tests via.

Extending the WP_UnitTestCase

Some project require additional functionality to be added to every test case. Most commonly this is required for rolling back transactions on custom database adapters.

To use your own version of the WP_UnitTestCase:

  1. Create a WP_UnitTestCase class in your local project.
  2. Extend WP_UnitTestCase_Base in your class.
  3. Add your custom test methods to your class.
  4. Define a WP_UNIT_TESTCASE_BASE constant with the path to your class.

Example for a SQLite3 database

In your project create a WP_UnitTestCase.php file.

In your bootstrap.php file add the following line.


All versions of wp-unit with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4.0
yoast/phpunit-polyfills Version ^2.0.0
dg/bypass-finals Version ^1.5
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 lipemat/wp-unit contains the following files

Loading the files please wait ....