1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace TBolier\RethinkQL\IntegrationTest\Query; |
5
|
|
|
|
6
|
|
|
use TBolier\RethinkQL\Query\Logic\FuncLogic; |
7
|
|
|
use TBolier\RethinkQL\Response\ResponseInterface; |
8
|
|
|
use TBolier\RethinkQL\Types\Term\TermType; |
9
|
|
|
|
10
|
|
|
class RowTest extends AbstractTableTest |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @throws \Exception |
14
|
|
|
*/ |
15
|
|
|
public function testRowWithDateGreaterThanLogic(): void |
16
|
|
|
{ |
17
|
|
|
$this->insertDocumentWithDate(1, new \DateTime('-1 days')); |
18
|
|
|
$this->insertDocumentWithDate(2, new \DateTime('+1 days')); |
19
|
|
|
|
20
|
|
|
/** @var ResponseInterface $res */ |
21
|
|
|
$dateTime = (new \DateTime('now'))->format(\DateTime::ATOM); |
22
|
|
|
$row = $this->r()->row('date')->gt($dateTime); |
23
|
|
|
|
24
|
|
|
$this->assertInstanceOf(FuncLogic::class, $row); |
25
|
|
|
$this->assertArraySubset($this->equalsParsedQuery(TermType::GT, $dateTime), $row->toArray()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @throws \Exception |
30
|
|
|
*/ |
31
|
|
|
public function testRowWithDateEqualLogic(): void |
32
|
|
|
{ |
33
|
|
|
$this->insertDocumentWithDate(1, new \DateTime('-1 days')); |
34
|
|
|
$this->insertDocumentWithDate(2, new \DateTime('+1 days')); |
35
|
|
|
|
36
|
|
|
/** @var ResponseInterface $res */ |
37
|
|
|
$dateTime = (new \DateTime('now'))->format(\DateTime::ATOM); |
38
|
|
|
$row = $this->r()->row('date')->eq($dateTime); |
39
|
|
|
|
40
|
|
|
$this->assertInstanceOf(FuncLogic::class, $row); |
41
|
|
|
$this->assertArraySubset($this->equalsParsedQuery(TermType::EQ, $dateTime), $row->toArray()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @throws \Exception |
46
|
|
|
*/ |
47
|
|
|
public function testRowWithDateNotEqualLogic(): void |
48
|
|
|
{ |
49
|
|
|
$this->insertDocumentWithDate(1, new \DateTime('-1 days')); |
50
|
|
|
$this->insertDocumentWithDate(2, new \DateTime('+1 days')); |
51
|
|
|
|
52
|
|
|
/** @var ResponseInterface $res */ |
53
|
|
|
$dateTime = (new \DateTime('now'))->format(\DateTime::ATOM); |
54
|
|
|
$row = $this->r()->row('date')->ne($dateTime); |
55
|
|
|
|
56
|
|
|
$this->assertInstanceOf(FuncLogic::class, $row); |
57
|
|
|
$this->assertArraySubset($this->equalsParsedQuery(TermType::NE, $dateTime), $row->toArray()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param int $funcType |
62
|
|
|
* @param $dateTime |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
|
|
private function equalsParsedQuery(int $funcType, $dateTime): array |
66
|
|
|
{ |
67
|
|
|
return [ |
68
|
|
|
TermType::FUNC, |
69
|
|
|
[ |
70
|
|
|
[ |
71
|
|
|
TermType::MAKE_ARRAY, |
72
|
|
|
[ |
73
|
|
|
TermType::DATUM, |
74
|
|
|
], |
75
|
|
|
], |
76
|
|
|
[ |
77
|
|
|
$funcType, |
78
|
|
|
[ |
79
|
|
|
[ |
80
|
|
|
TermType::GET_FIELD, |
81
|
|
|
[ |
82
|
|
|
[ |
83
|
|
|
TermType::IMPLICIT_VAR, |
84
|
|
|
[], |
85
|
|
|
], |
86
|
|
|
'date', |
87
|
|
|
], |
88
|
|
|
], |
89
|
|
|
$dateTime, |
90
|
|
|
], |
91
|
|
|
], |
92
|
|
|
], |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|