diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9eff67636..1c7529959 100755 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] + php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6'] os: [ubuntu-latest, windows-latest] steps: diff --git a/src/main/php/io/File.class.php b/src/main/php/io/File.class.php index 5b6b04b94..1a7697132 100755 --- a/src/main/php/io/File.class.php +++ b/src/main/php/io/File.class.php @@ -132,8 +132,8 @@ public function setURI($uri) { * * @param string mode one of the File::* constants * @return self - * @throws io.FileNotFoundException in case the file is not found - * @throws io.IOException in case the file cannot be opened (e.g., lacking permissions) + * @throws io.NotFound in case the file is not found + * @throws io.OperationFailed in case the file cannot be opened (e.g., lacking permissions) */ public function open($mode= self::READ): self { $this->mode= $mode; @@ -141,12 +141,12 @@ public function open($mode= self::READ): self { self::READ === $mode && 0 !== strncmp('php://', $this->uri, 6) && !$this->exists() - ) throw new FileNotFoundException('File "'.$this->uri.'" not found'); + ) throw new NotFound('File "'.$this->uri.'" not found'); $this->_fd= fopen($this->uri, $this->mode); if (!$this->_fd) { $this->_fd= null; - $e= new IOException('Cannot open '.$this->uri.' mode '.$this->mode); + $e= new OperationFailed('Cannot open '.$this->uri.' mode '.$this->mode); \xp::gc(__FILE__); throw $e; } @@ -164,11 +164,11 @@ public function exists(): bool { return file_exists($this->uri); } * Retrieve the file's size in bytes * * @return int size filesize in bytes - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function size(): int { if (false === ($stat= $this->_fd ? fstat($this->_fd) : stat($this->uri))) { - $e= new IOException('Cannot get filesize for '.$this->uri); + $e= new OperationFailed('Cannot get filesize for '.$this->uri); \xp::gc(__FILE__); throw $e; } @@ -180,11 +180,11 @@ public function size(): int { * * @param int $size Default 0 * @return bool - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function truncate(int $size= 0): bool { if (null === $this->_fd) { - throw new IOException('Cannot truncate file '.$this->uri); + throw new OperationFailed('Cannot truncate file '.$this->uri); } // OS vagaries: Windows does not retain file position! @@ -197,7 +197,7 @@ public function truncate(int $size= 0): bool { } if (false === $return) { - $e= new IOException('Cannot truncate file '.$this->uri); + $e= new OperationFailed('Cannot truncate file '.$this->uri); \xp::gc(__FILE__); throw $e; } @@ -216,11 +216,11 @@ public function truncate(int $size= 0): bool { * On such filesystems this function will be useless. * * @return int The date the file was last accessed as a unix-timestamp - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function lastAccessed() { if (false === ($atime= fileatime($this->uri))) { - $e= new IOException('Cannot get atime for '.$this->uri); + $e= new OperationFailed('Cannot get atime for '.$this->uri); \xp::gc(__FILE__); throw $e; } @@ -231,11 +231,11 @@ public function lastAccessed() { * Retrieve last modification time * * @return int The date the file was last modified as a unix-timestamp - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function lastModified() { if (false === ($mtime= filemtime($this->uri))) { - $e= new IOException('Cannot get mtime for '.$this->uri); + $e= new OperationFailed('Cannot get mtime for '.$this->uri); \xp::gc(__FILE__); throw $e; } @@ -247,12 +247,12 @@ public function lastModified() { * * @param int time default -1 Unix-timestamp * @return bool success - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function touch($time= -1) { if (-1 == $time) $time= time(); if (false === touch($this->uri, $time)) { - $e= new IOException('Cannot set mtime for '.$this->uri); + $e= new OperationFailed('Cannot set mtime for '.$this->uri); \xp::gc(__FILE__); throw $e; } @@ -263,11 +263,11 @@ public function touch($time= -1) { * Retrieve when the file was created * * @return int The date the file was created as a unix-timestamp - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function createdAt() { if (false === ($mtime= filectime($this->uri))) { - $e= new IOException('Cannot get mtime for '.$this->uri); + $e= new OperationFailed('Cannot get mtime for '.$this->uri); \xp::gc(__FILE__); throw $e; } @@ -283,7 +283,7 @@ public function createdAt() { * * @param int bytes default 4096 Max. amount of bytes to be read * @return string Data read - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function readLine($bytes= 4096) { $bytes= $this->gets($bytes); @@ -294,11 +294,11 @@ public function readLine($bytes= 4096) { * Read one char * * @return string the character read - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function readChar() { if (null === $this->_fd || false === ($result= fgetc($this->_fd)) && !feof($this->_fd)) { - $e= new IOException('Cannot read 1 byte from '.$this->uri); + $e= new OperationFailed('Cannot read 1 byte from '.$this->uri); \xp::gc(__FILE__); throw $e; } @@ -313,12 +313,12 @@ public function readChar() { * * @param int bytes default 4096 Max. amount of bytes to read * @return string Data read - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function gets($bytes= 4096) { if (0 === $bytes) return ''; if (null === $this->_fd || false === ($result= fgets($this->_fd, $bytes)) && !feof($this->_fd)) { - $e= new IOException('Cannot read '.$bytes.' bytes from '.$this->uri); + $e= new OperationFailed('Cannot read '.$bytes.' bytes from '.$this->uri); \xp::gc(__FILE__); throw $e; } @@ -330,12 +330,12 @@ public function gets($bytes= 4096) { * * @param int bytes default 4096 Max. amount of bytes to read * @return string Data read - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function read($bytes= 4096) { if (0 === $bytes) return ''; if (null === $this->_fd || false === ($result= fread($this->_fd, $bytes)) && !feof($this->_fd)) { - $e= new IOException('Cannot read '.$bytes.' bytes from '.$this->uri); + $e= new OperationFailed('Cannot read '.$bytes.' bytes from '.$this->uri); \xp::gc(__FILE__); throw $e; } @@ -347,11 +347,11 @@ public function read($bytes= 4096) { * * @param string string data to write * @return int number of bytes written - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function write($string) { if (null === $this->_fd || false === ($result= fwrite($this->_fd, $string))) { - $e= new IOException('Cannot write '.strlen($string).' bytes to '.$this->uri); + $e= new OperationFailed('Cannot write '.strlen($string).' bytes to '.$this->uri); \xp::gc(__FILE__); throw $e; } @@ -363,11 +363,11 @@ public function write($string) { * * @param string string data default '' to write * @return int number of bytes written - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function writeLine($string= '') { if (null === $this->_fd || false === ($result= fwrite($this->_fd, $string."\n"))) { - $e= new IOException('Cannot write '.(strlen($string)+ 1).' bytes to '.$this->uri); + $e= new OperationFailed('Cannot write '.(strlen($string)+ 1).' bytes to '.$this->uri); \xp::gc(__FILE__); throw $e; } @@ -382,12 +382,12 @@ public function writeLine($string= '') { * * @see php://feof * @return bool TRUE when the end of the file is reached - * @throws io.IOException in case of an error (e.g., the file's not been opened) + * @throws io.OperationFailed in case of an error (e.g., the file's not been opened) */ public function eof() { $result= feof($this->_fd); if (isset(\xp::$errors[__FILE__][__LINE__ - 1])) { - $e= new IOException('Cannot determine eof of '.$this->uri); + $e= new OperationFailed('Cannot determine eof of '.$this->uri); \xp::gc(__FILE__); throw $e; } @@ -401,11 +401,11 @@ public function eof() { * This function is identical to a call of $f->seek(0, SEEK_SET) * * @return bool TRUE if rewind suceeded - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function rewind() { if (null === $this->_fd || false === ($result= rewind($this->_fd))) { - $e= new IOException('Cannot rewind file pointer'); + $e= new OperationFailed('Cannot rewind file pointer'); \xp::gc(__FILE__); throw $e; } @@ -418,12 +418,12 @@ public function rewind() { * @param int position default 0 The new position * @param int mode default SEEK_SET * @see php://fseek - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error * @return bool success */ public function seek($position= 0, $mode= SEEK_SET) { if (null === $this->_fd || 0 != ($result= fseek($this->_fd, $position, $mode))) { - $e= new IOException('Seek error, position '.$position.' in mode '.$mode); + $e= new OperationFailed('Seek error, position '.$position.' in mode '.$mode); \xp::gc(__FILE__); throw $e; } @@ -434,11 +434,11 @@ public function seek($position= 0, $mode= SEEK_SET) { * Retrieve file pointer position * * @return int position - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function tell() { if (null === $this->_fd || false === ($result= ftell($this->_fd))) { - $e= new IOException('Cannot retrieve file pointer\'s position'); + $e= new OperationFailed('Cannot retrieve file pointer\'s position'); \xp::gc(__FILE__); throw $e; } @@ -462,7 +462,7 @@ public function tell() { * errno condition). * * @param int op operation (one of the predefined LOCK_* constants) - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error * @return bool success * @see php://flock */ @@ -480,7 +480,7 @@ protected function _lock($mode) { $mode-= $o; } } - $e= new IOException('Cannot lock file '.$this->uri.' w/ '.substr($os, 3)); + $e= new OperationFailed('Cannot lock file '.$this->uri.' w/ '.substr($os, 3)); \xp::gc(__FILE__); throw $e; } @@ -524,14 +524,14 @@ public function unLock() { * Close this file * * @return bool success - * @throws io.IOException if close fails + * @throws io.OperationFailed if close fails */ public function close() { if (!is_resource($this->_fd)) { - throw new IOException('Cannot close non-opened file '.$this->uri); + throw new OperationFailed('Cannot close non-opened file '.$this->uri); } if (false === fclose($this->_fd)) { - $e= new IOException('Cannot close file '.$this->uri); + $e= new OperationFailed('Cannot close file '.$this->uri); \xp::gc(__FILE__); throw $e; } @@ -547,7 +547,7 @@ public function close() { * close the file first * * @return bool success - * @throws io.IOException in case of an error (e.g., lack of permissions) + * @throws io.OperationFailed in case of an error (e.g., lack of permissions) * @throws lang.IllegalStateException in case the file is still open */ public function unlink() { @@ -555,7 +555,7 @@ public function unlink() { throw new IllegalStateException('File still open'); } if (false === unlink($this->uri)) { - $e= new IOException('Cannot delete file '.$this->uri); + $e= new OperationFailed('Cannot delete file '.$this->uri); \xp::gc(__FILE__); throw $e; } @@ -570,7 +570,7 @@ public function unlink() { * * @param var target where to move the file to, either a string, a File or a Folder * @return bool success - * @throws io.IOException in case of an error (e.g., lack of permissions) + * @throws io.OperationFailed in case of an error (e.g., lack of permissions) * @throws lang.IllegalStateException in case the file is still open */ public function move($target) { @@ -587,7 +587,7 @@ public function move($target) { } if (false === rename($this->uri, $uri)) { - $e= new IOException('Cannot move file '.$this->uri.' to '.$uri); + $e= new OperationFailed('Cannot move file '.$this->uri.' to '.$uri); \xp::gc(__FILE__); throw $e; } @@ -604,7 +604,7 @@ public function move($target) { * * @param var target where to copy the file to, either a string, a File or a Folder * @return bool success - * @throws io.IOException in case of an error (e.g., lack of permissions) + * @throws io.OperationFailed in case of an error (e.g., lack of permissions) * @throws lang.IllegalStateException in case the file is still open */ public function copy($target) { @@ -621,7 +621,7 @@ public function copy($target) { } if (false === copy($this->uri, $uri)) { - $e= new IOException('Cannot copy file '.$this->uri.' to '.$uri); + $e= new OperationFailed('Cannot copy file '.$this->uri.' to '.$uri); \xp::gc(__FILE__); throw $e; } diff --git a/src/main/php/io/FileNotFoundException.class.php b/src/main/php/io/FileNotFoundException.class.php index 47a8964ce..cdb988b94 100755 --- a/src/main/php/io/FileNotFoundException.class.php +++ b/src/main/php/io/FileNotFoundException.class.php @@ -2,6 +2,9 @@ /** * Indicates the file could not be found + * + * @deprecated https://github.com/xp-framework/core/issues/363 */ class FileNotFoundException extends IOException { -} + +} \ No newline at end of file diff --git a/src/main/php/io/Files.class.php b/src/main/php/io/Files.class.php index 47f6141bc..b74bdfda1 100755 --- a/src/main/php/io/Files.class.php +++ b/src/main/php/io/Files.class.php @@ -18,8 +18,8 @@ class Files { * * @param string|io.File $file * @return string file contents - * @throws io.IOException - * @throws io.FileNotFoundException + * @throws io.OperationFailed + * @throws io.NotFound */ public static function read($file) { $f= $file instanceof File ? $file : new File($file); @@ -57,7 +57,7 @@ public static function read($file) { * @param string|io.File $file * @param string $bytes * @return int - * @throws io.IOException + * @throws io.OperationFailed */ public static function write($file, $bytes) { $f= $file instanceof File ? $file : new File($file); @@ -80,7 +80,7 @@ public static function write($file, $bytes) { * @param string|io.File $file * @param string $bytes * @return int - * @throws io.IOException + * @throws io.OperationFailed */ public static function append($file, $bytes) { $f= $file instanceof File ? $file : new File($file); diff --git a/src/main/php/io/Folder.class.php b/src/main/php/io/Folder.class.php index d7c503579..b15d594a7 100755 --- a/src/main/php/io/Folder.class.php +++ b/src/main/php/io/Folder.class.php @@ -8,8 +8,8 @@ * Usage: * ``` * $d= new Folder('/etc/'); - * while (false !== ($entry= $d->getEntry())) { - * printf("%s/%s\n", $d->uri, $entry); + * foreach ($d->entries() as $entry) { + * echo $entry, "\n"; * } * $d->close(); * ``` @@ -17,12 +17,7 @@ * @test io.unittest.FolderTest */ class Folder implements Value { - public - $uri = '', - $dirname = '', - $path = ''; - - private $_hdir = false; + public $uri, $dirname, $path; /** * Constructor @@ -41,23 +36,6 @@ public function __construct($base= null, ... $args) { $this->setURI($composed.implode(DIRECTORY_SEPARATOR, $args)); } - - /** - * Destructor - */ - public function __destruct() { - $this->close(); - } - - /** - * Close directory - * - * @return void - */ - public function close() { - if (false != $this->_hdir) $this->_hdir->close(); - $this->_hdir= false; - } /** * Set URI @@ -112,11 +90,11 @@ public function getURI(): string { return $this->uri; } * * @param int permissions default 0700 * @return bool TRUE in case the creation succeeded or the directory already exists - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function create($permissions= 0700) { if ('' == (string)$this->uri) { - throw new IOException('Cannot create folder with empty name'); + throw new OperationFailed('Cannot create folder with empty name'); } // Border-case: Folder already exists @@ -128,7 +106,7 @@ public function create($permissions= 0700) { if (is_dir($d= substr($this->uri, 0, ++$i))) continue; if (false === mkdir($d, $permissions)) { umask($umask); - throw new IOException(sprintf('mkdir("%s", %d) failed', $d, $permissions)); + throw new OperationFailed(sprintf('mkdir("%s", %d) failed', $d, $permissions)); } } umask($umask); @@ -141,12 +119,12 @@ public function create($permissions= 0700) { * Warning: Stops at the first element that can't be deleted! * * @return bool success - * @throws io.IOException in case one of the entries could'nt be deleted + * @throws io.OperationFailed in case one of the entries could'nt be deleted */ public function unlink($uri= null) { $uri= null === $uri ? $this->uri : rtrim($uri, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; if (false === ($d= opendir($uri))) { - throw new IOException('Directory '.$uri.' does not exist'); + throw new OperationFailed('Directory '.$uri.' does not exist'); } while (false !== ($e= readdir($d))) { @@ -158,31 +136,24 @@ public function unlink($uri= null) { $this->unlink($fn); } else if (false === unlink($fn)) { closedir($d); - throw new IOException("Deleting '{$fn}' failed"); + throw new OperationFailed("Deleting '{$fn}' failed"); } } closedir($d); - if (false === rmdir($uri)) throw new IOException("Deleting '{$uri}' failed"); + if (false === rmdir($uri)) throw new OperationFailed("Deleting '{$uri}' failed"); return true; } /** * Move this directory * - * Warning: Open directories cannot be moved. Use the close() method to - * close the directory first - * * @return bool success - * @throws io.IOException in case of an error (e.g., lack of permissions) - * @throws lang.IllegalStateException in case the directory is still open + * @throws io.OperationFailed in case of an error (e.g., lack of permissions) */ public function move($target) { - if (is_resource($this->_hdir)) { - throw new IllegalStateException('Directory still open'); - } if (false === rename($this->uri, $target)) { - throw new IOException('Cannot move directory '.$this->uri.' to '.$target); + throw new OperationFailed('Cannot move directory '.$this->uri.' to '.$target); } return true; } @@ -197,11 +168,11 @@ public function entries(): FolderEntries { return new FolderEntries($this); } * Retrieve when the folder was created * * @return int The date the file was created as a unix-timestamp - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function createdAt() { if (false === ($mtime= filectime($this->uri))) { - throw new IOException('Cannot get mtime for '.$this->uri); + throw new OperationFailed('Cannot get mtime for '.$this->uri); } return $mtime; } @@ -218,11 +189,11 @@ public function createdAt() { * On such filesystems this function will be useless. * * @return int The date the file was last accessed as a unix-timestamp - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function lastAccessed() { if (false === ($atime= fileatime($this->uri))) { - throw new IOException('Cannot get atime for '.$this->uri); + throw new OperationFailed('Cannot get atime for '.$this->uri); } return $atime; } @@ -231,11 +202,11 @@ public function lastAccessed() { * Retrieve last modification time * * @return int The date the file was last modified as a unix-timestamp - * @throws io.IOException in case of an error + * @throws io.OperationFailed in case of an error */ public function lastModified() { if (false === ($mtime= filemtime($this->uri))) { - throw new IOException('Cannot get mtime for '.$this->uri); + throw new OperationFailed('Cannot get mtime for '.$this->uri); } return $mtime; } diff --git a/src/main/php/io/FolderEntries.class.php b/src/main/php/io/FolderEntries.class.php index c66b5bcd7..78e7c04d6 100755 --- a/src/main/php/io/FolderEntries.class.php +++ b/src/main/php/io/FolderEntries.class.php @@ -31,11 +31,20 @@ public function named(string $name): Path { return new Path($this->base, $name); } - /** Iterate over all entries */ + /** + * Iterate over all entries + * + * @throws io.NotFound + * @throws io.OperationFailed + */ public function getIterator(): Traversable { if (null === $this->handle) { - if (!is_resource($handle= opendir($this->base->asFolder()->getURI()))) { - $e= new IOException('Cannot open folder '.$this->base); + $uri= $this->base->asURI(); + if (!is_resource($handle= opendir($uri))) { + $e= file_exists($uri) + ? new OperationFailed('Cannot open folder '.$uri) + : new NotFound('Folder '.$uri.' does not exist') + ; \xp::gc(__FILE__); throw $e; } diff --git a/src/main/php/io/IOException.class.php b/src/main/php/io/IOException.class.php index 5a4265117..b0de690eb 100755 --- a/src/main/php/io/IOException.class.php +++ b/src/main/php/io/IOException.class.php @@ -3,7 +3,9 @@ /** * Signals that an I/O exception of some sort has occurred. This * class is the general class of exceptions produced by failed or - * interrupted I/O operations. + * interrupted I/O operations. + * + * @deprecated https://github.com/xp-framework/core/issues/363 */ class IOException extends \lang\XPException { diff --git a/src/main/php/io/NotFound.class.php b/src/main/php/io/NotFound.class.php new file mode 100755 index 000000000..e099ee49d --- /dev/null +++ b/src/main/php/io/NotFound.class.php @@ -0,0 +1,6 @@ +uri, $contents)) { - $e= new IOException('Cannot write to temporary file '.$this->uri); + $e= new OperationFailed('Cannot write to temporary file '.$this->uri); \xp::gc(__FILE__); throw $e; } diff --git a/src/main/php/io/TimedOut.class.php b/src/main/php/io/TimedOut.class.php new file mode 100755 index 000000000..5e8ea2ba4 --- /dev/null +++ b/src/main/php/io/TimedOut.class.php @@ -0,0 +1,6 @@ +file ? $this->file->seek($position, SEEK_SET) : $this->pointer= $position; diff --git a/src/main/php/io/streams/ChannelInputStream.class.php b/src/main/php/io/streams/ChannelInputStream.class.php index abec9b9ed..8a3cb5371 100755 --- a/src/main/php/io/streams/ChannelInputStream.class.php +++ b/src/main/php/io/streams/ChannelInputStream.class.php @@ -1,6 +1,6 @@ fd= fopen('php://'.$arg, 'rb'))) { - throw new IOException('Could not open '.$arg.' channel for reading'); + throw new OperationFailed('Could not open '.$arg.' channel for reading'); } $this->name= $arg; } else if (is_resource($arg)) { $this->fd= $arg; $this->name= '#'.(int)$arg; } else { - throw new IOException('Expecting either stdin, input or a file descriptor '.typeof($arg).' given'); + throw new OperationFailed('Expecting either stdin, input or a file descriptor '.typeof($arg).' given'); } } @@ -44,7 +44,7 @@ public function __construct($arg) { */ public function read($limit= 8192) { if (null === $this->fd || false === ($bytes= fread($this->fd, $limit))) { - $e= new IOException('Could not read '.$limit.' bytes from '.$this->name.' channel'); + $e= new OperationFailed('Could not read '.$limit.' bytes from '.$this->name.' channel'); \xp::gc(__FILE__); throw $e; } diff --git a/src/main/php/io/streams/ChannelOutputStream.class.php b/src/main/php/io/streams/ChannelOutputStream.class.php index 856737518..701c20996 100755 --- a/src/main/php/io/streams/ChannelOutputStream.class.php +++ b/src/main/php/io/streams/ChannelOutputStream.class.php @@ -1,6 +1,6 @@ fd= fopen('php://'.$arg, 'wb'))) { - throw new IOException('Could not open '.$arg.' channel for writing'); + throw new OperationFailed('Could not open '.$arg.' channel for writing'); } $this->name= $arg; } else if (is_resource($arg)) { $this->fd= $arg; $this->name= '#'.(int)$arg; } else { - throw new IOException('Expecting either stdout, stderr, output or a file descriptor '.typeof($arg).' given'); + throw new OperationFailed('Expecting either stdout, stderr, output or a file descriptor '.typeof($arg).' given'); } } @@ -43,7 +43,7 @@ public function __construct($arg) { */ public function write($arg) { if (null === $this->fd || false === fwrite($this->fd, $arg)) { - $e= new IOException('Could not write '.strlen($arg).' bytes to '.$this->name.' channel'); + $e= new OperationFailed('Could not write '.strlen($arg).' bytes to '.$this->name.' channel'); \xp::gc(__FILE__); throw $e; } diff --git a/src/main/php/io/streams/FileInputStream.class.php b/src/main/php/io/streams/FileInputStream.class.php index ee76ee87b..5aaa53cd3 100755 --- a/src/main/php/io/streams/FileInputStream.class.php +++ b/src/main/php/io/streams/FileInputStream.class.php @@ -66,7 +66,7 @@ public function toString() { * * @param int offset * @param int whence default SEEK_SET (one of SEEK_[SET|CUR|END]) - * @throws io.IOException in case of error + * @throws io.OperationFailed in case of error */ public function seek($offset, $whence= SEEK_SET) { $this->file->seek($offset, $whence); diff --git a/src/main/php/io/streams/FileOutputStream.class.php b/src/main/php/io/streams/FileOutputStream.class.php index ed1c7ac69..334ba1bba 100755 --- a/src/main/php/io/streams/FileOutputStream.class.php +++ b/src/main/php/io/streams/FileOutputStream.class.php @@ -39,7 +39,7 @@ public function write($arg) { * * @param int $offset * @param int $whence default SEEK_SET (one of SEEK_[SET|CUR|END]) - * @throws io.IOException in case of error + * @throws io.OperationFailed in case of error */ public function seek($offset, $whence= SEEK_SET) { $this->file->seek($offset, $whence); diff --git a/src/main/php/io/streams/MemoryInputStream.class.php b/src/main/php/io/streams/MemoryInputStream.class.php index b463c1945..740fce672 100755 --- a/src/main/php/io/streams/MemoryInputStream.class.php +++ b/src/main/php/io/streams/MemoryInputStream.class.php @@ -1,6 +1,6 @@ pos= $offset; break; case SEEK_CUR: $this->pos+= $offset; break; case SEEK_END: $this->pos= strlen($this->bytes) + $offset; break; - default: throw new IOException('Unexpected whence '.$whence); + default: throw new OperationFailed('Unexpected whence '.$whence); } // Ensure we cannot seek *before* start if ($this->pos < 0) { $this->pos= 0; - throw new IOException('Seek error, position '.$offset.', whence: '.$whence); + throw new OperationFailed('Seek error, position '.$offset.', whence: '.$whence); } } diff --git a/src/main/php/io/streams/MemoryOutputStream.class.php b/src/main/php/io/streams/MemoryOutputStream.class.php index d13bd4258..d1a226e5c 100755 --- a/src/main/php/io/streams/MemoryOutputStream.class.php +++ b/src/main/php/io/streams/MemoryOutputStream.class.php @@ -1,6 +1,6 @@ pos= $offset; break; case SEEK_CUR: $this->pos+= $offset; break; case SEEK_END: $this->pos= strlen($this->bytes) + $offset; break; - default: throw new IOException('Unexpected whence '.$whence); + default: throw new OperationFailed('Unexpected whence '.$whence); } // Ensure we cannot seek *before* start if ($this->pos < 0) { $this->pos= 0; - throw new IOException('Seek error, position '.$offset.', whence: '.$whence); + throw new OperationFailed('Seek error, position '.$offset.', whence: '.$whence); } } diff --git a/src/main/php/io/streams/Reader.class.php b/src/main/php/io/streams/Reader.class.php index 7301f9d16..d2bc5b5d0 100755 --- a/src/main/php/io/streams/Reader.class.php +++ b/src/main/php/io/streams/Reader.class.php @@ -1,6 +1,6 @@ stream instanceof Seekable) { @@ -73,7 +73,7 @@ public function reset() { $this->beginning= true; $this->buf= ''; } else { - throw new IOException('Underlying stream does not support seeking'); + throw new OperationFailed('Underlying stream does not support seeking'); } } diff --git a/src/main/php/io/streams/Seekable.class.php b/src/main/php/io/streams/Seekable.class.php index 35774c1c0..1e5583caa 100755 --- a/src/main/php/io/streams/Seekable.class.php +++ b/src/main/php/io/streams/Seekable.class.php @@ -12,7 +12,7 @@ interface Seekable { * * @param int offset * @param int whence default SEEK_SET (one of SEEK_[SET|CUR|END]) - * @throws io.IOException in case of error + * @throws io.OperationFailed in case of error */ public function seek($offset, $whence= SEEK_SET); diff --git a/src/main/php/io/streams/SpooledInputStream.class.php b/src/main/php/io/streams/SpooledInputStream.class.php index 1b7ac8aab..c1f208062 100755 --- a/src/main/php/io/streams/SpooledInputStream.class.php +++ b/src/main/php/io/streams/SpooledInputStream.class.php @@ -1,6 +1,6 @@ in->available()) { @@ -66,22 +66,22 @@ public function transmit() { * streams even if one of the close() calls yields an exception. * * @return void - * @throws io.IOException + * @throws io.OperationFailed */ public function close() { $errors= ''; try { $this->in->close(); - } catch (IOException $e) { + } catch (OperationFailed $e) { $errors.= 'Could not close input stream: '.$e->getMessage().', '; } try { $this->out->close(); - } catch (IOException $e) { + } catch (OperationFailed $e) { $errors.= 'Could not close output stream: '.$e->getMessage().', '; } if ($errors) { - throw new IOException(rtrim($errors, ', ')); + throw new OperationFailed(rtrim($errors, ', ')); } } diff --git a/src/main/php/io/streams/Streams.class.php b/src/main/php/io/streams/Streams.class.php index 95037367c..3d6fbaee7 100755 --- a/src/main/php/io/streams/Streams.class.php +++ b/src/main/php/io/streams/Streams.class.php @@ -1,6 +1,6 @@ id]->truncate($size); return true; } - throw new IOException('Cannot truncate underlying stream'); + throw new NotSupported('Cannot truncate underlying stream'); } public function stream_read($count) { - throw new IOException('Cannot read from writeable stream'); + throw new NotSupported('Cannot read from writeable stream'); } public function stream_flush() { @@ -125,7 +125,7 @@ public static function writeableUri(OutputStream $s) { * * @param io.streams.InputStream $s * @return string - * @throws io.IOException + * @throws io.OperationFailed */ public static function readAll(InputStream $s) { $r= ''; @@ -140,14 +140,14 @@ public static function readAll(InputStream $s) { * @param int $offset * @param int $whence default SEEK_SET (one of SEEK_[SET|CUR|END]) * @return void - * @throws io.IOException - * @throws io.OperationNotSupportedException + * @throws io.OperationFailed + * @throws io.NotSupported */ public static function seek(InputStream $s, $offset, $whence= SEEK_SET) { if ($s instanceof Seekable) { $s->seek($offset, $whence); } else { - throw new OperationNotSupportedException('Cannot seek instances of '.nameof($s)); + throw new NotSupported('Cannot seek instances of '.nameof($s)); } } @@ -158,12 +158,12 @@ public static function seek(InputStream $s, $offset, $whence= SEEK_SET) { * @param string mode * @param int options * @param string opened_path - * @throws io.FileNotFoundException in case the given file cannot be found + * @throws io.NotFound in case the given file cannot be found */ public function stream_open($path, $mode, $options, $opened_path) { sscanf(urldecode($path), "iostr%c://%[^$]", $m, $this->id); if (!isset(self::$streams[$this->id])) { - throw new FileNotFoundException('Cannot open stream "'.$this->id.'" mode '.$mode); + throw new NotFound('Cannot open stream "'.$this->id.'" mode '.$mode); } return true; } @@ -190,7 +190,7 @@ public function stream_close() { */ public function stream_seek($offset, $whence) { if (!self::$streams[$this->id] instanceof Seekable) { - throw new IOException('Underlying stream does not support seeking'); + throw new OperationFailed('Underlying stream does not support seeking'); } self::$streams[$this->id]->seek($offset, $whence); @@ -204,7 +204,7 @@ public function stream_seek($offset, $whence) { */ public function stream_tell() { if (!self::$streams[$this->id] instanceof Seekable) { - throw new IOException('Underlying stream does not support seeking'); + throw new OperationFailed('Underlying stream does not support seeking'); } return self::$streams[$this->id]->tell(); } diff --git a/src/main/php/lang.base.php b/src/main/php/lang.base.php index 0ce66b163..186573295 100755 --- a/src/main/php/lang.base.php +++ b/src/main/php/lang.base.php @@ -465,4 +465,12 @@ function iconv_strlen($str, $charset) { $cl->loadClass0($name); return true; }); + +// https://github.com/xp-framework/core/issues/363 +if (PHP_VERSION_ID < 80600) { + class_alias(\io\OperationFailed::class, \io\IOException::class); + class_alias(\io\NotFound::class, \io\FileNotFoundException::class); + class_alias(\io\NotSupported::class, \io\OperationNotSupportedException::class); + class_alias(\io\TimedOut::class, \io\OperationTimedOutException::class); +} // }}} \ No newline at end of file diff --git a/src/main/php/lang/Process.class.php b/src/main/php/lang/Process.class.php index a44c95216..ffef1ba0b 100755 --- a/src/main/php/lang/Process.class.php +++ b/src/main/php/lang/Process.class.php @@ -1,6 +1,6 @@ handle= proc_open($exec, $spec, $pipes, $cwd, $env, $options))) { - throw new IOException('Could not execute "'.$exec.'"'); + throw new OperationFailed('Could not execute "'.$exec.'"'); } $this->status= proc_get_status($this->handle); @@ -99,7 +99,7 @@ public function __construct($command= null, $arguments= [], $cwd= null, $env= nu return; } - throw new IOException('Could not find "'.$command.'" in path'); + throw new OperationFailed('Could not find "'.$command.'" in path'); } /** @@ -110,7 +110,7 @@ public function __construct($command= null, $arguments= [], $cwd= null, $env= nu * @param ?[:string] $env default NULL the environment * @param var[] $descriptors * @return self - * @throws io.IOException in case the command could not be executed + * @throws io.OperationFailed in case the command could not be executed */ public function newInstance($arguments= [], $cwd= null, $env= null, $descriptors= []): self { return new self($this->status['exe'], $arguments, $cwd, $env, $descriptors); @@ -222,7 +222,7 @@ public static function getProcessById($pid, $exe= null): self { if (0 !== $exit) { throw new IllegalStateException('Cannot find executable: '.implode('', $out)); } - } catch (IOException $e) { + } catch (OperationFailed $e) { throw new IllegalStateException($e->getMessage()); } $self->status['running?']= function() use($pid) { diff --git a/src/main/php/util/Properties.class.php b/src/main/php/util/Properties.class.php index f1a8cd621..f23123a1c 100755 --- a/src/main/php/util/Properties.class.php +++ b/src/main/php/util/Properties.class.php @@ -69,7 +69,7 @@ public function expanding($kind, $expansion) { * @param io.streams.Reader|io.streams.InputStream|io.Channel|string $in * @param ?string $charset the charset the stream is encoded in or NULL to trigger autodetection by BOM * @return self - * @throws io.IOException + * @throws io.OperationFailed * @throws lang.FormatException */ public function load($in, $charset= 'utf-8'): self { @@ -148,7 +148,7 @@ protected function quote($val) { * * @param io.streams.Writer|io.streams.OutputStream|io.Channel|string $out * @param string $charset - * @throws io.IOException + * @throws io.OperationFailed */ public function store($out, $charset= 'utf-8') { $writer= $out instanceof Writer ? $out : new TextWriter($out, $charset); @@ -184,7 +184,7 @@ public function exists(): bool { return file_exists($this->_file); } * Create the property file * * @return void - * @throws io.IOException if the property file could not be created + * @throws io.OperationFailed if the property file could not be created */ public function create() { if (null !== $this->_file) { @@ -199,7 +199,7 @@ public function create() { * Helper method that loads the data from the file if needed * * @param bool force default FALSE - * @throws io.IOException + * @throws io.OperationFailed */ private function _load($force= false) { if ($force || null === $this->_data) { diff --git a/src/main/php/util/Random.class.php b/src/main/php/util/Random.class.php index 338df8b34..92ed7a321 100755 --- a/src/main/php/util/Random.class.php +++ b/src/main/php/util/Random.class.php @@ -1,6 +1,6 @@ lockfile->open(File::WRITE); $this->lockfile->lockExclusive(); - } catch (\io\IOException $e) { + } catch (\io\OperationFailed $e) { $this->lockfile->close(); return false; } diff --git a/src/main/php/xp/xar/instruction/DiffInstruction.class.php b/src/main/php/xp/xar/instruction/DiffInstruction.class.php index 07efd0c47..32f716cb6 100755 --- a/src/main/php/xp/xar/instruction/DiffInstruction.class.php +++ b/src/main/php/xp/xar/instruction/DiffInstruction.class.php @@ -1,7 +1,7 @@ close(); - } catch (IOException $e) { + } catch (OperationFailed $e) { $this->err->writeLine('!=> Invocation of `diff` program failed.'); $templ->unlink(); $tempr->unlink(); diff --git a/src/test/php/io/unittest/BlobTest.class.php b/src/test/php/io/unittest/BlobTest.class.php index 565d8787d..ff87b53f4 100755 --- a/src/test/php/io/unittest/BlobTest.class.php +++ b/src/test/php/io/unittest/BlobTest.class.php @@ -2,7 +2,7 @@ use ArrayObject; use io\streams\{MemoryInputStream, InputStream}; -use io\{Blob, OperationNotSupportedException}; +use io\{Blob, NotSupported}; use lang\IllegalArgumentException; use test\verify\Runtime; use test\{Assert, Expect, Test, Values}; @@ -97,7 +97,7 @@ public function close() { $this->input= []; } }); iterator_to_array($fixture->slices()); - Assert::throws(OperationNotSupportedException::class, fn() => iterator_to_array($fixture->slices())); + Assert::throws(NotSupported::class, fn() => iterator_to_array($fixture->slices())); } /** @see https://bugs.php.net/bug.php?id=77069 */ diff --git a/src/test/php/io/unittest/BufferTest.class.php b/src/test/php/io/unittest/BufferTest.class.php index 3b7d7b2ac..fb57b1888 100755 --- a/src/test/php/io/unittest/BufferTest.class.php +++ b/src/test/php/io/unittest/BufferTest.class.php @@ -1,7 +1,7 @@ $this->newFixture()->seek(-1)); + Assert::throws(OperationFailed::class, fn() => $this->newFixture()->seek(-1)); } #[Test] public function cannot_seek_invalid_whence() { - Assert::throws(IOException::class, fn() => $this->newFixture()->seek(0, 6100)); + Assert::throws(OperationFailed::class, fn() => $this->newFixture()->seek(0, 6100)); } #[Test] diff --git a/src/test/php/io/unittest/ChannelStreamTest.class.php b/src/test/php/io/unittest/ChannelStreamTest.class.php index 55311058a..f3473db49 100755 --- a/src/test/php/io/unittest/ChannelStreamTest.class.php +++ b/src/test/php/io/unittest/ChannelStreamTest.class.php @@ -1,48 +1,48 @@ isOpen() && $file->close(); $file->unlink(); - } catch (IOException $ignored) { + } catch (OperationFailed $ignored) { // Can't really do anything about it... } } @@ -71,12 +71,12 @@ public function delete() { }); } - #[Test, Expect(FileNotFoundException::class)] + #[Test, Expect(NotFound::class)] public function nonExistantFile() { new FileInputStream('::NON-EXISTANT::'); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function readingAfterClose() { with (new FileInputStream($this->tempFile()), function($stream) { $stream->close(); @@ -84,7 +84,7 @@ public function readingAfterClose() { }); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function availableAfterClose() { with (new FileInputStream($this->tempFile()), function($stream) { $stream->close(); diff --git a/src/test/php/io/unittest/FileIntegrationTest.class.php b/src/test/php/io/unittest/FileIntegrationTest.class.php index 82e032352..57639212e 100755 --- a/src/test/php/io/unittest/FileIntegrationTest.class.php +++ b/src/test/php/io/unittest/FileIntegrationTest.class.php @@ -1,6 +1,6 @@ open($append ? File::APPEND : File::WRITE); @@ -113,7 +113,7 @@ public function noLongerExistsAfterDeleting() { Assert::false($file->exists()); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function cannotDeleteNonExistant() { $this->tempFile()->unlink(); } @@ -125,7 +125,7 @@ public function cannotDeleteOpenFile() { $file->unlink(); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function cannotCloseUnopenedFile() { $this->tempFile()->close(); } @@ -291,7 +291,7 @@ public function appendingToExistant() { } } - #[Test, Expect(FileNotFoundException::class)] + #[Test, Expect(NotFound::class)] public function cannotOpenNonExistantForReading() { $this->tempFile()->open(File::READ); } diff --git a/src/test/php/io/unittest/FileOutputStreamTest.class.php b/src/test/php/io/unittest/FileOutputStreamTest.class.php index f64e6aa7f..a0c727497 100755 --- a/src/test/php/io/unittest/FileOutputStreamTest.class.php +++ b/src/test/php/io/unittest/FileOutputStreamTest.class.php @@ -1,7 +1,7 @@ isOpen() && $file->close(); $file->unlink(); - } catch (IOException $ignored) { + } catch (OperationFailed $ignored) { // Can't really do anything about it... } } @@ -64,7 +64,7 @@ public function given_an_invalid_file_an_exception_is_raised() { new FileOutputStream(''); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function cannot_write_after_closing() { with (new FileOutputStream($this->tempFile()), function($stream) { $stream->close(); diff --git a/src/test/php/io/unittest/FolderEntriesTest.class.php b/src/test/php/io/unittest/FolderEntriesTest.class.php index 971679c9a..dccf2972a 100755 --- a/src/test/php/io/unittest/FolderEntriesTest.class.php +++ b/src/test/php/io/unittest/FolderEntriesTest.class.php @@ -1,6 +1,6 @@ folder, '@non-existant@'))); + } + + #[Test, Expect(OperationFailed::class)] + public function entries_iteration_for_file() { + (new File($this->folder, 'file'))->touch(); + iterator_to_array(new FolderEntries(new Folder($this->folder, 'file'))); + } + #[Test] public function named() { Assert::equals(new Path($this->folder, 'test'), (new FolderEntries($this->folder))->named('test')); diff --git a/src/test/php/io/unittest/FolderTest.class.php b/src/test/php/io/unittest/FolderTest.class.php index fa5265d53..fe563106e 100755 --- a/src/test/php/io/unittest/FolderTest.class.php +++ b/src/test/php/io/unittest/FolderTest.class.php @@ -1,6 +1,6 @@ exists()); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function unlink_nonexistant() { $f= new Folder($this->tempFolder()); $f->unlink(); @@ -235,7 +235,7 @@ public function entries() { Assert::instance(FolderEntries::class, (new Folder($this->tempFolder()))->entries()); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function entries_iteration_raises_exception_if_path_does_not_exist() { iterator_to_array((new Folder($this->tempFolder()))->entries()); } diff --git a/src/test/php/io/unittest/LinesInTest.class.php b/src/test/php/io/unittest/LinesInTest.class.php index 06d120b3c..8b00527f4 100755 --- a/src/test/php/io/unittest/LinesInTest.class.php +++ b/src/test/php/io/unittest/LinesInTest.class.php @@ -1,7 +1,7 @@ 'A', 2 => 'B'], iterator_to_array($fixture)); try { iterator_to_array($fixture); - $this->fail('No exception raised', null, 'io.IOException'); - } catch (IOException $expected) { + $this->fail('No exception raised', null, 'io.OperationFailed'); + } catch (OperationFailed $expected) { // OK } } diff --git a/src/test/php/io/unittest/MemoryInputStreamTest.class.php b/src/test/php/io/unittest/MemoryInputStreamTest.class.php index bad754af0..3e0de3401 100755 --- a/src/test/php/io/unittest/MemoryInputStreamTest.class.php +++ b/src/test/php/io/unittest/MemoryInputStreamTest.class.php @@ -1,6 +1,6 @@ read(5)); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function seek_unknown_whence() { $in= $this->newFixture(); $in->seek(0, 9999); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function seek_before_start() { $in= $this->newFixture(); $in->seek(0, -1); diff --git a/src/test/php/io/unittest/MemoryOutputStreamTest.class.php b/src/test/php/io/unittest/MemoryOutputStreamTest.class.php index d422cda1f..38611c285 100755 --- a/src/test/php/io/unittest/MemoryOutputStreamTest.class.php +++ b/src/test/php/io/unittest/MemoryOutputStreamTest.class.php @@ -1,6 +1,6 @@ bytes()); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function seek_unknown_whence() { (new MemoryOutputStream(''))->seek(0, 9999); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function seek_before_start() { (new MemoryOutputStream(''))->seek(-1); } diff --git a/src/test/php/io/unittest/SpooledInputStreamTest.class.php b/src/test/php/io/unittest/SpooledInputStreamTest.class.php index 3593136a4..176ceef4d 100755 --- a/src/test/php/io/unittest/SpooledInputStreamTest.class.php +++ b/src/test/php/io/unittest/SpooledInputStreamTest.class.php @@ -1,7 +1,7 @@ close(); } - #[Test, Expect(IOException::class), Values([SEEK_SET, SEEK_CUR])] + #[Test, Expect(OperationFailed::class), Values([SEEK_SET, SEEK_CUR])] public function cannot_seek_before_beginning_of_file($whence) { $this->newFixture()->seek(-1, $whence); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function cannot_seek_with_invalid_whence() { $this->newFixture()->seek(0, 6100); } @@ -161,7 +161,7 @@ public function position_after_seek_error() { $stream= $this->newFixture(); $stream->read(4); - Assert::throws(IOException::class, fn() => $stream->seek(-1)); + Assert::throws(OperationFailed::class, fn() => $stream->seek(-1)); Assert::equals(4, $stream->tell()); } diff --git a/src/test/php/io/unittest/StreamTransferTest.class.php b/src/test/php/io/unittest/StreamTransferTest.class.php index 5d2938370..b67f77344 100755 --- a/src/test/php/io/unittest/StreamTransferTest.class.php +++ b/src/test/php/io/unittest/StreamTransferTest.class.php @@ -1,6 +1,6 @@ close(); - $this->fail('Expected exception not caught', null, 'io.IOException'); - } catch (IOException $expected) { + $this->fail('Expected exception not caught', null, 'io.OperationFailed'); + } catch (OperationFailed $expected) { Assert::equals('Could not close output stream: Close error', $expected->getMessage()); } @@ -115,8 +115,8 @@ public function closing_input_fails() { try { (new StreamTransfer($in, $out))->close(); - $this->fail('Expected exception not caught', null, 'io.IOException'); - } catch (IOException $expected) { + $this->fail('Expected exception not caught', null, 'io.OperationFailed'); + } catch (OperationFailed $expected) { Assert::equals('Could not close input stream: Close error', $expected->getMessage()); } @@ -130,8 +130,8 @@ public function closing_input_and_output_fails() { try { (new StreamTransfer($in, $out))->close(); - $this->fail('Expected exception not caught', null, 'io.IOException'); - } catch (IOException $expected) { + $this->fail('Expected exception not caught', null, 'io.OperationFailed'); + } catch (OperationFailed $expected) { Assert::equals('Could not close input stream: Close error, Could not close output stream: Close error', $expected->getMessage()); } } diff --git a/src/test/php/io/unittest/StreamWrappingTest.class.php b/src/test/php/io/unittest/StreamWrappingTest.class.php index 0ef75f37d..b3ba110aa 100755 --- a/src/test/php/io/unittest/StreamWrappingTest.class.php +++ b/src/test/php/io/unittest/StreamWrappingTest.class.php @@ -1,6 +1,6 @@ bytes()); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function reading_from_writeable_fd_raises_exception() { $fd= Streams::writeableFd(new MemoryOutputStream()); fread($fd, 1024); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function writing_to_readable_fd_raises_exception() { $fd= Streams::readableFd(new MemoryInputStream('')); fwrite($fd, 1024); @@ -157,10 +157,10 @@ public function readAll($value) { Assert::equals($value, Streams::readAll(new MemoryInputStream($value))); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function readAll_propagates_exception() { Streams::readAll(new class() implements InputStream { - public function read($limit= 8192) { throw new IOException('FAIL'); } + public function read($limit= 8192) { throw new OperationFailed('FAIL'); } public function available() { return 1; } public function close() { } }); diff --git a/src/test/php/io/unittest/TempFileTest.class.php b/src/test/php/io/unittest/TempFileTest.class.php index a0d7e0b3d..ca9efdc6b 100755 --- a/src/test/php/io/unittest/TempFileTest.class.php +++ b/src/test/php/io/unittest/TempFileTest.class.php @@ -1,6 +1,6 @@ containing('Test'); - $this->fail('No exception raised', null, IOException::class); - } catch (IOException $expected) { + $this->fail('No exception raised', null, OperationFailed::class); + } catch (OperationFailed $expected) { // OK } finally { $t->setPermissions(0600); diff --git a/src/test/php/io/unittest/TextReaderTest.class.php b/src/test/php/io/unittest/TextReaderTest.class.php index de9fbfbba..5e5024d09 100755 --- a/src/test/php/io/unittest/TextReaderTest.class.php +++ b/src/test/php/io/unittest/TextReaderTest.class.php @@ -1,7 +1,7 @@ read(3)); } - #[Test, Expect(class: IOException::class, message: 'Underlying stream does not support seeking')] + #[Test, Expect(class: OperationFailed::class, message: 'Underlying stream does not support seeking')] public function resetUnseekable() { $r= new TextReader($this->unseekableStream()); $r->reset(); @@ -439,8 +439,8 @@ public function can_only_iterate_unseekable_once() { Assert::equals([1 => 'A', 2 => 'B'], iterator_to_array($reader->lines())); try { iterator_to_array($reader->lines()); - $this->fail('No exception raised', null, 'io.IOException'); - } catch (\io\IOException $expected) { + $this->fail('No exception raised', null, 'io.OperationFailed'); + } catch (\io\OperationFailed $expected) { // OK } } diff --git a/src/test/php/lang/unittest/ProcessTest.class.php b/src/test/php/lang/unittest/ProcessTest.class.php index fce4c7c7a..56bde5345 100755 --- a/src/test/php/lang/unittest/ProcessTest.class.php +++ b/src/test/php/lang/unittest/ProcessTest.class.php @@ -1,7 +1,7 @@ readString('section', 'key')); } - #[Test, Expect(IOException::class)] + #[Test, Expect(OperationFailed::class)] public function throws_error_when_reading() { $p= new Properties('@@does-not-exist.ini@@'); $p->readString('section', 'key');