Skip to content

Commit 07387cc

Browse files
committed
addressing #15 in latest release and cleaning up phpunit.xml...
1 parent 878f2cb commit 07387cc

File tree

6 files changed

+161
-126
lines changed

6 files changed

+161
-126
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ install:
2222
- composer install --no-interaction --no-progress --no-suggest --optimize-autoloader
2323

2424
script:
25-
- ./vendor/bin/phpunit -c phpunit.xml.dist
25+
- ./vendor/bin/phpunit -c phpunit.xml

phpunit.local.xml

-54
This file was deleted.

phpunit.xml.dist renamed to phpunit.xml

+2-14
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
55
bootstrap="./vendor/autoload.php"
66
colors="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
107
verbose="true"
118
stopOnFailure="true"
12-
processIsolation="false"
13-
backupGlobals="false"
149
>
1510

1611
<php>
@@ -22,21 +17,18 @@
2217
<testsuite name="definition">
2318
<directory>./tests/Definition</directory>
2419
</testsuite>
25-
2620
<testsuite name="usage-config">
2721
<file>./tests/Usage/ConfigUsageTest.php</file>
2822
</testsuite>
29-
3023
<testsuite name="usage-request">
3124
<file>./tests/Usage/RequestUsageTest.php</file>
3225
</testsuite>
3326

3427
<testsuite name="usage-agent">
35-
<file>./tests/Usage/Agent/AgentClientUsageTests.php</file>
28+
<directory>./tests/Usage/Agent</directory>
3629
</testsuite>
37-
3830
<testsuite name="usage-kv">
39-
<file>./tests/usage/KV/KVClientCRUDTests.php</file>
31+
<directory>./tests/Usage/KV</directory>
4032
</testsuite>
4133
</testsuites>
4234

@@ -46,8 +38,4 @@
4638
</whitelist>
4739
</filter>
4840

49-
<logging>
50-
<log type="plain" target="./tmp/tests/php-consul-api-tests.log"/>
51-
</logging>
52-
5341
</phpunit>

src/KV/KVClient.php

+34-13
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class KVClient extends AbstractClient {
3030
/**
31-
* @param string $key Name of key to retrieve value for
31+
* @param string $key Name of key to retrieve value for
3232
* @param \DCarbone\PHPConsulAPI\QueryOptions $options
3333
* @return array(
3434
* @type KVPair|null kv object or null on error
@@ -78,7 +78,7 @@ public function get($key, QueryOptions $options = null) {
7878
}
7979

8080
/**
81-
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
81+
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
8282
* @param \DCarbone\PHPConsulAPI\WriteOptions $options
8383
* @return array(
8484
* @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
@@ -101,7 +101,7 @@ public function put(KVPair $p, WriteOptions $options = null) {
101101
}
102102

103103
/**
104-
* @param string $key
104+
* @param string $key
105105
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $options
106106
* @return array(
107107
* @type \DCarbone\PHPConsulAPI\WriteMeta metadata about write
@@ -121,7 +121,7 @@ public function delete($key, WriteOptions $options = null) {
121121
}
122122

123123
/**
124-
* @param string $prefix
124+
* @param string $prefix
125125
* @param \DCarbone\PHPConsulAPI\QueryOptions|null $options
126126
* @return array(
127127
* @type KVPair[]|null array of KVPair objects under specified prefix
@@ -171,7 +171,7 @@ public function valueList($prefix = '', QueryOptions $options = null) {
171171
}
172172

173173
/**
174-
* @param string $prefix Prefix to search for. Null returns all keys.
174+
* @param string $prefix Prefix to search for. Null returns all keys.
175175
* @param \DCarbone\PHPConsulAPI\QueryOptions $options
176176
* @return array(
177177
* @type string[]|null list of keys
@@ -211,9 +211,10 @@ public function keys($prefix = null, QueryOptions $options = null) {
211211
}
212212

213213
/**
214-
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
214+
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
215215
* @param \DCarbone\PHPConsulAPI\WriteOptions $options
216216
* @return array(
217+
* @type bool whether the operation succeeded or not
217218
* @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
218219
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
219220
* )
@@ -225,17 +226,16 @@ public function cas(KVPair $p, WriteOptions $options = null) {
225226
if (0 !== $p->Flags) {
226227
$r->Params->set('flags', (string)$p->Flags);
227228
}
228-
229-
list($duration, $_, $err) = $this->requireOK($this->doRequest($r));
229+
/** @var \Psr\Http\Message\ResponseInterface $response */
230+
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
230231
if (null !== $err) {
231232
return [null, $err];
232233
}
233-
234-
return [$this->buildWriteMeta($duration), null];
234+
return [0 === strpos($response->getBody()->getContents(), 'true'), $this->buildWriteMeta($duration), null];
235235
}
236236

237237
/**
238-
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
238+
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
239239
* @param \DCarbone\PHPConsulAPI\WriteOptions $options
240240
* @return array(
241241
* @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
@@ -259,7 +259,28 @@ public function acquire(KVPair $p, WriteOptions $options = null) {
259259
}
260260

261261
/**
262-
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
262+
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
263+
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $options
264+
* @return array(
265+
* @type bool
266+
* @type \DCarbone\PHPConsulAPI\WriteMeta
267+
* @type \DCarbone\PHPConsulAPI\Error|null
268+
* )
269+
*/
270+
public function deleteCAS(KVPair $p, WriteOptions $options = null) {
271+
$r = new Request('DELETE', sprintf('v1/kv/%s', ltrim($p->Key, "/")), $this->config);
272+
$r->setWriteOptions($options);
273+
$r->Params['cas'] = (string)$p->ModifyIndex;
274+
/** @var \Psr\Http\Message\ResponseInterface $response */
275+
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
276+
if (null !== $err) {
277+
return [null, null, $err];
278+
}
279+
return [0 === strpos($response->getBody()->getContents(), 'true'), $this->buildWriteMeta($duration), null];
280+
}
281+
282+
/**
283+
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
263284
* @param \DCarbone\PHPConsulAPI\WriteOptions $options
264285
* @return array(
265286
* @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
@@ -283,7 +304,7 @@ public function release(KVPair $p, WriteOptions $options = null) {
283304
}
284305

285306
/**
286-
* @param null|string $prefix
307+
* @param null|string $prefix
287308
* @param \DCarbone\PHPConsulAPI\QueryOptions $options
288309
* @return array(
289310
* @type KVPair[]|KVTree[]|null array of trees, values, or null on error

0 commit comments

Comments
 (0)