vfs-stream

PHPUnit: How do I mock this file system?

南笙酒味 提交于 2020-01-01 08:33:04
问题 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 Exception("mkdir() failed."); } // create a file in that folder $myFile = fopen("$path/myFile.txt", "w"); if(!$myFile) { throw new Exception("Cannot open file handle."); } } } Right, so what's the problem? Code coverage reports that this line is not covered: throw new Exception("Cannot

PHPUnit: How do I mock this file system?

非 Y 不嫁゛ 提交于 2020-01-01 08:32:42
问题 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 Exception("mkdir() failed."); } // create a file in that folder $myFile = fopen("$path/myFile.txt", "w"); if(!$myFile) { throw new Exception("Cannot open file handle."); } } } Right, so what's the problem? Code coverage reports that this line is not covered: throw new Exception("Cannot

Trying to test filesystem operations with VFSStream

左心房为你撑大大i 提交于 2019-12-08 18:09:18
问题 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 RequestBody implements iface\request\RequestBody { const REQ_PATH = 'php://input', protected $requestHandle = false; /** * Obtain a handle to the request body * * @return resource a file pointer resource on success, or <b>FALSE</b> on error. */ protected

PHPUnit: How do I mock this file system?

喜你入骨 提交于 2019-12-04 01:18:19
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 Exception("mkdir() failed."); } // create a file in that folder $myFile = fopen("$path/myFile.txt", "w"); if(!$myFile) { throw new Exception("Cannot open file handle."); } } } Right, so what's the problem? Code coverage reports that this line is not covered: throw new Exception("Cannot open file handle."); Which is correct, but since I'm creating the folder above logically it would seem