Hailwood
Hailwood

Reputation: 92661

Writing tests with unknown variables

I am trying to use PHPunit to do testing.

One of the tests I am writing requires scanning a directories sub directories for a certain folder.

I want to write a test that checks to make sure it does not fail if the folder does not exist.

The issue is that the directory it scans may or may not have the folder in it. so I am confused as to how I am meant to do this.

One option I could see is to move everything out of the directory, run the assertion, and then move everything back in, but that seems messy to me. What is the best way to do this?

Upvotes: 1

Views: 68

Answers (1)

Mark Baker
Mark Baker

Reputation: 212502

phpunit actually provides a means to mock the filesystem using vfsStream. This is described in the PHPUnit documentation (specifically look at example 10.19 to see how this is used). vfsStream acts as a wrapper for the filesystem.

Upvotes: 3

Related Questions