Changeset 50771 for trunk/tests/phpunit/includes/class-wp-test-stream.php
- Timestamp:
- 04/20/2021 03:01:55 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/class-wp-test-stream.php
r49545 r50771 12 12 * (note the trailing slash). 13 13 * 14 * This class can be used to test that code works with basic read/write streams, 15 * as such, operations such as seeking are not supported. 14 * This class can be used to test that code works with basic read/write streams. 16 15 * 17 16 * This class does not register itself as a stream handler: test fixtures … … 25 24 * In-memory storage for files and directories simulated by this wrapper. 26 25 */ 27 static $data = array();28 29 var$position;30 var$file;31 var$bucket;32 var$data_ref;26 public static $data = array(); 27 28 public $position; 29 public $file; 30 public $bucket; 31 public $data_ref; 33 32 34 33 /** … … 67 66 * @see streamWrapper::stream_open 68 67 */ 69 function stream_open( $path, $mode, $options, &$opened_path ) {68 public function stream_open( $path, $mode, $options, &$opened_path ) { 70 69 $this->open( $path ); 71 70 return true; … … 77 76 * @see streamWrapper::stream_read 78 77 */ 79 function stream_read( $count ) {78 public function stream_read( $count ) { 80 79 if ( ! isset( $this->data_ref ) ) { 81 80 return ''; … … 93 92 * @see streamWrapper::stream_write 94 93 */ 95 function stream_write( $data ) {94 public function stream_write( $data ) { 96 95 if ( ! isset( $this->data_ref ) ) { 97 96 $this->data_ref = ''; … … 108 107 109 108 /** 109 * Seeks to specific location in a stream. 110 * 111 * @see streamWrapper::stream_seek 112 * 113 * @param int $offset The stream offset to seek to. 114 * @param int $whence Optional. Seek position. 115 * @return bool Returns true when position is updated, else false. 116 */ 117 public function stream_seek( $offset, $whence = SEEK_SET ) { 118 if ( empty( $this->data_ref ) ) { 119 return false; 120 } 121 122 $new_offset = $this->position; 123 switch ( $whence ) { 124 case SEEK_CUR: 125 $new_offset += $offset; 126 break; 127 128 case SEEK_END: 129 $new_offset = strlen( $this->data_ref ) + $offset; 130 break; 131 132 case SEEK_SET: 133 $new_offset = $offset; 134 break; 135 136 default: 137 return false; 138 } 139 140 if ( $new_offset < 0 ) { 141 return false; 142 } 143 144 // Save the new position. 145 $this->position = $new_offset; 146 147 return true; 148 } 149 150 /** 110 151 * Retrieves the current position of a stream. 111 152 * 112 153 * @see streamWrapper::stream_tell 113 154 */ 114 function stream_tell() {155 public function stream_tell() { 115 156 return $this->position; 116 157 } … … 121 162 * @see streamWrapper::stream_eof 122 163 */ 123 function stream_eof() {164 public function stream_eof() { 124 165 if ( ! isset( $this->data_ref ) ) { 125 166 return true; … … 134 175 * @see streamWrapper::stream_metadata 135 176 */ 136 function stream_metadata( $path, $option, $var ) {177 public function stream_metadata( $path, $option, $var ) { 137 178 $this->open( $path ); 138 179 if ( STREAM_META_TOUCH === $option ) { … … 150 191 * @see streamWrapper::mkdir 151 192 */ 152 function mkdir( $path, $mode, $options ) {193 public function mkdir( $path, $mode, $options ) { 153 194 $this->open( $path ); 154 195 $plainfile = rtrim( $this->file, '/' );
Note: See TracChangeset
for help on using the changeset viewer.