Skip to content

Commit 29620e4

Browse files
committed
Add integration tests
1 parent b9b6311 commit 29620e4

File tree

13 files changed

+321
-16
lines changed

13 files changed

+321
-16
lines changed

src/Query/Aggregation/AbstractAggregation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
namespace TBolier\RethinkQL\Query\Aggregation;
55

6+
use TBolier\RethinkQL\Query\AbstractQuery;
67
use TBolier\RethinkQL\Query\QueryInterface;
7-
use TBolier\RethinkQL\Query\Transformation\AbstractTransformation;
88

9-
abstract class AbstractAggregation extends AbstractTransformation implements AggregationInterface
9+
abstract class AbstractAggregation extends AbstractQuery implements AggregationInterface
1010
{
1111
/**
1212
* @inheritdoc
@@ -19,15 +19,15 @@ public function count(): QueryInterface
1919
/**
2020
* @inheritdoc
2121
*/
22-
public function sum($key): AggregationInterface
22+
public function sum($key): QueryInterface
2323
{
2424
return new Sum($this->rethink, $this->message, $this, $key);
2525
}
2626

2727
/**
2828
* @inheritdoc
2929
*/
30-
public function avg($key): AggregationInterface
30+
public function avg($key): QueryInterface
3131
{
3232
return new Avg($this->rethink, $this->message, $this, $key);
3333
}

src/Query/Aggregation/AggregationInterface.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
namespace TBolier\RethinkQL\Query\Aggregation;
55

66
use TBolier\RethinkQL\Query\QueryInterface;
7-
use TBolier\RethinkQL\Query\Transformation\TransformationInterface;
87
use TBolier\RethinkQL\Response\ResponseInterface;
98

10-
interface AggregationInterface extends TransformationInterface
9+
interface AggregationInterface
1110
{
1211
/**
1312
* @return QueryInterface
@@ -16,15 +15,15 @@ public function count(): QueryInterface;
1615

1716
/**
1817
* @param string $key
19-
* @return AggregationInterface
18+
* @return QueryInterface
2019
*/
21-
public function sum($key): AggregationInterface;
20+
public function sum($key): QueryInterface;
2221

2322
/**
2423
* @param string $key
25-
* @return AggregationInterface
24+
* @return QueryInterface
2625
*/
27-
public function avg($key): AggregationInterface;
26+
public function avg($key): QueryInterface;
2827

2928
/**
3029
* @param string $key

src/Query/Operation/Filter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
use TBolier\RethinkQL\Message\MessageInterface;
77
use TBolier\RethinkQL\Query\QueryInterface;
8+
use TBolier\RethinkQL\Query\Transformation\AbstractTransformationCompound;
89
use TBolier\RethinkQL\RethinkInterface;
910
use TBolier\RethinkQL\Types\Term\TermType;
1011

11-
class Filter extends AbstractOperation
12+
class Filter extends AbstractTransformationCompound
1213
{
1314
/**
1415
* @var array

src/Query/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
namespace TBolier\RethinkQL\Query;
55

66
use TBolier\RethinkQL\Message\MessageInterface;
7-
use TBolier\RethinkQL\Query\Operation\AbstractOperation;
87
use TBolier\RethinkQL\Query\Operation\Get;
98
use TBolier\RethinkQL\Query\Operation\IndexCreate;
109
use TBolier\RethinkQL\Query\Operation\IndexDrop;
1110
use TBolier\RethinkQL\Query\Operation\IndexList;
1211
use TBolier\RethinkQL\Query\Operation\IndexRename;
12+
use TBolier\RethinkQL\Query\Transformation\AbstractTransformationCompound;
1313
use TBolier\RethinkQL\RethinkInterface;
1414
use TBolier\RethinkQL\Types\Term\TermType;
1515

16-
class Table extends AbstractOperation implements TableInterface
16+
class Table extends AbstractTransformationCompound implements TableInterface
1717
{
1818
/**
1919
* @var array

src/Query/TableInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
namespace TBolier\RethinkQL\Query;
55

66
use TBolier\RethinkQL\Query\Operation\OperationInterface;
7+
use TBolier\RethinkQL\Query\Transformation\TransformationInterface;
78

8-
interface TableInterface extends OperationInterface
9+
interface TableInterface extends OperationInterface, TransformationInterface
910
{
1011
/**
1112
* @param string|int $key
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace TBolier\RethinkQL\Query\Transformation;
5+
6+
use TBolier\RethinkQL\Query\Operation\AbstractOperation;
7+
use TBolier\RethinkQL\Query\QueryInterface;
8+
9+
abstract class AbstractTransformationCompound extends AbstractOperation implements TransformationInterface
10+
{
11+
/**
12+
* @inheritdoc
13+
*/
14+
public function isEmpty(): QueryInterface
15+
{
16+
return new IsEmpty($this->rethink, $this->message, $this);
17+
}
18+
19+
/**
20+
* @inheritdoc
21+
*/
22+
public function limit($value): TransformationInterface
23+
{
24+
return new Limit($this->rethink, $this->message, $this, $value);
25+
}
26+
27+
/**
28+
* @inheritdoc
29+
*/
30+
public function skip($value): TransformationInterface
31+
{
32+
return new Skip($this->rethink, $this->message, $this, $value);
33+
}
34+
35+
/**
36+
* @inheritdoc
37+
*/
38+
public function orderBy($key): TransformationInterface
39+
{
40+
return new OrderBy($this->rethink, $this->message, $this, $key);
41+
}
42+
}

test/integration/Aggregation/AvgTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,48 @@ public function testAvg(): void
2828

2929
$this->assertTrue(is_float($res->getData()) || is_int($res->getData()));
3030
}
31+
32+
/**
33+
* @return void
34+
* @throws \Exception
35+
*/
36+
public function testFilterAndAvg(): void
37+
{
38+
$this->insertDocument(5);
39+
$this->insertDocument(4);
40+
$this->insertDocument(3);
41+
$this->insertDocument(2);
42+
$this->insertDocument(1);
43+
44+
/** @var ResponseInterface $res */
45+
$res = $this->r()
46+
->table('tabletest')
47+
->filter(['description' => 'A document description.'])
48+
->avg('number')
49+
->run();
50+
51+
$this->assertTrue(is_float($res->getData()) || is_int($res->getData()));
52+
}
53+
54+
/**
55+
* @return void
56+
* @throws \Exception
57+
*/
58+
public function testGetAllAndAvg(): void
59+
{
60+
$this->insertDocument(5);
61+
$this->insertDocument(4);
62+
$this->insertDocument(3);
63+
$this->insertDocument(2);
64+
$this->insertDocument(1);
65+
66+
/** @var ResponseInterface $res */
67+
$res = $this->r()
68+
->table('tabletest')
69+
->getAll(1, 2, 3, 4, 5)
70+
->avg('number')
71+
->run();
72+
73+
$this->assertTrue(is_float($res->getData()) || is_int($res->getData()));
74+
}
3175
}

test/integration/Aggregation/CountTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,28 @@ public function testCount()
2626
/**
2727
* @throws \Exception
2828
*/
29-
public function testFilterCount()
29+
public function testGetAllAndCount()
30+
{
31+
$this->insertDocument(1);
32+
$this->insertDocument(2);
33+
$this->insertDocument(3);
34+
$this->insertDocument(4);
35+
$this->insertDocument(5);
36+
37+
/** @var ResponseInterface $res */
38+
$res = $this->r()
39+
->table('tabletest')
40+
->getAll(1, 2, 3, 4, 5)
41+
->count()
42+
->run();
43+
44+
$this->assertEquals(5, $res->getData());
45+
}
46+
47+
/**
48+
* @throws \Exception
49+
*/
50+
public function testFilterAndCount()
3051
{
3152
$this->insertDocument(1);
3253
$this->insertDocument(2);
@@ -47,7 +68,7 @@ public function testFilterCount()
4768
/**
4869
* @throws \Exception
4970
*/
50-
public function testFilterCountOnMultipleDocuments()
71+
public function testFilterAndCountMultiple()
5172
{
5273
$this->insertDocument(1);
5374
$this->insertDocument(2);

test/integration/Aggregation/SumTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,48 @@ public function testSum(): void
2828

2929
$this->assertInternalType('int', $res->getData());
3030
}
31+
32+
/**
33+
* @return void
34+
* @throws \Exception
35+
*/
36+
public function testFilterAndSum(): void
37+
{
38+
$this->insertDocument(5);
39+
$this->insertDocument(4);
40+
$this->insertDocument(3);
41+
$this->insertDocument(2);
42+
$this->insertDocument(1);
43+
44+
/** @var ResponseInterface $res */
45+
$res = $this->r()
46+
->table('tabletest')
47+
->filter(['description' => 'A document description.'])
48+
->sum('number')
49+
->run();
50+
51+
$this->assertInternalType('int', $res->getData());
52+
}
53+
54+
/**
55+
* @return void
56+
* @throws \Exception
57+
*/
58+
public function testGetAllAndSum(): void
59+
{
60+
$this->insertDocument(5);
61+
$this->insertDocument(4);
62+
$this->insertDocument(3);
63+
$this->insertDocument(2);
64+
$this->insertDocument(1);
65+
66+
/** @var ResponseInterface $res */
67+
$res = $this->r()
68+
->table('tabletest')
69+
->getAll(1, 2, 3, 4, 5)
70+
->sum('number')
71+
->run();
72+
73+
$this->assertInternalType('int', $res->getData());
74+
}
3175
}

test/integration/Query/FilterTest.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace TBolier\RethinkQL\IntegrationTest\Query;
55

66
use TBolier\RethinkQL\Response\Cursor;
7+
use TBolier\RethinkQL\Response\ResponseInterface;
78

89
class FilterTest extends AbstractTableTest
910
{
@@ -46,4 +47,96 @@ public function testFilterOnMultipleDocuments()
4647

4748
$this->assertCount(1, $cursor);
4849
}
50+
51+
/**
52+
* @throws \Exception
53+
*/
54+
public function testFilterAndAvg()
55+
{
56+
$this->insertDocument(1);
57+
$this->insertDocument(2);
58+
$this->insertDocument(3);
59+
$this->insertDocument(4);
60+
$this->insertDocument(5);
61+
62+
/** @var ResponseInterface $cursor */
63+
$res = $this->r()
64+
->table('tabletest')
65+
->filter(['title' => 'Test document 1'])
66+
->avg('number')
67+
->run();
68+
69+
$this->assertTrue(is_float($res->getData()) || is_int($res->getData()));
70+
}
71+
72+
/**
73+
* @throws \Exception
74+
*/
75+
public function testFilterAndSum()
76+
{
77+
$this->insertDocument(1);
78+
$this->insertDocument(2);
79+
$this->insertDocument(3);
80+
$this->insertDocument(4);
81+
$this->insertDocument(5);
82+
83+
/** @var ResponseInterface $cursor */
84+
$res = $this->r()
85+
->table('tabletest')
86+
->filter(['title' => 'Test document 1'])
87+
->sum('number')
88+
->run();
89+
90+
$this->assertTrue(is_float($res->getData()) || is_int($res->getData()));
91+
}
92+
93+
/**
94+
* @throws \Exception
95+
*/
96+
public function testFilterAndMin()
97+
{
98+
$this->insertDocument(1);
99+
$this->insertDocument(2);
100+
$this->insertDocument(3);
101+
$this->insertDocument(4);
102+
$this->insertDocument(5);
103+
104+
/** @var ResponseInterface $cursor */
105+
$res = $this->r()
106+
->table('tabletest')
107+
->filter(['title' => 'Test document 1'])
108+
->min('number')
109+
->run();
110+
111+
/** @var array $array */
112+
$array = $res->getData();
113+
114+
$this->assertArraySubset(['description' => 'A document description.'], $array);
115+
}
116+
117+
/**
118+
* @throws \Exception
119+
*/
120+
public function testFilterAndMax()
121+
{
122+
$this->insertDocument(1);
123+
$this->insertDocument(2);
124+
$this->insertDocument(3);
125+
$this->insertDocument(4);
126+
$this->insertDocument(5);
127+
128+
/** @var ResponseInterface $cursor */
129+
$res = $this->r()
130+
->table('tabletest')
131+
->filter(['title' => 'Test document 1'])
132+
->max('number')
133+
->run();
134+
135+
/** @var array $array */
136+
$array = $res->getData();
137+
138+
$this->assertArraySubset(['description' => 'A document description.'], $array);
139+
}
140+
141+
49142
}

0 commit comments

Comments
 (0)