PHPackages                             jdgrimes/wp-filesystem-mock - 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-filesystem-mock

ActiveLibrary[Testing &amp; Quality](/categories/testing)

jdgrimes/wp-filesystem-mock
===========================

Shim for the WordPress filesystem API to use a mock filesystem in PHPUnit tests

0.1.2(8y ago)43.1kMITPHPPHP &gt;=5.2.0

Since Mar 26Pushed 8y ago1 watchersCompare

[ Source](https://github.com/JDGrimes/wp-filesystem-mock)[ Packagist](https://packagist.org/packages/jdgrimes/wp-filesystem-mock)[ Docs](https://github.com/JDGrimes/wp-filesystem-mock)[ RSS](/packages/jdgrimes-wp-filesystem-mock/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

WP Filesystem Mock [![Build Status](https://camo.githubusercontent.com/d4fac5a9fc004168c192cfd3001ec3ddc0390ff08f5f6e5ddb6898df3af728bf/68747470733a2f2f7472617669732d63692e6f72672f4a444772696d65732f77702d66696c6573797374656d2d6d6f636b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/JDGrimes/wp-filesystem-mock)
===================================================================================================================================================================================================================================================================================================================================

[](#wp-filesystem-mock-)

Provides a class that can be used as a mock filesystem, and also a shim for the WordPress filesystem API that uses it. This is useful in unit tests that include simple filesystem operations.

Requirements
------------

[](#requirements)

- **PHP**: 5.2.17+
- **WordPress**: 3.9+

It will probably work with earlier versions of WordPress as well, but that is all that I have tested.

Note that WordPress is actually not required, and you can use the filesystem mocker without it (you just won't be able to use the extension of WordPress's filesystem API).

Installation
------------

[](#installation)

You may install with composer:

```
composer require --dev jdgrimes/wp-filesystem-mock
```

Usage
-----

[](#usage)

If you aren't using auto-loading, the first thing you need to do is load the thing:

```
		/**
		 * WordPress's base filesystem API class.
		 *
		 * We need to make sure this is loaded before we can load the mock.
		 */
		require_once( ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php' );

		/**
		 * The filesystem API shim that uses mock filesystems.
		 */
		require_once( MY_TESTS_DIR . '/../../vendor/jdgrimes/wp-filesystem-mock/src/wp-filesystem-mock.php' );

		/**
		 * The mock filesystem class.
		 */
		require_once( MY_TESTS_DIR . '/../../vendor/jdgrimes/wp-filesystem-mock/src/wp-mock-filesystem.php' );
```

To use the mock filesystem in your tests, just add this code (e.g., in your PHPUnit testcase's `setUp()` method):

```
		// Creating a new mock filesystem.
		// We assign it to a member property so we can access it later.
		$this->mock_fs = new WP_Mock_Filesystem;

		// Create the /wp-content directory.
		// This part is optional, and you'll do more or less setup here depending on
		// what you are testing.
		$this->mock_fs->mkdir_p( WP_CONTENT_DIR );

		// Tell the WordPress filesystem API shim to use this mock filesystem.
		WP_Filesystem_Mock::set_mock( $this->mock_fs );

		// Tell the shim to start overriding whatever other filesystem access method
		// is in use.
		WP_Filesystem_Mock::start();

		// Set up the $wp_filesystem global, if the code being tested doesn't do this.
		WP_Filesystem();
```

For a full view of what the it can do, check the source.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~451 days

Total

3

Last Release

3168d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4005415?v=4)[J.D. Grimes](/maintainers/jdgrimes)[@JDGrimes](https://github.com/JDGrimes)

---

Top Contributors

[![JDGrimes](https://avatars.githubusercontent.com/u/4005415?v=4)](https://github.com/JDGrimes "JDGrimes (18 commits)")

---

Tags

phpunitphpunit-testswordpresswordpress-filesystem-api

### Embed Badge

![Health badge](/badges/jdgrimes-wp-filesystem-mock/health.svg)

```
[![Health](https://phpackages.com/badges/jdgrimes-wp-filesystem-mock/health.svg)](https://phpackages.com/packages/jdgrimes-wp-filesystem-mock)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
