Coder Social home page Coder Social logo

Comments (11)

mikey179 avatar mikey179 commented on August 19, 2024

The problem here is the issued warning, when stream_resolve_include_path() should not result in a warning, but silently return false instead.

from vfsstream.

mikey179 avatar mikey179 commented on August 19, 2024

After further investigation I believe it's not a bug with vfsStream, but with PHP calling vfsStream's url_stat() method with a wrong value for $flags, therefore vfsStream does not know it must not issue a warning.

However, I'm a bit unsure that I got the bit operations right.

from vfsstream.

mikey179 avatar mikey179 commented on August 19, 2024

Added a test case. It seems stream_resolve_include_path() might not call url_stat() correctly. Needs to be clarified with PHP core.

from vfsstream.

larsnystrom avatar larsnystrom commented on August 19, 2024

I have the same problem where stream_resolve_include_path() returns false for vfs:// urls, even though it works fine to fopen() them. Did you file a bug report with PHP core?

from vfsstream.

mikey179 avatar mikey179 commented on August 19, 2024

No, I didn't, as nobody had an issue with that again. Also, the bug report would have been about the missing flag in the call to the vfsStream method. In your case I suspect there must be something else, as stream_resolve_include_path() should work just fine when the file exists, see f780403#diff-727ee525c70e3fbdc1c65e385ed866d3R56

from vfsstream.

larsnystrom avatar larsnystrom commented on August 19, 2024

I'm not sure if it's an edge case, but zendframework/zend-validator uses stream_resolve_include_path to check if a file exists, see zendframework/zend-validator#77. stream_resolve_include_path will return something !== false when the file exists, but that doesn't seem to work with vfsStream.

To reproduce:

$vfs = org\bovigo\vfs\vfsStream::setup('root', null, ['file' => 'content']);
$file = $vfs->getChild('file');

// echoes bool(false) but should be the path to the file.
var_dump(stream_resolve_include_path($file->url()));

Compare that to:

touch(getcwd() . "/test.tmp");
// echoes /path/to/test.tmp
var_dump(stream_resolve_include_path(getcwd() . "/test.tmp"));

from vfsstream.

mikey179 avatar mikey179 commented on August 19, 2024

In your example you don't add the vfsStream path vfs://root to PHP's include_path, whereas the current working directory usually is added to it automatically by PHP. If you add the vfsStream path to the include path as can be seen in the test I linked to it should be resolved correctly.

from vfsstream.

larsnystrom avatar larsnystrom commented on August 19, 2024

Any absolute path to an existing file is resolved by stream_resolve_include_path, not just those in the include path. The problem is that it cannot resolve "absolute" vfs:// urls.

For example, the zend validator relies on the fact that any absolute path to an existing file will return something !== false. However, when given a vfs:// "absolute url" stream_resolve_include_path returns false.

from vfsstream.

mikey179 avatar mikey179 commented on August 19, 2024

Ah, didn't know about that. Just tested, vfsStream doesn't even get called when an absolute vfsStream path is used with stream_resolve_include_path. So there's nothing that it can do about it - but if it would be called it should work out of the box as vfsStream's url_stat method would return the correct information.

from vfsstream.

paul-m avatar paul-m commented on August 19, 2024
<?php

require_once __DIR__ . '/../vendor/autoload.php';

use org\bovigo\vfs\vfsStream;

$vfs = vfsStream::setup('root');
vfsStream::create(['Hi.php' => '<?php // stuff.'], $vfs);

// checkAndLoad() calls stream_resolve_include_path(). Explosion happens here:
\PHPUnit_Util_Fileloader::checkAndLoad(vfsStream::url('root/Hi.php'));

// [24-Jun-2016 05:38:20 Europe/Berlin] PHP Fatal error:  Uncaught PHPUnit_Framework_Exception:
// Cannot open file "vfs://root/Hi.php".

Here's another example. I'm trying to write a PHPUnit test suite loader, and also test the loader. The whole thing is stream safe and can thus be mocked with vfsStream, except for stream_resolve_include_path().

This is where I'm working if you're curious: https://www.drupal.org/node/2499239

from vfsstream.

mikey179 avatar mikey179 commented on August 19, 2024

As noted above, there is nothing that vfsStream can do about. I added a remark on this in the list of known issues. If someone wants to make it work please submit a feature/pull request to PHP core - personally I don't have any deeper interest in that, so I won't take care of that.

from vfsstream.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.