1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Onoi\HttpRequest\Tests; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @codeCoverageIgnore |
7
|
|
|
* @see https://gist.github.com/ukolka/8448362 |
8
|
|
|
*/ |
9
|
|
|
class MockHttpStreamWrapper { |
10
|
|
|
|
11
|
|
|
public static $mockBodyData = ''; |
12
|
|
|
public static $mockResponseCode = 'HTTP/1.1 200 OK'; |
13
|
|
|
|
14
|
|
|
public $context; |
15
|
|
|
public $position = 0; |
16
|
|
|
public $bodyData = 'test data'; |
17
|
|
|
public $responseCode = ''; |
18
|
|
|
|
19
|
|
|
protected $streamArray = array(); |
20
|
|
|
protected $options = array(); |
21
|
|
|
protected $isOpen = false; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* StreamWrapper::stream_open |
25
|
|
|
*/ |
26
|
|
|
public function stream_open( $path, $mode, $options, &$opened_path ) { |
|
|
|
|
27
|
|
|
$this->bodyData = self::$mockBodyData; |
28
|
|
|
$this->responseCode = self::$mockResponseCode; |
29
|
|
|
array_push( $this->streamArray, self::$mockResponseCode ); |
30
|
|
|
$this->isOpen = true; |
31
|
|
|
return true; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* StreamWrapper::stream_write |
36
|
|
|
*/ |
37
|
|
|
public function stream_write( $data ) { |
38
|
|
|
|
39
|
|
|
if ( $this->isOpen ) { |
40
|
|
|
return strlen( $data ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return 0; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* StreamWrapper::stream_read |
48
|
|
|
*/ |
49
|
|
|
public function stream_read( $count ) { |
50
|
|
|
|
51
|
|
|
if ( $this->position > strlen($this->bodyData)) { |
52
|
|
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$result = substr( $this->bodyData, $this->position, $count ); |
56
|
|
|
$this->position += $count; |
57
|
|
|
return $result; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* StreamWrapper::stream_eof |
62
|
|
|
*/ |
63
|
|
|
public function stream_eof() { |
64
|
|
|
return $this->position >= strlen($this->bodyData); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* StreamWrapper::stream_set_option |
69
|
|
|
*/ |
70
|
|
|
public function stream_set_option( $option, $arg1, $arg2 ) { |
|
|
|
|
71
|
|
|
$this->options[$option] = array(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* StreamWrapper::stream_stat |
76
|
|
|
*/ |
77
|
|
|
public function stream_stat() { |
78
|
|
|
return array( 'wrapper_data' => array( 'test' ) ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* StreamWrapper::stream_tell |
83
|
|
|
*/ |
84
|
|
|
public function stream_tell() { |
85
|
|
|
return $this->position; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.