|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ProtocolsTests\Http; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\RemoteRequest\Connection; |
|
8
|
|
|
use kalanis\RemoteRequest\Protocols\Dummy; |
|
9
|
|
|
use kalanis\RemoteRequest\Protocols\Http; |
|
10
|
|
|
use kalanis\RemoteRequest\RequestException; |
|
11
|
|
|
use kalanis\RemoteRequest\Translations; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class TestProcessor extends Connection\Processor |
|
15
|
|
|
{ |
|
16
|
|
|
public function process(): Connection\Processor |
|
17
|
|
|
{ |
|
18
|
|
|
return $this; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function getResponse() |
|
22
|
|
|
{ |
|
23
|
|
|
return CommonTestClass::stringToResource('HTTP/0.1 900 KO' . Http::DELIMITER); |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
class ContentTestProcessor extends TestProcessor |
|
29
|
|
|
{ |
|
30
|
|
|
public function process(): Connection\Processor |
|
31
|
|
|
{ |
|
32
|
|
|
return $this; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function getResponse() |
|
36
|
|
|
{ |
|
37
|
|
|
return CommonTestClass::stringToResource('HTTP/0.1 901 KO' . Http::DELIMITER . Http::DELIMITER . 'abcdefghijkl'); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
class SimpleQueryTest extends CommonTestClass |
|
43
|
|
|
{ |
|
44
|
|
|
/** |
|
45
|
|
|
* When the answer is empty |
|
46
|
|
|
* @throws RequestException |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testSetsSimple(): void |
|
49
|
|
|
{ |
|
50
|
|
|
$result = $this->queryOnMock(new TestProcessor(new Translations())); |
|
51
|
|
|
$this->assertEquals(900, $result->getCode()); |
|
52
|
|
|
$this->assertEquals('', $result->getContent()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* When the answer contains something |
|
57
|
|
|
* @throws RequestException |
|
58
|
|
|
*/ |
|
59
|
|
|
public function testSetsBody(): void |
|
60
|
|
|
{ |
|
61
|
|
|
$result = $this->queryOnMock(new ContentTestProcessor(new Translations())); |
|
62
|
|
|
$this->assertEquals(901, $result->getCode()); |
|
63
|
|
|
$this->assertEquals('abcdefghijkl', $result->getContent()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param Connection\Processor $processor cim vrati vzdalena data |
|
68
|
|
|
* @throws RequestException |
|
69
|
|
|
* @return Http\Answer |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function queryOnMock(Connection\Processor $processor): Http\Answer |
|
72
|
|
|
{ |
|
73
|
|
|
$processor->setData(new Dummy\Query()); |
|
74
|
|
|
$processor->setConnectionParams(new Connection\Params\Tcp()); |
|
75
|
|
|
$processor->process(); |
|
76
|
|
|
$answer = new Http\Answer(new Translations()); |
|
77
|
|
|
return $answer->setResponse($processor->getResponse()); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|