Skip to content

Commit

Permalink
addressing #15 in latest release and cleaning up phpunit.xml...
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed May 14, 2018
1 parent 878f2cb commit 07387cc
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 126 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ install:
- composer install --no-interaction --no-progress --no-suggest --optimize-autoloader

script:
- ./vendor/bin/phpunit -c phpunit.xml.dist
- ./vendor/bin/phpunit -c phpunit.xml
54 changes: 0 additions & 54 deletions phpunit.local.xml

This file was deleted.

16 changes: 2 additions & 14 deletions phpunit.xml.dist → phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true"
stopOnFailure="true"
processIsolation="false"
backupGlobals="false"
>

<php>
Expand All @@ -22,21 +17,18 @@
<testsuite name="definition">
<directory>./tests/Definition</directory>
</testsuite>

<testsuite name="usage-config">
<file>./tests/Usage/ConfigUsageTest.php</file>
</testsuite>

<testsuite name="usage-request">
<file>./tests/Usage/RequestUsageTest.php</file>
</testsuite>

<testsuite name="usage-agent">
<file>./tests/Usage/Agent/AgentClientUsageTests.php</file>
<directory>./tests/Usage/Agent</directory>
</testsuite>

<testsuite name="usage-kv">
<file>./tests/usage/KV/KVClientCRUDTests.php</file>
<directory>./tests/Usage/KV</directory>
</testsuite>
</testsuites>

Expand All @@ -46,8 +38,4 @@
</whitelist>
</filter>

<logging>
<log type="plain" target="./tmp/tests/php-consul-api-tests.log"/>
</logging>

</phpunit>
47 changes: 34 additions & 13 deletions src/KV/KVClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
class KVClient extends AbstractClient {
/**
* @param string $key Name of key to retrieve value for
* @param string $key Name of key to retrieve value for
* @param \DCarbone\PHPConsulAPI\QueryOptions $options
* @return array(
* @type KVPair|null kv object or null on error
Expand Down Expand Up @@ -78,7 +78,7 @@ public function get($key, QueryOptions $options = null) {
}

/**
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
* @param \DCarbone\PHPConsulAPI\WriteOptions $options
* @return array(
* @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
Expand All @@ -101,7 +101,7 @@ public function put(KVPair $p, WriteOptions $options = null) {
}

/**
* @param string $key
* @param string $key
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $options
* @return array(
* @type \DCarbone\PHPConsulAPI\WriteMeta metadata about write
Expand All @@ -121,7 +121,7 @@ public function delete($key, WriteOptions $options = null) {
}

/**
* @param string $prefix
* @param string $prefix
* @param \DCarbone\PHPConsulAPI\QueryOptions|null $options
* @return array(
* @type KVPair[]|null array of KVPair objects under specified prefix
Expand Down Expand Up @@ -171,7 +171,7 @@ public function valueList($prefix = '', QueryOptions $options = null) {
}

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

/**
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
* @param \DCarbone\PHPConsulAPI\WriteOptions $options
* @return array(
* @type bool whether the operation succeeded or not
* @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
* )
Expand All @@ -225,17 +226,16 @@ public function cas(KVPair $p, WriteOptions $options = null) {
if (0 !== $p->Flags) {
$r->Params->set('flags', (string)$p->Flags);
}

list($duration, $_, $err) = $this->requireOK($this->doRequest($r));
/** @var \Psr\Http\Message\ResponseInterface $response */
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
if (null !== $err) {
return [null, $err];
}

return [$this->buildWriteMeta($duration), null];
return [0 === strpos($response->getBody()->getContents(), 'true'), $this->buildWriteMeta($duration), null];
}

/**
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
* @param \DCarbone\PHPConsulAPI\WriteOptions $options
* @return array(
* @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
Expand All @@ -259,7 +259,28 @@ public function acquire(KVPair $p, WriteOptions $options = null) {
}

/**
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $options
* @return array(
* @type bool
* @type \DCarbone\PHPConsulAPI\WriteMeta
* @type \DCarbone\PHPConsulAPI\Error|null
* )
*/
public function deleteCAS(KVPair $p, WriteOptions $options = null) {
$r = new Request('DELETE', sprintf('v1/kv/%s', ltrim($p->Key, "/")), $this->config);
$r->setWriteOptions($options);
$r->Params['cas'] = (string)$p->ModifyIndex;
/** @var \Psr\Http\Message\ResponseInterface $response */
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
if (null !== $err) {
return [null, null, $err];
}
return [0 === strpos($response->getBody()->getContents(), 'true'), $this->buildWriteMeta($duration), null];
}

/**
* @param \DCarbone\PHPConsulAPI\KV\KVPair $p
* @param \DCarbone\PHPConsulAPI\WriteOptions $options
* @return array(
* @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
Expand All @@ -283,7 +304,7 @@ public function release(KVPair $p, WriteOptions $options = null) {
}

/**
* @param null|string $prefix
* @param null|string $prefix
* @param \DCarbone\PHPConsulAPI\QueryOptions $options
* @return array(
* @type KVPair[]|KVTree[]|null array of trees, values, or null on error
Expand Down
Loading

0 comments on commit 07387cc

Please sign in to comment.