Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests.
PHP-VCR | Record HTTP interactions while testing
Is there a reason why a call to stat
would throw a RuntimeException
? This is during testing with phpunit, using CakePHP and PHP-VCR. The call to stat includes the error control operator, @. So it's:
The error occurs in the PHP-VCR code (StreamProcessor.php line 291).
try {
$result = @stat($path);
} catch (\RuntimeException $e) {
error_log(print_r($e, true));
}
'type' => (int) 2,
'message' => 'stat(): stat failed for /x/y/z/mycakephpprojet/app/tmp/cache/persistent/myapp_cake_core_cake_eng',
'file' => '/x/y/z/mycakephpprojet/app/Vendor/php-vcr/php-vcr/src/VCR/Util/StreamProcessor.php',
'line' => (int) 291
What I know is that the referenced file is missing (it's a cache file that is generated at some point later). So I'd expect stat to return false, not throw an exception.
Notes:
- I was thinking perhaps it's thrown by some custom handler of a composer package (like phpunit). However,
error_reporting()
reports 24575, where I'd expect it to be 0 because of the @ error control operator. Also, I looked through all the set_error_handler
calls and even put debug calls in those and I'm sure it's not from them.
The stack trace from the exception object has the most recent line as
'#0 [internal function]: VCR\Util\StreamProcessor->url_stat('/home/tylercoll...', 2)
so I don't feel like there's another level that I could possibly intercept to inspect.
- Oddly, the RuntimeException that's thrown cannot be handled with my own custom
set_exception_handler
. But if I manually use throw new \RuntimeException
, my custom handler will be used.
- ONE time the exception type was
PHPUnit_Framework_Error_Warning
. I'm 99% positive that I ran it again immediately and it's been RuntimeException since then. But the warning would make sense given that the error's type is reported as 2 (aka E_WARNING).
- One of the reasons I think it's something to do with PHP is because if I remove the @ error control operator, I get many WARNINGs (not exceptions) saying stat failed. However, this I'm pretty sure is from the CakePHP test harness because after many of those go by, then I see
PHPUnit 3.7.37 by Sebastian Bergmann. Configuration read from phpunit.xml
. And then the failure is after that.
- I'm on Ubuntu 12.04 with PHP 5.4.23.
Source: (StackOverflow)