1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace TBolier\RethinkQL\IntegrationTest\Query; |
5
|
|
|
|
6
|
|
|
use TBolier\RethinkQL\Query\RowInterface; |
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(RowInterface::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(RowInterface::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(RowInterface::class, $row); |
57
|
|
|
$this->assertArraySubset($this->equalsParsedQuery(TermType::NE, $dateTime), $row->toArray()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @throws \Exception |
62
|
|
|
*/ |
63
|
|
|
public function testRowWithDateMultipleLogic(): void |
64
|
|
|
{ |
65
|
|
|
$yesterday = new \DateTime('-1 days'); |
66
|
|
|
$tomorrow = new \DateTime('+1 days'); |
67
|
|
|
$this->insertDocumentWithDate(1, $yesterday); |
68
|
|
|
$this->insertDocumentWithDate(2, $tomorrow); |
69
|
|
|
|
70
|
|
|
/** @var ResponseInterface $res */ |
71
|
|
|
$row = $this->r()->row('date')->eq($yesterday->format(\DateTime::ATOM))->and( |
72
|
|
|
$this->r()->row('date')->ne($tomorrow->format(\DateTime::ATOM))->and( |
73
|
|
|
$this->r()->row('id')->eq(1)->and( |
74
|
|
|
$this->r()->row('id')->ne(2) |
75
|
|
|
) |
76
|
|
|
) |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$this->assertInstanceOf(RowInterface::class, $row); |
80
|
|
|
$this->assertArraySubset( |
81
|
|
|
[ |
82
|
|
|
TermType::FUNC, |
83
|
|
|
[ |
84
|
|
|
[TermType::MAKE_ARRAY, [TermType::DATUM]], |
85
|
|
|
[ |
86
|
|
|
TermType::AND, |
87
|
|
|
[ |
88
|
|
|
[ |
89
|
|
|
TermType::EQ, |
90
|
|
|
[ |
91
|
|
|
[TermType::GET_FIELD, [[TermType::IMPLICIT_VAR, []], "date"]], |
92
|
|
|
$yesterday->format(\DateTime::ATOM), |
93
|
|
|
], |
94
|
|
|
], |
95
|
|
|
[ |
96
|
|
|
TermType::NE, |
97
|
|
|
[ |
98
|
|
|
[TermType::GET_FIELD, [[TermType::IMPLICIT_VAR, []], "date"]], |
99
|
|
|
$tomorrow->format(\DateTime::ATOM), |
100
|
|
|
], |
101
|
|
|
], |
102
|
|
|
], |
103
|
|
|
], |
104
|
|
|
], |
105
|
|
|
], |
106
|
|
|
$row->toArray() |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param int $funcType |
112
|
|
|
* @param $dateTime |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
|
|
private function equalsParsedQuery(int $funcType, $dateTime): array |
116
|
|
|
{ |
117
|
|
|
return [ |
118
|
|
|
TermType::FUNC, |
119
|
|
|
[ |
120
|
|
|
[ |
121
|
|
|
TermType::MAKE_ARRAY, |
122
|
|
|
[ |
123
|
|
|
TermType::DATUM, |
124
|
|
|
], |
125
|
|
|
], |
126
|
|
|
[ |
127
|
|
|
$funcType, |
128
|
|
|
[ |
129
|
|
|
[ |
130
|
|
|
TermType::GET_FIELD, |
131
|
|
|
[ |
132
|
|
|
[ |
133
|
|
|
TermType::IMPLICIT_VAR, |
134
|
|
|
[], |
135
|
|
|
], |
136
|
|
|
'date', |
137
|
|
|
], |
138
|
|
|
], |
139
|
|
|
$dateTime, |
140
|
|
|
], |
141
|
|
|
], |
142
|
|
|
], |
143
|
|
|
]; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|