93% of 538OPs |
97% of 126Lines |
82% of 182Branches |
84% of 67Paths |
Method | OPs | OPs % | Lines | Line % | Branches | Branches % | Paths | Path % |
---|---|---|---|---|---|---|---|---|
mageekguy\atoum\mock\stream\controller::__construct() | 14 | 100% | 3 | 100% | 1 | 0% | 1 | 100% |
mageekguy\atoum\mock\stream\controller::__toString() | 9 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\mock\stream\controller::__get() | 21 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\mock\stream\controller::__set() | 133 | 87% | 34 | 91% | 22 | 68% | 4 | 50% |
mageekguy\atoum\mock\stream\controller::__isset() | 18 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\mock\stream\controller::duplicate() | 20 | 100% | 5 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\mock\stream\controller::setPath() | 9 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\mock\stream\controller::getPath() | 6 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\mock\stream\controller::getBasename() | 11 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\mock\stream\controller::invoke() | 49 | 100% | 6 | 100% | 11 | 100% | 8 | 38% |
mageekguy\atoum\mock\stream\controller::mapMethod() | 248 | 91% | 70 | 99% | 141 | 83% | 47 | 91% |
# | |
---|---|
1 |
<?php |
2 |
|
3 |
namespace mageekguy\atoum\mock\stream; |
4 |
|
5 |
use |
6 |
mageekguy\atoum\test, |
7 |
mageekguy\atoum\exceptions |
8 |
; |
9 |
|
10 |
class controller extends test\adapter |
11 |
{ |
12 |
protected $path = ''; |
13 |
|
14 |
public function __construct($path)100% |
15 |
{ |
16 |
parent::__construct(); |
17 |
|
18 |
$this->path = (string) $path; |
19 |
} |
20 |
|
21 |
public function __toString()100% |
22 |
{ |
23 |
return $this->getPath(); |
24 |
} |
25 |
|
26 |
public function __get($method)100% |
27 |
{ |
28 |
$method = static::mapMethod($method); |
29 |
|
30 |
return $this->setInvoker($method, function() use ($method) { return new invoker($method); }); |
31 |
} |
32 |
|
33 |
public function __set($method, $value)91% |
34 |
{ |
35 |
switch (strtolower($method)) |
36 |
{ |
37 |
case 'file_get_contents': |
38 |
if ($value === false) |
39 |
{ |
40 |
$this->fopen = false; |
41 |
} |
42 |
else |
43 |
{ |
44 |
$this->stat = array('mode' => 33188); |
45 |
$this->fopen = true; |
46 |
$this->fread[1] = $value; |
47 |
$this->fread[2] = false; |
48 |
$this->fclose = true; |
49 |
} |
50 |
return $this; |
51 |
|
52 |
case 'file_put_contents': |
53 |
$this->stat = array('mode' => 33188); |
54 |
$this->fopen = true; |
55 |
$this->fwrite = $value; |
56 |
$this->fclose = true; |
57 |
return $this; |
58 |
|
59 |
default: |
60 |
$method = static::mapMethod($method); |
61 |
|
62 |
switch ($method) |
63 |
{ |
64 |
case 'dir_opendir': |
65 |
$this->dir_closedir = true; |
66 |
$this->dir_rewinddir = true; |
67 |
$this->dir_readdir = false; |
68 |
$this->url_stat = array('mode' => 16877); |
69 |
break; |
70 |
|
71 |
case 'dir_readdir': |
72 |
if ($value instanceof self) |
73 |
{ |
74 |
$value = $value->getBasename(); |
75 |
} |
76 |
break; |
77 |
} |
78 |
|
79 |
return parent::__set($method, $value); |
80 |
} |
81 |
} |
82 |
|
83 |
public function __isset($method)100% |
84 |
{ |
85 |
return parent::__isset(static::mapMethod($method)); |
86 |
} |
87 |
|
88 |
public function duplicate()100% |
89 |
{ |
90 |
$controller = clone $this; |
91 |
|
92 |
$controller->path = & $this->path; |
93 |
$controller->calls = & $this->calls; |
94 |
$controller->invokers = & $this->invokers; |
95 |
|
96 |
return $controller; |
97 |
} |
98 |
|
99 |
public function setPath($path)100% |
100 |
{ |
101 |
$this->path = $path; |
102 |
|
103 |
return $this; |
104 |
} |
105 |
|
106 |
public function getPath()100% |
107 |
{ |
108 |
return $this->path; |
109 |
} |
110 |
|
111 |
public function getBasename()100% |
112 |
{ |
113 |
return basename($this->path); |
114 |
} |
115 |
|
116 |
public function invoke($method, array $arguments = array())100% |
117 |
{ |
118 |
$method = static::mapMethod($method); |
119 |
|
120 |
if ($method === 'dir_rewinddir' && isset($this->{$method}) === true) |
121 |
{ |
122 |
$this->resetCalls('dir_readdir'); |
123 |
} |
124 |
|
125 |
return ($this->nextCallIsOverloaded($method) === false ? null : parent::invoke($method, $arguments)); |
126 |
} |
127 |
|
128 |
protected static function mapMethod($method)99% |
129 |
{ |
130 |
$method = strtolower($method); |
131 |
|
132 |
switch ($method) |
133 |
{ |
134 |
case 'mkdir': |
135 |
case 'rmdir': |
136 |
case 'rename': |
137 |
case 'unlink': |
138 |
case '__construct': |
139 |
case 'stream_set_option': |
140 |
return $method; |
141 |
|
142 |
case 'closedir': |
143 |
case 'dir_closedir': |
144 |
return 'dir_closedir'; |
145 |
|
146 |
case 'opendir': |
147 |
case 'dir_opendir': |
148 |
return 'dir_opendir'; |
149 |
|
150 |
case 'readdir': |
151 |
case 'dir_readdir': |
152 |
return 'dir_readdir'; |
153 | |
154 |
case 'rewinddir': |
155 |
case 'dir_rewinddir': |
156 |
return 'dir_rewinddir'; |
157 |
|
158 |
case 'select': |
159 |
case 'stream_cast': |
160 |
return 'stream_cast'; |
161 |
|
162 |
case 'fclose': |
163 |
case 'stream_close': |
164 |
return 'stream_close'; |
165 |
|
166 |
case 'feof': |
167 |
case 'stream_eof': |
168 |
return 'stream_eof'; |
169 |
|
170 |
case 'fflush': |
171 |
case 'stream_flush': |
172 |
return 'stream_flush'; |
173 |
|
174 |
case 'ftruncate': |
175 |
case 'stream_truncate': |
176 |
return 'stream_truncate'; |
177 |
|
178 |
case 'flock': |
179 |
case 'stream_lock': |
180 |
return 'stream_lock'; |
181 |
|
182 |
case 'touch': |
183 |
case 'chmod': |
184 |
case 'chown': |
185 |
case 'chgrp': |
186 |
case 'stream_metadata': |
187 |
return 'stream_metadata'; |
188 |
|
189 |
case 'fopen': |
190 |
case 'stream_open': |
191 |
return 'stream_open'; |
192 |
|
193 |
case 'fread': |
194 |
case 'fgets': |
195 |
case 'stream_read': |
196 |
return 'stream_read'; |
197 |
|
198 |
case 'fseek': |
199 |
case 'stream_seek': |
200 |
return 'stream_seek'; |
201 |
|
202 |
case 'fstat': |
203 |
case 'stream_stat': |
204 |
return 'stream_stat'; |
205 |
|
206 |
case 'ftell': |
207 |
case 'stream_tell': |
208 |
return 'stream_tell'; |
209 |
|
210 |
case 'fwrite': |
211 |
case 'stream_write': |
212 |
return 'stream_write'; |
213 |
|
214 |
case 'stat': |
215 |
case 'url_stat': |
216 |
return 'url_stat'; |
217 |
|
218 |
default: |
219 |
throw new exceptions\logic\invalidArgument('Method streamWrapper::' . $method . '() does not exist'); |
220 |
} |
221 |
} |
222 |
} |