Skip to content

Commit b8e2a85

Browse files
committed
Added more tests
1 parent 4f85233 commit b8e2a85

File tree

1 file changed

+231
-2
lines changed

1 file changed

+231
-2
lines changed

tests/ActionsTest.php

Lines changed: 231 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,29 @@ public static function blockFn() : callable
3131
return A\toException('Clue\\React\\Block\\await');
3232
}
3333

34+
const ID_REGEX = '/([\w\d])+/';
35+
36+
const REV_REGEX = '/(\d){1}(-){1}([\w\d]*)/';
37+
38+
const specialConst = 'Chemem\\Fauxton\\Tests\\ActionsTest::specialConst';
39+
40+
const revConst = 'Chemem\\Fauxton\\Tests\\ActionsTest::revConst';
41+
3442
const idConst = 'Chemem\\Fauxton\\Tests\\ActionsTest::idConst';
3543

36-
public static function idConst(string $val)
44+
public static function specialConst(string $val, string $regex, int $limit)
45+
{
46+
return preg_match($regex, $val) && strlen($val) >= $limit;
47+
}
48+
49+
public static function idConst(string $val) : bool
50+
{
51+
return self::specialConst($val, self::ID_REGEX, 32);
52+
}
53+
54+
public static function revConst(string $val) : bool
3755
{
38-
return preg_match('/([\w\d])+/', $val) && strlen($val) >= 32;
56+
return self::specialConst($val, self::REV_REGEX, 34);
3957
}
4058

4159
/**
@@ -179,6 +197,33 @@ public function testInsertSinglePutsDataInDatabase()
179197
});
180198
}
181199

200+
/**
201+
* @eris-repeat 5
202+
*/
203+
public function testInsertMultiplePutsDataInDatabase()
204+
{
205+
$this->forAll(
206+
Generator\constant('testdb'),
207+
Generator\associative([
208+
'docs' => Generator\tuple(
209+
Generator\associative([
210+
'user' => Generator\names()
211+
]),
212+
Generator\associative([
213+
'date' => Generator\date()
214+
]),
215+
)
216+
])
217+
)
218+
->then(function (string $database, array $data) {
219+
$promise = $this->action->insertMultiple($database, $data);
220+
$insert = self::blockFn()($promise, $this->eventLoop);
221+
222+
$this->assertInstanceOf(\React\Promise\Promise::class, $promise);
223+
$this->assertInternalType('string', $insert);
224+
});
225+
}
226+
182227
public function testQueryParamsPrintsArrayOfUrlQueryParameters()
183228
{
184229
$this->forAll(
@@ -198,4 +243,188 @@ public function testQueryParamsPrintsArrayOfUrlQueryParameters()
198243
$this->assertInternalType('array', $promise);
199244
});
200245
}
246+
247+
/**
248+
* @eris-repeat 5
249+
*/
250+
public function testCreateIndexGeneratesDatabaseSearchQueryIndex()
251+
{
252+
$this->forAll(
253+
Generator\constant('testdb'),
254+
Generator\associative([
255+
'index' => Generator\associative([
256+
'fields' => Generator\elements('_id', '_rev', 'foo')
257+
]),
258+
'name' => Generator\names('foo-index', 'bar-index')
259+
])
260+
)
261+
->then(function (string $database, array $opts) {
262+
$promise = $this->action->createIndex($database, $opts);
263+
$index = self::blockFn()($promise, $this->eventLoop);
264+
265+
$this->assertInstanceOf(\React\Promise\Promise::class, $promise);
266+
$this->assertInternalType('string', $index);
267+
});
268+
}
269+
270+
/**
271+
* @eris-repeat 5
272+
*/
273+
public function testGetIndexesOutputsIndexInformation()
274+
{
275+
$this->forAll(Generator\constant('testdb'))
276+
->then(function (string $database) {
277+
$promise = $this->action->getIndexes($database);
278+
$indexes = self::blockFn()($promise, $this->eventLoop);
279+
280+
$this->assertInstanceOf(\React\Promise\Promise::class, $promise);
281+
$this->assertInternalType('string', $indexes);
282+
});
283+
}
284+
285+
/**
286+
* @eris-repeat 5
287+
*/
288+
public function testChangesFunctionOutputsDatabaseChangeLogData()
289+
{
290+
$this->forAll(
291+
Generator\constant('testdb'),
292+
Generator\associative([
293+
'descending' => Generator\elements('true', 'false'),
294+
'include_docs' => Generator\elements('true', 'false'),
295+
'conflicts' => Generator\elements('true', 'false'),
296+
'limit' => Generator\choose(1, 5)
297+
])
298+
)
299+
->then(function (string $database, array $params) {
300+
$promise = $this->action->changes($database, $params);
301+
$changes = self::blockFn()($promise, $this->eventLoop);
302+
303+
$this->assertInstanceOf(\React\Promise\Promise::class, $promise);
304+
$this->assertInternalType('string', $changes);
305+
});
306+
}
307+
308+
/**
309+
* @eris-repeat 5
310+
* @eris-ratio 0.1
311+
*/
312+
public function testUpdateSingleUpdatesSingleDocumentInDatabase()
313+
{
314+
$this->forAll(
315+
Generator\constant('testdb'),
316+
Generator\suchThat(self::revConst, Generator\string()),
317+
Generator\suchThat(self::idConst, Generator\string()),
318+
Generator\associative([
319+
'age' => Generator\choose(18, 70),
320+
'date' => Generator\date()
321+
])
322+
)
323+
->then(function (string $database, string $rev, string $docId, array $update) {
324+
$promise = $this->action->updateSingle($database, $rev, $docId, $update);
325+
$update = self::blockFn()($promise, $this->eventLoop);
326+
327+
$this->assertInstanceOf(\React\Promise\Promise::class, $promise);
328+
$this->assertInternalType('string', $update);
329+
});
330+
}
331+
332+
/**
333+
* @eris-repeat 5
334+
* @eris-ratio 0.1
335+
*/
336+
public function testUpdateMultipleUpdatesMultipleDocumentsInDatabase()
337+
{
338+
$this->forAll(
339+
Generator\constant('testdb'),
340+
Generator\associative([
341+
'docs' => Generator\tuple(
342+
Generator\associative([
343+
'_id' => Generator\suchThat(self::idConst, Generator\string()),
344+
'_rev' => Generator\suchThat(self::revConst, Generator\string()),
345+
'name' => Generator\names()
346+
])
347+
)
348+
])
349+
)
350+
->then(function (string $database, array $update) {
351+
$promise = $this->action->updateMultiple($database, $update);
352+
$update = self::blockFn()($promise, $this->eventLoop);
353+
354+
$this->assertInstanceOf(\React\Promise\Promise::class, $promise);
355+
$this->assertInternalType('string', $update);
356+
});
357+
}
358+
359+
/**
360+
* @eris-repeat 5
361+
* @eris-ratio 0.1
362+
*/
363+
public function testDeleteSingleDeletesSingleDocument()
364+
{
365+
$this->forAll(
366+
Generator\constant('testdb'),
367+
Generator\suchThat(self::revConst, Generator\string()),
368+
Generator\suchThat(self::idConst, Generator\string())
369+
)
370+
->then(function (string $database, string $rev, string $docId) {
371+
$promise = $this->action->deleteSingle($database, $rev, $docId);
372+
$delete = self::blockFn()($promise, $this->eventLoop);
373+
374+
$this->assertInstanceOf(\React\Promise\Promise::class, $promise);
375+
$this->assertInternalType('string', $delete);
376+
});
377+
}
378+
379+
/**
380+
* @eris-repeat 5
381+
* @eris-ratio 0.1
382+
*/
383+
public function testDeleteMultipleDeletesMultipleDocuments()
384+
{
385+
$this->forAll(
386+
Generator\constant('testdb'),
387+
Generator\associative([
388+
'docs' => Generator\tuple(
389+
Generator\associative([
390+
'_id' => Generator\suchThat(self::idConst, Generator\string()),
391+
'_rev' => Generator\suchThat(self::revConst, Generator\string())
392+
])
393+
)
394+
])
395+
)
396+
->then(function (string $database, array $data) {
397+
$promise = $this->action->deleteMultiple($database, $data);
398+
$delete = self::blockFn()($promise, $this->eventLoop);
399+
400+
$this->assertInstanceOf(\React\Promise\Promise::class, $promise);
401+
$this->assertInternalType('string', $delete);
402+
});
403+
}
404+
405+
/**
406+
* @eris-repeat 5
407+
*/
408+
public function testCreateDesignDocCreatesDesignDocuments()
409+
{
410+
$this->forAll(
411+
Generator\constant('testdb'),
412+
Generator\elements('id-designdoc', 'rev-designdoc'),
413+
Generator\associative([
414+
'views' => Generator\associative([
415+
'map' => Generator\elements(
416+
'function (doc) { emit(doc._id); }',
417+
'function (doc) { emit(doc._rev, doc.user); }'
418+
)
419+
])
420+
])
421+
)
422+
->then(function (string $database, string $ddoc, array $docData) {
423+
$promise = $this->action->createDesignDoc($database, $ddoc, $docData);
424+
$ddoc = self::blockFn()($promise, $this->eventLoop);
425+
426+
$this->assertInstanceOf(\React\Promise\Promise::class, $promise);
427+
$this->assertInternalType('string', $ddoc);
428+
});
429+
}
201430
}

0 commit comments

Comments
 (0)