PHPackages                             jdgrimes/wp-plugin-uninstall-tester - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. jdgrimes/wp-plugin-uninstall-tester

Abandoned → [jdgrimes/wpppb](/?search=jdgrimes%2Fwpppb)Library[Testing &amp; Quality](/categories/testing)

jdgrimes/wp-plugin-uninstall-tester
===================================

Utilities for testing WordPress plugin install/uninstall with PHPUnit

0.6.0(9y ago)95.0k61MITPHPPHP &gt;=5.2.0

Since Aug 29Pushed 9y ago1 watchersCompare

[ Source](https://github.com/JDGrimes/wp-plugin-uninstall-tester)[ Packagist](https://packagist.org/packages/jdgrimes/wp-plugin-uninstall-tester)[ Docs](https://github.com/JDGrimes/wp-plugin-uninstall-tester)[ RSS](/packages/jdgrimes-wp-plugin-uninstall-tester/feed)WikiDiscussions master Synced today

READMEChangelog (10)DependenciesVersions (10)Used By (1)

WP Plugin Uninstall Tester
==========================

[](#wp-plugin-uninstall-tester)

A testcase class for testing plugin install and uninstall, with related tools.

Notice
======

[](#notice)

This project is no longer maintained. It has been merged into the [WP Plugin PHPUnit Bootstrap](https://github.com/JDGrimes/wpppb). It is recommended that you use that instead.

Background
==========

[](#background)

The purpose of this testcase is to allow you to make plugin uninstall testing as realistic as possible. WordPress uninstalls plugins when they aren't active, and these tools allow you simulate that. The installation is performed remotely, so the plugin is not loaded when the tests are being run.

I created these tools after finding that there was a fatal error in one of my plugin's uninstall scripts. Not that I didn't have unit tests for uninstallation. I did. But the uninstall tests were being run with the plugin already loaded. So I never realized that I was calling one of the plugin's functions that wouldn't normally be available. That's when I decided to create these testing tools, so my uninstall tests would fail if I wasn't including all required dependencies in my plugin's uninstall script.

In addition to providing a realistic uninstall testing environment, it also provides some assertions to help you make sure that your plugin entirely cleaned up the database.

Installation
============

[](#installation)

Composer
--------

[](#composer)

```
composer require --dev jdgrimes/wp-plugin-uninstall-tester
```

Set Up
======

[](#set-up)

Once you have the testing tools installed, you need to make a few changes to your bootstrap file for PHPUnit. We're going to assume that you have a bootstrap file similar to the one in [this tutorial](http://codesymphony.co/writing-wordpress-plugin-unit-tests/).

First, you need to include the `/includes/functions.php` file, so you can use `running_wp_plugin_uninstall_tests()` to check if the uninstall tests are being run. You need to be sure that you only load your plugin's files if the uninstall tests aren't being run.

```
/*
 * This needs to go after you include WordPress's unit test functions, but before
 * loading WordPress's bootstrap.php file.
 */

// Include the uninstall test tools functions.
include_once dirname( __FILE__ ) . '/../../../vendor/jdgrimes/wp-plugin-uninstall-tester/includes/functions.php';

// Check if the tests are running. Only load the plugin if they aren't.
if ( ! running_wp_plugin_uninstall_tests() ) {
	tests_add_filter( 'muplugins_loaded', 'my_plugin_activate' );
}
```

Secondly, you need to include the `bootstrap.php` file:

```
/*
 * This needs to be included after loading WordPress's bootstrap.php, because the
 * uninstall testcase extends WordPress's WP_UnitTestCase class.
 */

include_once dirname( __FILE__ ) . '/../../../vendor/jdgrimes/wp-plugin-uninstall-tester/bootstrap.php';
```

Thirdly, you need to exclude the `uninstall` group from the tests in your PHPUnit XML config file:

```

			uninstall

```

That will exclude the uninstall tests from running by default. To run them, you'll need to do `phpunit --group=uninstall`.

Finally, you need to make sure that you've copied or symlinked your plugin into the plugins folder of the test site (if you aren't developing it there already):

```
ln -s path/to/my-plugin path/to/trunk/src/wp-content/plugins/my-plugin
```

Usage
=====

[](#usage)

Now, it's finally time to create a testcase. To do this, extend the `WP_Plugin_Uninstall_UnitTestCase`class.

```
