Skip to content

Commit d02d121

Browse files
committed
rest of the tests implemented
1 parent b3ac936 commit d02d121

22 files changed

+1316
-481
lines changed

src/Documents/Indexes/IndexDefinitionHelper.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use RavenDB\Exceptions\IllegalArgumentException;
66
use RavenDB\Utils\StringUtils;
77

8-
// !status: DONE
98
class IndexDefinitionHelper
109
{
1110
public static function detectStaticIndexType(string $map, ?string $reduce): IndexType
@@ -61,7 +60,6 @@ public static function detectStaticIndexSourceType(?string $map): IndexSourceTyp
6160
if (str_starts_with($map, "from")) {
6261
// detect `from ts in timeseries` or `from ts in timeseries.Users.HeartRate`
6362

64-
// @todo: following five lines of code should be tested
6563
$tokens = [];
6664
foreach (explode(' ', $mapLower) as $item) {
6765
if (StringUtils::isNotEmpty($item)) {
@@ -83,17 +81,13 @@ public static function detectStaticIndexSourceType(?string $map): IndexSourceTyp
8381
return IndexSourceType::documents();
8482
}
8583

86-
// @todo: implement and this code should be tested
8784
private static function stripComments(string $input): string
8885
{
89-
return $input;
90-
// return trim(preg_replace("(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)","", $input));
86+
return trim(preg_replace('~(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/)|(?://.*)~',"", $input));
9187
}
9288

93-
// @todo: implement and this code should be tested
9489
private static function unifyWhiteSpace(string $input): string
9590
{
96-
return $input;
97-
// return preg_replace("\\s+", " ", $input);
91+
return preg_replace("/\s+/", " ", $input);
9892
}
9993
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace RavenDB\Documents\Operations\TimeSeries;
4+
5+
class ConfigureRawTimeSeriesPolicyOperation extends ConfigureTimeSeriesPolicyOperation
6+
{
7+
public function __construct(?string $collection, ?RawTimeSeriesPolicy $config) {
8+
parent::__construct($collection, $config);
9+
}
10+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace RavenDB\Documents\Operations\TimeSeries;
4+
5+
use RavenDB\Exceptions\IllegalArgumentException;
6+
use RavenDB\Http\HttpRequest;
7+
use RavenDB\Http\HttpRequestInterface;
8+
use RavenDB\Http\RaftCommandInterface;
9+
use RavenDB\Http\RavenCommand;
10+
use RavenDB\Http\ServerNode;
11+
use RavenDB\Utils\RaftIdGenerator;
12+
13+
class ConfigureTimeSeriesPolicyCommand extends RavenCommand implements RaftCommandInterface
14+
{
15+
private ?string $collection = null;
16+
private ?TimeSeriesPolicy $configuration = null;
17+
18+
public function __construct(?string $collection, ?TimeSeriesPolicy $configuration)
19+
{
20+
parent::__construct(ConfigureTimeSeriesOperationResult::class);
21+
22+
if ($configuration == null) {
23+
throw new IllegalArgumentException("Configuration cannot be null");
24+
}
25+
26+
if ($collection == null) {
27+
throw new IllegalArgumentException("Collection cannot be null");
28+
}
29+
30+
$this->collection = $collection;
31+
$this->configuration = $configuration;
32+
}
33+
34+
public function getRaftUniqueRequestId(): string
35+
{
36+
return RaftIdGenerator::newId();
37+
}
38+
39+
public function isReadRequest(): bool
40+
{
41+
return false;
42+
}
43+
44+
public function createUrl(ServerNode $serverNode): string
45+
{
46+
return $serverNode->getUrl() . "/databases/" . $serverNode->getDatabase() . "/admin/timeseries/policy?collection=" . urlEncode($this->collection);
47+
}
48+
49+
public function createRequest(ServerNode $serverNode): HttpRequestInterface
50+
{
51+
$options = [
52+
'json' => $this->getMapper()->normalize($this->configuration),
53+
'headers' => [
54+
'Content-Type' => 'application/json'
55+
]
56+
];
57+
58+
return new HttpRequest($this->createUrl($serverNode), HttpRequest::PUT, $options);
59+
}
60+
61+
public function setResponse(?string $response, bool $fromCache): void
62+
{
63+
if ($response == null) {
64+
$this->throwInvalidResponse();
65+
}
66+
67+
$this->result = $this->getMapper()->deserialize($response, $this->resultClass, 'json');
68+
}
69+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace RavenDB\Documents\Operations\TimeSeries;
4+
5+
use RavenDB\Documents\Conventions\DocumentConventions;
6+
use RavenDB\Documents\Operations\MaintenanceOperationInterface;
7+
use RavenDB\Http\RavenCommand;
8+
9+
class ConfigureTimeSeriesPolicyOperation implements MaintenanceOperationInterface
10+
{
11+
private ?string $collection = null;
12+
private ?TimeSeriesPolicy $config = null;
13+
14+
public function __construct(?string $collection, ?TimeSeriesPolicy $config)
15+
{
16+
$this->collection = $collection;
17+
$this->config = $config;
18+
}
19+
20+
public function getCommand(DocumentConventions $conventions): RavenCommand
21+
{
22+
return new ConfigureTimeSeriesPolicyCommand($this->collection, $this->config);
23+
}
24+
}

src/Documents/Operations/TimeSeries/ConfigureTimeSeriesValueNamesParameters.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public function getValueNames(): ?StringArray
5959
return $this->valueNames;
6060
}
6161

62-
public function setValueNames(?StringArray $valueNames): void
62+
public function setValueNames(null|array|StringArray $valueNames): void
6363
{
64-
$this->valueNames = $valueNames;
64+
$this->valueNames = is_array($valueNames) ? StringArray::fromArray($valueNames) : $valueNames;
6565
}
6666

6767
public function isUpdate(): bool

src/Documents/Operations/TimeSeries/GetMultipleTimeSeriesCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class GetMultipleTimeSeriesCommand extends RavenCommand
2121
private ?int $pageSize = null;
2222
private ?Closure $includes = null;
2323

24-
public function __construct(?string $docId, ?TimeSeriesRangeList $ranges, int $start, int $pageSize, ?Closure $includes = null)
24+
public function __construct(?string $docId, null|TimeSeriesRangeList|array $ranges, int $start, int $pageSize, ?Closure $includes = null)
2525
{
2626
parent::__construct(TimeSeriesDetails::class);
2727

@@ -30,7 +30,9 @@ public function __construct(?string $docId, ?TimeSeriesRangeList $ranges, int $s
3030
}
3131

3232
$this->docId = $docId;
33-
$this->ranges = $ranges;
33+
if ($ranges != null) {
34+
$this->ranges = TimeSeriesRangeList::ensure($ranges);
35+
}
3436
$this->start = $start;
3537
$this->pageSize = $pageSize;
3638
$this->includes = $includes;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace RavenDB\Documents\Operations\TimeSeries;
4+
5+
use RavenDB\Http\HttpRequest;
6+
use RavenDB\Http\HttpRequestInterface;
7+
use RavenDB\Http\RaftCommandInterface;
8+
use RavenDB\Http\RavenCommand;
9+
use RavenDB\Http\ServerNode;
10+
use RavenDB\Utils\RaftIdGenerator;
11+
12+
class RemoveTimeSeriesPolicyCommand extends RavenCommand implements RaftCommandInterface
13+
{
14+
private ?string $collection = null;
15+
private ?string $name = null;
16+
17+
public function __construct(?string $collection, ?string $name)
18+
{
19+
parent::__construct(ConfigureTimeSeriesOperationResult::class);
20+
21+
$this->collection = $collection;
22+
$this->name = $name;
23+
}
24+
public function getRaftUniqueRequestId(): string
25+
{
26+
return RaftIdGenerator::newId();
27+
}
28+
29+
public function isReadRequest(): bool
30+
{
31+
return false;
32+
}
33+
34+
public function createUrl(ServerNode $serverNode): string
35+
{
36+
return $serverNode->getUrl() . "/databases/" . $serverNode->getDatabase()
37+
. "/admin/timeseries/policy?collection=" . urlEncode($this->collection) . "&name=" . urlEncode($this->name);
38+
}
39+
40+
public function createRequest(ServerNode $serverNode): HttpRequestInterface
41+
{
42+
return new HttpRequest($this->createUrl($serverNode), HttpRequest::DELETE);
43+
}
44+
45+
public function setResponse(?string $response, bool $fromCache): void
46+
{
47+
if ($response == null) {
48+
$this->throwInvalidResponse();
49+
}
50+
51+
$this->result = $this->getMapper()->deserialize($response,$this->resultClass, 'json');
52+
}
53+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace RavenDB\Documents\Operations\TimeSeries;
4+
5+
use RavenDB\Documents\Conventions\DocumentConventions;
6+
use RavenDB\Documents\Operations\MaintenanceOperationInterface;
7+
use RavenDB\Exceptions\IllegalArgumentException;
8+
use RavenDB\Http\RavenCommand;
9+
10+
class RemoveTimeSeriesPolicyOperation implements MaintenanceOperationInterface
11+
{
12+
private ?string $collection = null;
13+
private ?string $name = null;
14+
15+
public function __construct(?string $collection, ?string $name)
16+
{
17+
if ($collection == null) {
18+
throw new IllegalArgumentException("Collection cannot be null");
19+
}
20+
if ($name == null) {
21+
throw new IllegalArgumentException("Name cannot be null");
22+
}
23+
24+
$this->collection = $collection;
25+
$this->name = $name;
26+
}
27+
28+
public function getCommand(DocumentConventions $conventions): RavenCommand
29+
{
30+
return new RemoveTimeSeriesPolicyCommand($this->collection, $this->name);
31+
}
32+
}

src/Documents/Operations/TimeSeries/TimeSeriesConfiguration.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ public function getNames(string $collection, string $timeSeries): ?array
8181
if (!$this->namedValues->offsetExists($collection)) {
8282
return null;
8383
}
84-
$timeSeriesHolder = $this->namedValues[$collection];
84+
$timeSeriesHolder = array_change_key_case($this->namedValues[$collection], CASE_LOWER);
8585

86-
if (!array_key_exists($timeSeries, $timeSeriesHolder)) {
86+
$timeSeriesLowerCase = strtolower($timeSeries);
87+
if (!array_key_exists($timeSeriesLowerCase, $timeSeriesHolder)) {
8788
return null;
8889
}
89-
return $timeSeriesHolder[$timeSeries];
90+
return $timeSeriesHolder[$timeSeriesLowerCase];
9091
}
9192

9293
private function internalPostJsonDeserialization(): void

0 commit comments

Comments
 (0)