Skip to content

Commit ab8196c

Browse files
committed
Added new methods
1 parent fdf575f commit ab8196c

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

src/Actions/Action.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,35 @@ public function replicate(array $opts, bool $continuous = false) : Promise
236236
{
237237
return self::_resolve($this->loop, 'post', array('replicate' => array()), $opts);
238238
}
239+
240+
public function queryView(string $database, string $ddoc, string $view, array $opts = array()) : Promise
241+
{
242+
return self::_resolve($this->loop, 'get', self::_queryParams('view', [
243+
'{db}' => $database,
244+
'{ddoc}' => $ddoc,
245+
'{view}' => $view
246+
], $opts));
247+
}
248+
249+
public function keysQueryView(
250+
string $database,
251+
string $ddoc,
252+
string $view,
253+
array $keys,
254+
array $opts = array()
255+
)
256+
{
257+
$resolve = A\partial(self::_resolve, $this->loop, 'post');
258+
259+
$query = A\compose(
260+
A\partial(self::_queryParams, 'view', array(
261+
'{db}' => $database,
262+
'{ddoc}' => $ddoc,
263+
'{view}' => $view
264+
)),
265+
A\partialRight($resolve, isset($keys['keys']) ? $keys : array('keys' => $keys))
266+
);
267+
268+
return $query($opts);
269+
}
239270
}

src/Actions/functions.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Chemem\Fauxton\Actions;
4+
5+
function updateMerge(array $original, array $update) : array
6+
{
7+
$update = A\compose(A\partial(A\omit, '_id', '_rev'), A\partial(A\extend, $update));
8+
9+
return $update($original);
10+
}

tests/ActionsTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,4 +445,58 @@ public function testReplicateFunctionReplicatesDatabase()
445445
$this->assertInternalType('string', $replicate);
446446
});
447447
}
448+
449+
/**
450+
* @eris-repeat 5
451+
*/
452+
public function testQueryViewGetsDataFromView()
453+
{
454+
$this->forAll(
455+
Generator\constant('testdb'),
456+
Generator\elements('id-designdoc', 'rev-designdoc'),
457+
Generator\constant('map'),
458+
Generator\associative([
459+
'descending' => Generator\elements('true', 'false'),
460+
'include_docs' => Generator\elements('true', 'false'),
461+
'group' => Generator\elements('true', 'false')
462+
])
463+
)
464+
->then(function (string $database, string $ddoc, string $view, array $opts) {
465+
$promise = $this->action->queryView($database, $ddoc, $view, $opts);
466+
$query = self::blockFn()($promise, $this->eventLoop);
467+
468+
$this->assertInstanceOf(\React\Promise\Promise::class, $promise);
469+
$this->assertInternalType('string', $query);
470+
});
471+
}
472+
473+
/**
474+
* @eris-ratio 0.1
475+
* @eris-repeat 5
476+
*/
477+
public function testKeysQueryViewGetsSpecificKeysFromView()
478+
{
479+
$this->forAll(
480+
Generator\constant('testdb'),
481+
Generator\elements('id-designdoc', 'rev-designdoc'),
482+
Generator\constant('map'),
483+
Generator\associative([
484+
'keys' => Generator\tuple(
485+
Generator\suchThat(self::idConst, Generator\string())
486+
)
487+
]),
488+
Generator\associative([
489+
'descending' => Generator\elements('true', 'false'),
490+
'include_docs' => Generator\elements('true', 'false'),
491+
'group' => Generator\elements('true', 'false')
492+
])
493+
)
494+
->then(function (string $database, string $ddoc, string $view, array $keys, array $opts) {
495+
$promise = $this->action->keysQueryView($database, $ddoc, $view, $keys, $opts);
496+
$query = self::blockFn()($promise, $this->eventLoop);
497+
498+
$this->assertInstanceOf(\React\Promise\Promise::class, $promise);
499+
$this->assertInternalType('string', $query);
500+
});
501+
}
448502
}

0 commit comments

Comments
 (0)