-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpTest.php
More file actions
128 lines (109 loc) · 4.44 KB
/
Copy pathHttpTest.php
File metadata and controls
128 lines (109 loc) · 4.44 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
namespace Chemem\Fauxton\Tests;
use \Eris\Generator;
use \Chemem\Fauxton\Config\State;
use \Chemem\Fauxton\Http;
use \Chemem\Bingo\Functional\Functors\Monads\IO;
use \Chemem\Bingo\Functional\Algorithms as A;
use \Chemem\Bingo\Functional\Functors\Monads as M;
use \Chemem\Bingo\Functional\PatternMatching as PM;
use \Psr\Http\Message\ResponseInterface;
class HttpTest extends \PHPUnit\Framework\TestCase
{
use \Eris\TestTrait;
private $eventLoop;
public function setUp()
{
$this->eventLoop = $this->getMockBuilder('React\\EventLoop\\LoopInterface')->getMock();
}
/**
* @eris-repeat 5
*/
public function testUrlFunctionGeneratesAppropriateRequestUrl()
{
$this->forAll(
Generator\string(),
Generator\string(),
Generator\bool(),
Generator\string(),
Generator\associative([
'uuids' => Generator\associative([
'{count}' => Generator\int()
])
])
)
->then(function (string $user, string $pwd, bool $local, string $clHost, array $opt) {
$url = Http\_url(array($local, $user, $pwd, $clHost), $opt);
$this->assertInternalType('string', $url);
$this->assertRegExp('/(http|https){1}(:){1}(\/){1}([\w\D\W]*)/', $url);
});
}
public function testTlsFunctionOutputsArrayContainingTLSConfiguration()
{
$this->forAll(Generator\constant('Chemem\\Fauxton\\Http\\_tls'))
->then(function (callable $function) {
$tlsOpts = $function();
$this->assertInternalType('array', $tlsOpts);
$this->assertArrayHasKey('tls', $tlsOpts);
});
}
public function testFetchFunctionOutputsInstanceOfReactPromise()
{
$this->forAll(Generator\elements(
array('get', State::COUCH_URI_LOCAL, State::COUCH_REQHEADERS),
array(
'post',
A\concat('/', State::COUCH_URI_LOCAL, 'testdb', '_all_docs'),
State::COUCH_REQHEADERS,
json_encode(array('keys' => array('abc', '123')))
)
))
->then(function (array $opts) {
$req = Http\_fetch($this->eventLoop, ...$opts)->then(function (ResponseInterface $response) {
$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertInternalType('string', (string) $response->getBody());
});
$this->assertInstanceOf(\React\Promise\Promise::class, $req);
});
}
public function testExecFunctionOutputsPromise()
{
$this->forAll(
Generator\elements(
array('uuids' => array('{count}' => 2)),
array('allDbs' => array())
)
)->then(function (array $urlOpts) {
$exec = Http\_exec($this->eventLoop, 'get', $urlOpts);
$this->assertInstanceOf(\React\Promise\Promise::class, $exec);
});
}
public function testConfigPathOutputsFauxtonJsonConfigurationFilePath()
{
$this->forAll(Generator\constant('Chemem\\Fauxton\\Http\\_configPath'))
->then(function (callable $function) {
$config = $function();
$this->assertInternalType('string', $config);
$this->assertRegExp('/([.\\w\/])+/', $config);
});
}
public function testReadConfigOutputsInstanceOfReactPromise()
{
$this->forAll(Generator\constant('Chemem\\Fauxton\\Http\\_readConfig'))
->then(function (callable $function) {
$config = $function($this->eventLoop);
$config->then(function ($contents) {
$this->assertInternalType('string', $contents);
});
$this->assertInstanceOf(\React\Promise\Promise::class, $config);
});
}
public function testCredentialsFunctionOutputsPivotalConfigurationOptions()
{
$this->forAll(Generator\constant('Chemem\\Fauxton\\Http\\_credentials'))
->then(function (callable $function) {
$config = M\bind(A\compose($function, IO\IO), IO\readFile(Http\_configPath()))->exec();
$this->assertInternalType('array', $config);
});
}
}