Skip to content

Use icecave/isolator to mock filesystem and getenv. - #6

Closed
nubs wants to merge 1 commit into
dnoegel:masterfrom
nubs:isolator
Closed

Use icecave/isolator to mock filesystem and getenv.#6
nubs wants to merge 1 commit into
dnoegel:masterfrom
nubs:isolator

Conversation

@nubs

@nubs nubs commented Aug 26, 2014

Copy link
Copy Markdown

Discussed in #4, this uses the Isolator class (really just a mock, but its nice to have something to point to) in order to mock out filesystem calls. These changes mean that the actual filesystem is no longer touched when running the tests.

Discussed in dnoegel#4, this uses the Isolator class (really just a mock, but
its nice to have something to point to) in order to mock out filesystem
calls.  These changes mean that the actual filesystem is no longer
touched when running the tests.
Comment thread src/Xdg.php

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rmdir call doesn't seem right to me. Shouldn't this be unlink instead as the $fallback isn't a directory and rmdir wouldn't work?

@bcremer

bcremer commented Aug 27, 2014

Copy link
Copy Markdown
Contributor

I created a alternative for this in PR #7, at least for the getenv part.

I'm not certain about your getRuntimeDir() tests.
You tests basically are testing the mocks and the internal order of method calls in the implementation of the method.

The getRuntimeDir method is used to create real filesystem directories and should be testen on a real filesystem.

I added the tests that write to the filesystem to the "filesystem" group in the phpunit tests, so they can be skipped.

In the future I would like to separate the getRuntimeDir() write logik into a separate class that is entirely responsible for creating directories.

@nubs

nubs commented Aug 27, 2014

Copy link
Copy Markdown
Author

You are right about the order of things being tricky. I'd much rather see things split out into something else that could be mocked away more easily without the complicated series of mocks.

But why do you think that it should run against a real filesystem? We don't need to make sure that mkdir actually makes directories, we just need to make sure that getRuntimeDir calls mkdir when a directory doesn't exist.

I wholeheartedly agree that things could be factored out differently in order to reduce the amount of calls that are being made by the function under test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants