vfsStream is a stream wrapper for a virtual file system that 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.

Overview

vfsStream

Tests Coverage Status Latest Stable Version Latest Unstable Version

vfsStream is a stream wrapper for a virtual file system that 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.

Documentation

See the wiki.

Also you might want to check vfsStream examples.

Comments
  • Fix: Use lower-case for package name

    Fix: Use lower-case for package name

    This PR

    • [x] uses lower-case for the package name in composer.json

    💁‍♂️ Following an update of composer to 1.8.1, the following message is emitted when running related composer commands

    Deprecation warning: require-dev.mikey179/vfsStream is invalid, it should not contain uppercase characters. Please use mikey179/vfsstream instead. Make sure you fix this as Composer 2.0 will error.

    For reference, see https://github.com/composer/composer/releases/tag/1.8.1.

    opened by localheinz 15
  • Added support for emulating block devices in the virtual filesystem

    Added support for emulating block devices in the virtual filesystem

    Added constant for the BLOCK filetype in vfsStreamContent.

    Added new file: vfsStreamBlock

    vfsStreamBlock is an extension of vfsStreamFile to represent a block device in the virtual filesystem, much the same way block devices are actually represented.

    Added method to get a new block device in vfsStream.

    Added a case for block devices in vfsStreamAbstractVisitor.

    If there are any other requirements needed for this to be merged upstream please let us know, block device support is something that we found beneficial for our testing purposes.

    feature 
    opened by hborawski 13
  • New maintainer(s) needed

    New maintainer(s) needed

    As some might have noticed this project needs some updates to ensure it will work seemlessly with future versions of Composer and probably PHP as well. Also, there are several issues which are now open for quite some time without progess from my side. Unfortunately, I‘m lacking the time to take care of this and if I‘m honest the motivation isn‘t there either. Some have provided pull requests to tackle issues, but I‘m not comfortable simply accepting them without thinking about them properly.

    Therefore I think it‘s time to hand this project over to new maintainers. If you are interested in becoming a maintainer please comment below. To ensure the project continues properly I‘d like if suggested maintainers see support by other users of the project, e.g. by +1 their comment, so this project doesn‘t run in a situation like certain Node modules. Also, I‘d be willing to support new maintainers in case of questions regarding the project for a couple of months to make sure they get a good understanding of the project.

    If you have any other suggestions regarding the topic please feel free to comment as well.

    opened by mikey179 12
  • PHP Warning with include_path() and stream_resolve_include_path()

    PHP Warning with include_path() and stream_resolve_include_path()

    From https://code.google.com/p/bovigo/issues/detail?id=24

    What steps will reproduce the problem? To reproduce it, Ive use the interactive console (php -a)

    php > require 'vfsStream.php';
    php > vfsStreamWrapper::register();
    php > mkdir('vfs://just/a/path',0777,true);
    php > set_include_path('vfs://just/a');
    php > $a = stream_resolve_include_path('path/unknownFile.php');
    PHP Warning:   No such file or directory in .../vfsStreamWrapper.php on line 658
    PHP Stack trace:
    PHP   1. {main}() php shell code:0
    PHP   2. stream_resolve_include_path() php shell code:1
    PHP   3. vfsStreamWrapper->url_stat() .../vfsStreamWrapper.php:0
    PHP   4. trigger_error() .../vfsStreamWrapper.php:658
    

    What version of the product are you using? On what operating system? Version 0.8.0 (from SVN) with PHP5.3 on Ubuntu 10.10

    Please provide any additional information below. Maybe this has something to do with #3?

    bug 
    opened by mikey179 11
  • Mock fopen failure, closes #155

    Mock fopen failure, closes #155

    Feature to test fopen() error cases, to simulate race conditions on fopen() that is when a readable file becomes unreadable on fopen() instantly, for example to simulate a file-system failure.

    opened by ktomk 10
  • https://github.com/mikey179/vfsStream/issues/40

    https://github.com/mikey179/vfsStream/issues/40

    Proposition of proper flock implementation in vfsStream. Things done:

    • each flock call should firstly release lock for current handler, so operations on just one file handler should be always successful
    • file with exclusive lock on one handler can't be exclusively locked on other file handler
    • file with shared lock on one handler can't be exclusively locked on other file handler
    • file with exclusive lock on one handler can't be shared locked on other file handler
    • you can make multiple shared locks using multiple file handlers
    • added some additional tests
    opened by arvenil 10
  • vfsStream::create() removes old structure

    vfsStream::create() removes old structure

    When using vfsStream::create(), the VFS is re-initialized each time. This is IMHO unexpected behaviour, as "create" is related to creating directories and files, not setting up the whole filesystem.

    I propose to add a check to create() if the VFS has been set up, and then re-use that root, otherwise initialize it as it is currently.

    bug feature 
    opened by andreaswolf 9
  • vfsStream+curl bug on Windows PHP (XAMPP)

    vfsStream+curl bug on Windows PHP (XAMPP)

    I'm using PHP Unit in Windows If you try to mock the file system with vfsStream and open the mocked file with curl you get an error cannot represent a stream of type user-space as a STDIO FILE* In Linux everything is ok.

    Tested with PHP 5.6.30

    opened by Arzerilla 8
  • Failing is_writable() on a directory with PHP 7.0

    Failing is_writable() on a directory with PHP 7.0

    A testcase which works fine with for example php 5.6.x fails under php 7.0. is_writable() for a directory returns false for some reason. Doing a stat() on that directory returns the attached values. I expected that for example mode might be set wrong - but that imho looks okay as well.

    array(26) { [0]=> int(0) [1]=> int(0) [2]=> int(16893) [3]=> int(0) [4]=> int(0) [5]=> int(0) [6]=> int(0) [7]=> int(0) [8]=> int(1449405664) [9]=> int(1449405664) [10]=> int(1449405664) [11]=> int(-1) [12]=> int(-1) ["dev"]=> int(0) ["ino"]=> int(0) ["mode"]=> int(16893) ["nlink"]=> int(0) ["uid"]=> int(0) ["gid"]=> int(0) ["rdev"]=> int(0) ["size"]=> int(0) ["atime"]=> int(1449405664) ["mtime"]=> int(1449405664) ["ctime"]=> int(1449405664) ["blksize"]=> int(-1) ["blocks"]=> int(-1) }

    Just to mention it: I'm using vfsStream 1.6.1. I saw there were some fixes lately.

    opened by neufeind 8
  • Implement locking meachanism for files

    Implement locking meachanism for files

    From https://code.google.com/p/bovigo/issues/detail?id=25

    It would be nice if a vfsStreamFile object can lock itself. With this feature it would be possible to test if a file is locked or not. The PHP stream API supports the method stream_lock, but this isn't implemented yet(in vfsStream).

    http://php.net/manual/de/streamwrapper.stream-lock.php

    feature 
    opened by mikey179 8
  • Possible 1.6.7 Release

    Possible 1.6.7 Release

    Since I think 2.0 is still a bit away judging by #181, should there be another 1.6.x release with at least the 7.4 compat changes that were made recently?

    Is there anything else we'd like to backport from the master branch?

    /cc @bovigo/vfsstream

    feedback required 
    opened by allejo 7
  • Best practices: using vfsStream methods vs native filesystem methods

    Best practices: using vfsStream methods vs native filesystem methods

    All of the documentation and reference implementations I can find (e.g. Drupal's core tests) use vfsStream methods extensively to mock test fixtures.

    But given that the whole point of this library is to mock a functional filesystem, shouldn't best practice be to use native filesystem methods when mocking fixtures? This decouples the choice of filesystem (real, vfs, or something else) from the business logic of fixture setup and is a heck of a lot more concise. For instance:

    // Using vfsStream methods.
    $root = vfsStream::setup();
    vfsStream::newFile('acquia-pipelines.yml')
      ->at($root)
      ->withContent(file_get_contents('acquia-pipelines.yml'));
    
    // Using native filesystem methods.
    $root = vfsStream::setup();
    copy('acquia-pipelines.yml', $root->url());
    

    These seem functionally identical to me, except the latter is a lot more concise and easier to maintain. Is there any reason one should prefer using vfsStream methods?

    opened by danepowell 2
  • touch() ignores permissions of existing objects

    touch() ignores permissions of existing objects

    touch() checks permissions only when it creates a new file (see also #107). Touching an existing object succeeds even when its permissions should not allow to:

    $root = vfsStream::setup('root');
    $file = vfsStream::newFile('test', 0)->at($root);
    var_dump(touch($file->url())); // Should be FALSE and issue a warning, but actually succeeds
    

    vfsStreamWrapper::stream_metadata() does not implement any permission checks.

    opened by hschletz 0
  • Bump actions/cache from 2 to 3.0.11

    Bump actions/cache from 2 to 3.0.11

    Bumps actions/cache from 2 to 3.0.11.

    Release notes

    Sourced from actions/cache's releases.

    v3.0.11

    What's Changed

    New Contributors

    Full Changelog: https://github.com/actions/cache/compare/v3...v3.0.11

    v3.0.10

    • Fix a bug with sorting inputs.
    • Update definition for restore-keys in README.md

    v3.0.9

    • Enhanced the warning message for cache unavailability in case of GHES.

    v3.0.8

    What's Changed

    • Fix zstd not working for windows on gnu tar in issues.
    • Allow users to provide a custom timeout as input for aborting cache segment download using the environment variable SEGMENT_DOWNLOAD_TIMEOUT_MIN. Default is 60 minutes.

    v3.0.7

    What's Changed

    • Fix for the download stuck problem has been added in actions/cache for users who were intermittently facing the issue. As part of this fix, new timeout has been introduced in the download step to stop the download if it doesn't complete within an hour and run the rest of the workflow without erroring out.

    v3.0.6

    What's Changed

    • Add example for clojure lein project dependencies by @​shivamarora1 in PR actions/cache#835
    • Update toolkit's cache npm module to latest. Bump cache version to v3.0.6 by @​pdotl in PR actions/cache#887
    • Fix issue #809 where cache save/restore was failing for Amazon Linux 2 runners due to older tar version
    • Fix issue #833 where cache save was not working for caching github workspace directory

    New Contributors

    Full Changelog: https://github.com/actions/cache/compare/v3...v3.0.6

    v3.0.5

    Removed error handling by consuming actions/cache 3.0 toolkit, Now cache server error handling will be done by toolkit.

    v3.0.4

    In this release, we have fixed the tar creation error while trying to create it with path as ~/ home folder on ubuntu-latest.

    v3.0.3

    Fixed avoiding empty cache save when no files are available for caching. (actions/cache#624)

    v3.0.2

    ... (truncated)

    Changelog

    Sourced from actions/cache's changelog.

    3.0.11

    • Update toolkit version to 3.0.5 to include @actions/core@^1.10.0
    • Update @actions/cache to use updated saveState and setOutput functions from @actions/core@^1.10.0
    Commits
    • 9b0c1fc Merge pull request #956 from actions/pdotl-version-bump
    • 18103f6 Fix licensed status error
    • 3e383cd Update RELEASES
    • 43428ea toolkit versioon update and version bump for cache
    • 1c73980 3.0.11
    • a3f5edc Merge pull request #950 from rentziass/rentziass/update-actions-core
    • 831ee69 Update licenses
    • b9c8bfe Update @​actions/core to 1.10.0
    • 0f20846 Merge pull request #946 from actions/Phantsure-patch-2
    • 862fc14 Update README.md
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 0
  • Bump actions/checkout from 2 to 3.1.0

    Bump actions/checkout from 2 to 3.1.0

    Bumps actions/checkout from 2 to 3.1.0.

    Release notes

    Sourced from actions/checkout's releases.

    v3.1.0

    What's Changed

    New Contributors

    Full Changelog: https://github.com/actions/checkout/compare/v3.0.2...v3.1.0

    v3.0.2

    What's Changed

    Full Changelog: https://github.com/actions/checkout/compare/v3...v3.0.2

    v3.0.1

    v3.0.0

    • Updated to the node16 runtime by default
      • This requires a minimum Actions Runner version of v2.285.0 to run, which is by default available in GHES 3.4 or later.

    v2.4.2

    What's Changed

    Full Changelog: https://github.com/actions/checkout/compare/v2...v2.4.2

    v2.4.1

    • Fixed an issue where checkout failed to run in container jobs due to the new git setting safe.directory

    v2.4.0

    • Convert SSH URLs like org-<ORG_ID>@github.com: to https://github.com/ - pr

    v2.3.5

    Update dependencies

    v2.3.4

    v2.3.3

    ... (truncated)

    Changelog

    Sourced from actions/checkout's changelog.

    v3.1.0

    v3.0.2

    v3.0.1

    v3.0.0

    v2.3.1

    v2.3.0

    v2.2.0

    v2.1.1

    • Changes to support GHES (here and here)

    v2.1.0

    v2.0.0

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies github_actions 
    opened by dependabot[bot] 0
  • Allow for custom directory separators

    Allow for custom directory separators

    Given that the file system is virtual, and as I understand fairly independent of the underlying system, it would seam it's possible to set a custom directory separator.

    I have a usecase.

    I develop an application that's supposed to work both on windows and Unix, so I need to write tests for / as separator and \ as well. In order to test it, I run two docker containers, one based on debian, one on windows.

    If vfsStream supported both kinds of separators, I could test all my code without need for docker at all.

    opened by Danon 2
  • PHP 8.2 Support - track issues here

    PHP 8.2 Support - track issues here

    Welp, here we go again! The v1.6.x-dev version available via Composer now has support for PHP 8.2 nightly (which is currently in development). We have added PHP 8.2 to our CI testing on the v1.6 branch and will maybe keep things functional while 8.2 is in development. Once PHP 8.2 hits RC status, then we'll work on fixing any remaining issues before the final release.

    If you're developing for PHP 8.2 and run into issues with vfsStream, report them here!

    As always, thank you for streaming with vfsStream 📂

    opened by allejo 7
Releases(v1.6.11)
  • v1.6.11(Jul 26, 2022)

  • v1.6.11-alpha.0(Jul 19, 2022)

  • v1.6.10(Sep 25, 2021)

    This is a maintenance release adding support for PHP 8.1.

    • Fix PHP 8.1 deprecation warnings affecting the following (#258, #259):
      • vfsStreamContainerIterator::current()
      • vfsStreamContainerIterator::next()
      • vfsStreamContainerIterator::key()
      • vfsStreamContainerIterator::rewind()
      • vfsStreamDirectory::getIterator()
      • vfsStreamPrintVisitor::printContent()
    Source code(tar.gz)
    Source code(zip)
  • v1.6.10-alpha.0(Aug 2, 2021)

  • v1.6.9(Jul 16, 2021)

    • Fix deprecation warning on StringBasedFileContent for PHP 8.1 (#252)
    • Fix return type for FileContent::write(), SeekableFileContent::write(), and vfsStreamFile::write() to fix static analysis tools
    Source code(tar.gz)
    Source code(zip)
  • v1.6.8(Oct 30, 2019)

  • v1.6.7(Aug 1, 2019)

  • v1.6.6(Apr 8, 2019)

  • v1.6.5(Aug 1, 2017)

    • fixed #157 seeking before beginning of file should fail, reported and fixed by @merijnvdk
    • structure array in vfsStream::create() and vfsStream::setup() now can contain instances of org\bovigo\vfs\content\FileContent and org\bovigo\vfs\vfsStreamFile, patch provided by Joshua Smith (@jsmitty12)
    Source code(tar.gz)
    Source code(zip)
  • v1.6.4(Jul 18, 2016)

  • v1.6.3(Jul 18, 2016)

  • v1.6.2(Jan 13, 2016)

  • v1.6.1(Jan 11, 2016)

    • vfsStream::url() didn't urlencode single path parts while vfsStream::path() did urldecode them
    • fixed #120, #122: create directory with trailing slash results in "Uninitialized string offset: 0"
    Source code(tar.gz)
    Source code(zip)
  • v1.6.0(Oct 6, 2015)

    • added vfsStreamWrapper::unregister(), provided by @malkusch with #114
    • fixed #115: incorrect handling of .. in root directory on PHP 5.5, fix provided by @acoulton with #116
    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Sep 14, 2014)

Owner
null
SimpleTest is a framework for unit testing, web site testing and mock objects for PHP

SimpleTest SimpleTest is a framework for unit testing, web site testing and mock objects for PHP. Installation Downloads All downloads are stored on G

SimpleTest 147 Jun 20, 2022
Mockery - Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library

Mockery Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its c

Mockery 10.3k Jan 1, 2023
Mock HTTP requests on the server side in your PHP unit tests

HTTP Mock for PHP Mock HTTP requests on the server side in your PHP unit tests. HTTP Mock for PHP mocks the server side of an HTTP request to allow in

InterNations GmbH 386 Dec 27, 2022
PHP Test Generator - A CLI tool which generates unit tests

This project make usages of PHPStan and PHPParser to generate test cases for a given PHP File.

Alexander Schranz 7 Dec 3, 2022
Mock implementation of the Translation package, for testing with PHPUnit

PoP Translation - Mock Mock implementation of the Translation package, for testing with PHPUnit Install Via Composer composer require getpop/translati

PoP 1 Jan 13, 2022
Provides generic data providers for use with phpunit/phpunit.

data-provider Installation Run composer require --dev ergebnis/data-provider Usage This package provides the following generic data providers: Ergebni

null 25 Jan 2, 2023
Qase-phpunit - Qase TMS PHPUnit reporter.

Qase TMS PHPUnit reporter Publish results simple and easy. How to integrate composer require qase/phpunit-reporter Example of usage The PHPUnit report

Qase TMS 6 Nov 24, 2022
Learn unit testing with PHPUnit.

PHPUnit Exercise Running PHPUnit ./vendor/bin/phpunit # with filter which tests to run ./vendor/bin/phpunit --filter <pattern> Running Pint ./vendor/

Nopal 2 Aug 23, 2022
Report high memory usage PHPUnit tests: Managed by opg-org-infra & Terraform

phpunit-memory-usage Report high memory usage PHPUnit tests: Managed by opg-org-infra & Terraform Configuration Add into the phpunit.xml extensions se

Ministry of Justice 2 Aug 4, 2022
Satisfy the Type APIs for the WordPress schema when running PHPUnit tests

Satisfy the Type APIs for the WordPress schema when running PHPUnit tests

GraphQL API 1 Apr 12, 2022
Real-world Project to learning about Unit Testing/TDD with Laravel for everybody

KivaNote - a Laravel TDD Sample Project Let me introduce you to KivaNote, a simple real-world application using Laravel to show you how the TDD & Unit

(Seth) Phat Tran 10 Dec 31, 2022
To run time/IO related unit tests (e.g., sleep function calls, database queries, API calls, etc) faster using Swoole.

To run time/IO related unit tests (e.g., sleep function calls, database queries, API calls, etc) faster using Swoole.

Demin Yin 11 Sep 9, 2022
A sample RESTful API in Laravel with PHPunit test.

Laravel PHP Framework URL | URI | Action |

Fasil 9 Jul 11, 2020
PHPUnit Application Architecture Test

PHPUnit Application Architecture Test Idea: write architecture tests as well as feature and unit tests Installation Install via composer composer requ

null 19 Dec 11, 2022
A set of helpful assertions when testing Laravel applications.

Installation composer require amirrezam75/laravel-assertions I was working on a project and in order to test oauth2 redirection, I ended up with somet

Amir Reza Mehrbakhsh 2 Sep 23, 2022
Magic Test allows you to write browser tests by simply clicking around on the application being tested, all without the slowness of constantly restarting the testing environment.

Magic Test for Laravel Magic Test allows you to write browser tests by simply clicking around on the application being tested, all without the slownes

null 400 Jan 5, 2023
Prevent none-test output in your Pest tests.

Pest Plugin Silence Often, when writing tests, we echo and dump test code to debug and check everything is working correctly. It can be easy to forget

Worksome 5 Feb 23, 2022
Mock built-in PHP functions (e.g. time(), exec() or rand())

PHP-Mock: mocking built-in PHP functions PHP-Mock is a testing library which mocks non deterministic built-in PHP functions like time() or rand(). Thi

null 331 Jan 3, 2023
A simple way to mock a client

Mocked Client A simple way to mock a client Install Via Composer $ composer require doppiogancio/mocked-client guzzlehttp/guzzle php-http/discovery No

Fabrizio Gargiulo 17 Oct 5, 2022