PHPackages                             ralphjsmit/pest-plugin-filesystem - 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. [Framework](/categories/framework)
4. /
5. ralphjsmit/pest-plugin-filesystem

ActiveLibrary[Framework](/categories/framework)

ralphjsmit/pest-plugin-filesystem
=================================

A set of handy filesystem testing helpers for Pest.

1.2.0(3y ago)31.6k3MITPHPPHP ^8.0

Since Dec 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ralphjsmit/pest-plugin-filesystem)[ Packagist](https://packagist.org/packages/ralphjsmit/pest-plugin-filesystem)[ RSS](/packages/ralphjsmit-pest-plugin-filesystem/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (3)Versions (8)Used By (3)

Handy filesystem helpers for your Pest tests
============================================

[](#handy-filesystem-helpers-for-your-pest-tests)

Testing with Pest is an absolute pleasure, but sometimes you just need that little bit extra. In my case, that extra was a set of expectations and functions to interact with the filesystem and make assertions on it. Below I made a list with all the helpers currently available. Enjoy!

Important

This package will only work for Pest V1 and not for Pest V2.

Contents
--------

[](#contents)

1. Expectations
    1. [expect(...)-&gt;toHaveContents()](#expect-tohavecontents)
    2. [expect(...)-&gt;toExist()](#expect-toexist)
    3. [expect(...)-&gt;toHaveNamespace()](#expect-tohavenamespace)
2. Higher-order expectations
    1. [expect(...)-&gt;contents-&gt;toBe(...)](#expect-contents-tobe)
3. Functions
    1. [rm($path, $allowNonExisting)](#rmpath-allownonexisting)
    2. [rmdir\_recursive($dir)](#rmdir_recursivedir)
    3. [contents($path)](#contentspath)
    4. [expectFailedAssertion()](#expectfailedassertion)

Expectations
------------

[](#expectations)

### expect(...)-&gt;toHaveContents()

[](#expect-tohavecontents)

Test whether a file has certain contents:

```
file_put_contents(__DIR__ . '/tmp/fileA.php', 'I\'m a test file!');
file_put_contents(__DIR__ . '/tmp/fileB.php', 'I\'m a second test file!');

expect(__DIR__ . '/tmp/fileA.php')->toHaveContents('I\'m a test file!');
expect(__DIR__ . '/tmp/fileB.php')->not->toHaveContents('I\'m a test file!');
```

### expect(...)-&gt;toExist()

[](#expect-toexist)

Test whether a file exists:

```
expect(__DIR__ . '/tmp/fileA.php')->toExist();
```

### expect(...)-&gt;toHaveNamespace()

[](#expect-tohavenamespace)

Test whether a file has a certain namespace (PHP-only):

```
expect(__DIR__ . '/tmp/fileA.php')->toHaveNamespace('App\Models');
```

Higher-order expectations
-------------------------

[](#higher-order-expectations)

### expect(...)-&gt;contents-&gt;toBe(...)

[](#expect-contents-tobe)

Make assertions on the contents of a file:

```
file_put_contents(__DIR__ . '/tmp/fileA.php', 'I\'m a test file!');

expect(__DIR__ . '/tmp/fileA.php')
    ->contents->toBe('I\'m a test file!')
    ->toContain('test file')
    ->not->toContain('Hello world');
```

Functions
---------

[](#functions)

### rm($path, $allowNonExisting)

[](#rmpath-allownonexisting)

Completely remove a file or directory:

```
use function RalphJSmit\PestPluginFilesystem\rm;

rm(__DIR__ . '/tmp'); // Make sure that this file or directory doesn't exist

file_put_contents(__DIR__ . '/tmp/fileA.php', 'I\'m a test file!');
file_put_contents(__DIR__ . '/tmp/fileB.php', 'I\'m a second test file!');

// Other code
```

### rmdir\_recursive($dir)

[](#rmdir_recursivedir)

This function recursively deletes a folder, including its contents. Internally this is used by the `rm()` function:

```
use function RalphJSmit\PestPluginFilesystem\rmdir_recursive;

rmdir_recursive(__DIR__ . '/tmp'); // Recursively remove this directory
```

### contents($path)

[](#contentspath)

Gets the file contents of a certain file. Its simply a shorter wrapper for `file_get_contents()`:

```
use function RalphJSmit\PestPluginFilesystem\contents;

expect(
    contents(__DIR__ . '/tmp/fileA.php')
)->toBe(
    contents(__DIR__ . '/tmp/fileB.php')
);
```

### expectFailedAssertion()

[](#expectfailedassertion)

> Note that this helper will be added to another package soon and thus be removed here.

Expect a failed assertion. Helpful for testing your own custom Pest assertions:

```
use function RalphJSmit\PestPluginFilesystem\expectFailedAssertion;

expectFailedAssertion();
expect(true)->toBe(false);

// This test will pass
```

```
// Somewhere
expect()->extend('toBeHello', function () {
    return $this->toBe('Hello there');
});

// In your test
use function RalphJSmit\PestPluginFilesystem\expectFailedAssertion;

expect('Hello there')->toBeHello(); // This will pass

expectFailedAssertion();
expect('Bye')->toBeHello(); // This will pass

expectFailedAssertion();
expect('Hello there')->toBeHello(); // This will fail
```

General
-------

[](#general)

🐞 If you spot a bug, please submit a detailed issue and I'll try to fix it as soon as possible.

🔐 If you discover a vulnerability, please review [our security policy](../../security/policy).

🙌 If you want to contribute, please submit a pull request. All PRs will be fully credited. If you're unsure whether I'd accept your idea, feel free to contact me!

🙋‍♂️ [Ralph J. Smit](https://ralphjsmit.com)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity59

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 ~69 days

Recently: every ~103 days

Total

7

Last Release

1184d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/59207045?v=4)[Ralph J. Smit](/maintainers/ralphjsmit)[@ralphjsmit](https://github.com/ralphjsmit)

---

Top Contributors

[![ralphjsmit](https://avatars.githubusercontent.com/u/59207045?v=4)](https://github.com/ralphjsmit "ralphjsmit (62 commits)")

---

Tags

phpplugintestingunitframeworktestpest

### Embed Badge

![Health badge](/badges/ralphjsmit-pest-plugin-filesystem/health.svg)

```
[![Health](https://phpackages.com/badges/ralphjsmit-pest-plugin-filesystem/health.svg)](https://phpackages.com/packages/ralphjsmit-pest-plugin-filesystem)
```

###  Alternatives

[defstudio/pest-plugin-laravel-expectations

A plugin to add laravel tailored expectations to Pest

98548.9k4](/packages/defstudio-pest-plugin-laravel-expectations)[pestphp/pest-plugin-stressless

Stressless plugin for Pest

67792.6k16](/packages/pestphp-pest-plugin-stressless)[jonpurvis/lawman

A PestPHP Plugin to help with architecture testing SaloonPHP integrations

4027.7k8](/packages/jonpurvis-lawman)[spatie/pest-plugin-route-testing

Make sure all routes in your Laravel app are ok

13753.8k](/packages/spatie-pest-plugin-route-testing)[milroyfraser/pest-plugin-gwt

Given When Then(GWT) Plugin for Pest

10332.1k1](/packages/milroyfraser-pest-plugin-gwt)[ozzie/pest-plugin-nest

Nest Pest PHP tests for better organization and readability

2028.3k](/packages/ozzie-pest-plugin-nest)

PHPackages © 2026

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