|
5 | 5 |
|
6 | 6 | namespace Palicao\PhpRedisTimeSeries\Tests\Integration;
|
7 | 7 |
|
| 8 | +use DateInterval; |
| 9 | +use DateTime; |
8 | 10 | use DateTimeImmutable;
|
9 | 11 | use Palicao\PhpRedisTimeSeries\AggregationRule;
|
| 12 | +use Palicao\PhpRedisTimeSeries\DateTimeUtils; |
10 | 13 | use Palicao\PhpRedisTimeSeries\Filter;
|
11 | 14 | use Palicao\PhpRedisTimeSeries\Label;
|
12 | 15 | use Palicao\PhpRedisTimeSeries\RedisClient;
|
@@ -150,4 +153,64 @@ public function testAddAndRetrieveKeysWithMultipleFilters(): void
|
150 | 153 | $this->assertEquals($expectedResult, $range);
|
151 | 154 | }
|
152 | 155 |
|
| 156 | + public function testAddAndRetrieveWithDateTimeObjectAsMultiRangeWithMultipleFilters(): void |
| 157 | + { |
| 158 | + $currentDate = new DateTime(); |
| 159 | + $from = $currentDate->sub(new DateInterval('P1D')); |
| 160 | + $to = $currentDate; |
| 161 | + |
| 162 | + $this->sut->create( |
| 163 | + 'temperature:3:11', |
| 164 | + 6000, |
| 165 | + [new Label('sensor_id', '2'), new Label('area_id', '32')] |
| 166 | + ); |
| 167 | + $this->sut->add(new Sample('temperature:3:11', 30, $from)); |
| 168 | + $this->sut->add(new Sample('temperature:3:11', 42, $to)); |
| 169 | + |
| 170 | + $filter = new Filter('sensor_id', '2'); |
| 171 | + $filter->add('area_id', Filter::OP_EQUALS, '32'); |
| 172 | + |
| 173 | + $range = $this->sut->multiRange($filter); |
| 174 | + |
| 175 | + $expectedRange = [ |
| 176 | + Sample::createFromTimestamp('temperature:3:11', (float)42, DateTimeUtils::timestampWithMsFromDateTime(new DateTimeImmutable($to->format('Y-m-d H:i:s.u')))) |
| 177 | + ]; |
| 178 | + |
| 179 | + $this->assertEquals($expectedRange, $range); |
| 180 | + } |
| 181 | + |
| 182 | + |
| 183 | + public function testAddAndRetrieveWithDateTimeObjectAsRange(): void |
| 184 | + { |
| 185 | + $from = new DateTimeImmutable('2019-11-06 20:34:17.103000'); |
| 186 | + $to = new DateTimeImmutable('2019-11-06 20:34:17.107000'); |
| 187 | + |
| 188 | + $this->sut->create( |
| 189 | + 'temperature:3:11', |
| 190 | + null, |
| 191 | + [new Label('sensor_id', '2'), new Label('area_id', '32')] |
| 192 | + ); |
| 193 | + |
| 194 | + $this->sut->add(new Sample('temperature:3:11', 30, $from)); |
| 195 | + $this->sut->add(new Sample('temperature:3:11', 42, $to)); |
| 196 | + |
| 197 | + $range = $this->sut->range( |
| 198 | + 'temperature:3:11' |
| 199 | + ); |
| 200 | + |
| 201 | + $expectedRange = [ |
| 202 | + Sample::createFromTimestamp( |
| 203 | + 'temperature:3:11', |
| 204 | + (float)30, |
| 205 | + DateTimeUtils::timestampWithMsFromDateTime(new DateTimeImmutable($from->format('Y-m-d H:i:s.u'))) |
| 206 | + ), |
| 207 | + Sample::createFromTimestamp( |
| 208 | + 'temperature:3:11', |
| 209 | + (float)42, |
| 210 | + DateTimeUtils::timestampWithMsFromDateTime(new DateTimeImmutable($to->format('Y-m-d H:i:s.u'))) |
| 211 | + ), |
| 212 | + ]; |
| 213 | + |
| 214 | + $this->assertEquals($expectedRange, $range); |
| 215 | + } |
153 | 216 | }
|
0 commit comments