-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathStreamStub.php
78 lines (64 loc) · 1.56 KB
/
StreamStub.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
* Copyright (c) Ouzo contributors, https://github.com/letsdrink/ouzo
* This file is made available under the MIT License (view the LICENSE file for more information).
*/
namespace Ouzo\Tests;
class StreamStub
{
public $context;
public static $position = 0;
public static $body = '';
public static $streamName;
public function stream_open($path, $mode, $options, &$opened_path)
{
return true;
}
public function stream_read($bytes)
{
$chunk = substr(static::$body, static::$position, $bytes);
static::$position += strlen($chunk);
return $chunk;
}
public function stream_write($data)
{
static::$body .= $data;
return strlen($data);
}
public function stream_eof()
{
return static::$position >= strlen(static::$body);
}
public function stream_tell()
{
return static::$position;
}
public function stream_stat()
{
return [];
}
public function stream_seek($offset, $whence)
{
static::$position = $offset;
return true;
}
public function stream_close()
{
return null;
}
public static function register($streamName)
{
self::$streamName = $streamName;
stream_wrapper_register($streamName, StreamStub::class);
}
public static function unregister()
{
stream_wrapper_unregister(self::$streamName);
self::reset();
}
private static function reset()
{
static::$body = '';
static::$position = 0;
}
}