92% of 197OPs |
100% of 34Lines |
81% of 27Branches |
63% of 24Paths |
Method | OPs | OPs % | Lines | Line % | Branches | Branches % | Paths | Path % |
---|---|---|---|---|---|---|---|---|
mageekguy\atoum\writers\http::__construct() | 16 | 100% | 3 | 100% | 1 | 0% | 1 | 100% |
mageekguy\atoum\writers\http::writeAsynchronousReport() | 12 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\writers\http::clear() | 5 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\writers\http::addHeader() | 11 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\writers\http::getHeaders() | 6 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\writers\http::setMethod() | 11 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\writers\http::getMethod() | 6 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\writers\http::setParameter() | 9 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\writers\http::getParameter() | 6 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\writers\http::setUrl() | 9 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\writers\http::getUrl() | 6 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\writers\http::doWrite() | 100 | 84% | 17 | 100% | 16 | 75% | 13 | 31% |
# | |
---|---|
1 |
<?php |
2 |
|
3 |
namespace mageekguy\atoum\writers; |
4 |
|
5 |
use |
6 |
mageekguy\atoum, |
7 |
mageekguy\atoum\reports, |
8 |
mageekguy\atoum\exceptions, |
9 |
mageekguy\atoum\report\writers |
10 |
; |
11 |
|
12 |
class http extends atoum\writer implements writers\asynchronous |
13 |
{ |
14 |
protected $url = null; |
15 |
protected $method = null; |
16 |
protected $parameter = null; |
17 |
protected $headers = array(); |
18 |
|
19 |
public function __construct(atoum\adapter $adapter = null)100% |
20 |
{ |
21 |
parent::__construct($adapter); |
22 |
|
23 |
$this->setMethod(); |
24 |
} |
25 |
|
26 |
public function writeAsynchronousReport(reports\asynchronous $report)100% |
27 |
{ |
28 |
return $this->write((string) $report); |
29 |
} |
30 |
|
31 |
public function clear()100% |
32 |
{ |
33 |
return $this; |
34 |
} |
35 |
|
36 |
public function addHeader($name, $value)100% |
37 |
{ |
38 |
$this->headers[$name] = $value; |
39 |
|
40 |
return $this; |
41 |
} |
42 |
|
43 |
public function getHeaders()100% |
44 |
{ |
45 |
return $this->headers; |
46 |
} |
47 |
|
48 |
public function setMethod($method = null)100% |
49 |
{ |
50 |
$this->method = $method ?: 'GET'; |
51 |
|
52 |
return $this; |
53 |
} |
54 |
|
55 |
public function getMethod()100% |
56 |
{ |
57 |
return $this->method; |
58 |
} |
59 |
|
60 |
public function setParameter($parameter = null)100% |
61 |
{ |
62 |
$this->parameter = $parameter; |
63 |
|
64 |
return $this; |
65 |
} |
66 |
|
67 |
public function getParameter()100% |
68 |
{ |
69 |
return $this->parameter; |
70 |
} |
71 |
|
72 |
public function setUrl($url)100% |
73 |
{ |
74 |
$this->url = $url; |
75 |
|
76 |
return $this; |
77 |
} |
78 |
|
79 |
public function getUrl()100% |
80 |
{ |
81 |
return $this->url; |
82 |
} |
83 |
|
84 |
protected function doWrite($string)100% |
85 |
{ |
86 |
if ($this->url === null) |
87 |
{ |
88 |
throw new exceptions\runtime('No URL set for HTTP writer'); |
89 |
} |
90 |
|
91 |
$headers = array(); |
92 |
|
93 |
foreach ($this->headers as $name => $value) |
94 |
{ |
95 |
$headers[] = sprintf('%s: %s', $name, $value); |
96 |
} |
97 |
|
98 |
$context = $this->adapter->stream_context_create(array( |
99 |
'http' => array( |
100 |
'method' => $this->method, |
101 |
'header' => join("\r\n", $headers), |
102 |
'content' => $this->parameter ? http_build_query(array($this->parameter => $string)) : $string |
103 |
) |
104 |
)); |
105 |
|
106 |
if (@$this->adapter->file_get_contents($this->url, false, $context) === false) |
107 |
{ |
108 |
throw new atoum\writers\http\exception('Unable to write coverage report to ' . $this->url); |
109 |
} |
110 |
|
111 |
return $this; |
112 |
} |
113 |
} |