Questions tagged [vfs-stream]

vfsStream is a stream wrapper for a virtual file system.

vfsStream may be helpful in unit tests to mock the real file system. It can be used with any unit test framework, like PHPUnit or SimpleTest. http://vfs.bovigo.org/

21 questions
16
votes
3 answers

PHPUnit: How do I mock this file system?

Consider the following scenario (this is not production code): class MyClass { public function myMethod() { // create a directory $path = sys_get_temp_dir() . '/' . md5(rand()); if(!mkdir($path)) { throw new…
Elliot Chance
  • 5,526
  • 10
  • 49
  • 80
9
votes
2 answers

vfsstream paths and realpath

I'm experimenting with vfsStream for unit testing filesystem interactions and have very quickly run into a major hurdle. One of the validation checks the code under test does is execute realpath() on a supplied input path to test that it's an…
GordonM
  • 31,179
  • 15
  • 87
  • 129
8
votes
2 answers

Trying to test filesystem operations with VFSStream

I'm trying to mock a filesystem operation (well actually a read from php://input) with vfsStream but the lack of decent documentation and examples is really hampering me. The relevant code from the class I'm testing is as follows: class…
GordonM
  • 31,179
  • 15
  • 87
  • 129
6
votes
2 answers

PHPUnit: How can I mock this file creation?

I want to mock the creation of a file using the vfsstream class MyClass{ public function createFile($dirPath) { $name = time() . "-RT"; $file = $dirPath . '/' . $name . '.tmp'; fopen($file, "w+"); if (file_exists($file)) { …
Dev DOS
  • 1,018
  • 4
  • 18
  • 45
3
votes
2 answers

Insert a file into specific directory/node using vfsStream

The use case of vfsStream is as follows: $directories = explode('/', 'path/to/some/dir'); $structure = []; $reference =& $structure; foreach ($directories as $directory) { $reference[$directory] = []; $reference =&…
sitilge
  • 3,687
  • 4
  • 30
  • 56
3
votes
2 answers

vfsstream: file_get_contents() failed to open stream: stream_open call failed

I have set up a vfsstream block device and I'm trying to call file_get_contents() on it. However the call to vfsStreamWrapper::stream_open fails and therefore the stream cannot be opened. Here is my code: $this->root =…
Conor Wright
  • 41
  • 1
  • 3
2
votes
1 answer

CodeIgniter 3 - Composer Update Error - vfsstream

When running composer update for my CodeIgniter 3 project, I get the following error: > sed -i s/name{0}/name[0]/ vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStream.php sed: 1: "vendor/mikey179/vfsstre ...": invalid command code…
hatchtag
  • 33
  • 5
2
votes
0 answers

How to mock images and other file formats with vfsStream?

I am able to mock text files of any size and images of any resolution. But for my tests I need images of any resolution and simultaneously of any file size (e.g.: 800x600px and 100 MB) as well as other file formats like PDFs. When I use…
Zini
  • 53
  • 7
2
votes
1 answer

FilesystemIterator with vfsStream

I am using (learning) vfsStream to test file system operations on a directory tree with 23,000 items in it. Here's what I am trying to do in a PHPUnit test: public function testMockFS() { $buffer = (array)…
DrDamnit
  • 4,736
  • 4
  • 23
  • 38
1
vote
1 answer

file_put_contents into vfsstream raises error `failed to open stream:`

I want to write UnitTests, mocking the Filesystem with vfs. My test looks like this:
Paflow
  • 2,030
  • 3
  • 30
  • 50
1
vote
1 answer

Apache VFS2 reply timeout from the server

I am using VFS2 to upload file to remote hosts (FTP, SFTP) for my clients but sometimes i have to wait up to 5 minutes to get a timeout if connection is established but the server doesn't reply. E.g. apache vfs receives a connection from remote…
Yuriy Korovko
  • 515
  • 2
  • 9
  • 21
1
vote
2 answers

How to mock file system with Laravel and vfsStream? [Laravel 5.1]

I have request like this: $path = storage_path('testing/unnamed.png'); $original_name = 'unnamed'; $mime_type = 'image/png'; $size = 2192; $error = null; $test = true; $file = new UploadedFile($path,…
Vladimir Djukic
  • 925
  • 2
  • 9
  • 28
1
vote
1 answer

How to mock readonly directory using PHPUnit and VFSstream

I have a simple open (file) method which should throw an exception if it fails to open or create a file in the given path: const ERR_MSG_OPEN_FILE = 'Failed to open or create file at %s'; public function open($filePath) { …
Ali
  • 2,993
  • 3
  • 19
  • 42
1
vote
1 answer

phpspec testing file contents / file operations

I'm curious about the best way of speccing classes that handle file operations. Assuming I have a fictional class with a method duplicate whose job is to duplicate the contents of a file.
Adam
  • 5,091
  • 5
  • 32
  • 49
1
vote
1 answer

PHP Unit testing and mocking a file system scandir()

I have a method in a class that scans a directory and creates an array of all the subdirectories. It's pretty simple and works great. However, I would like to add a unit test for this method and I am having a hard time figuring out how. Here's my…
Apollo
  • 945
  • 2
  • 9
  • 24
1
2