Skip to content

Commit 5da8cd3

Browse files
tboliermarcgeurts
authored andcommitted
Improve assertions for aggregation unit tests
1 parent e132aa6 commit 5da8cd3

File tree

3 files changed

+17
-164
lines changed

3 files changed

+17
-164
lines changed

test/integration/Aggregation/AvgTest.php

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,62 +14,18 @@ class AvgTest extends AbstractTableTest
1414
*/
1515
public function testAvg(): void
1616
{
17-
$this->insertDocument(5);
18-
$this->insertDocument(4);
19-
$this->insertDocument(3);
20-
$this->insertDocument(2);
21-
$this->insertDocument(1);
17+
$this->insertDocumentWithNumber(5, 5);
18+
$this->insertDocumentWithNumber(4, 10);
19+
$this->insertDocumentWithNumber(3, 15);
20+
$this->insertDocumentWithNumber(2, 20);
21+
$this->insertDocumentWithNumber(1, 25);
2222

2323
/** @var ResponseInterface $res */
2424
$res = $this->r()
2525
->table('tabletest')
2626
->avg('number')
2727
->run();
2828

29-
$this->assertTrue(is_float($res->getData()) || is_int($res->getData()));
30-
}
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()));
29+
$this->assertEquals(15, $res->getData());
7430
}
7531
}

test/integration/Aggregation/CountTest.php

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,76 +13,17 @@ class CountTest extends AbstractTableTest
1313
*/
1414
public function testCount()
1515
{
16-
$this->insertDocument(1);
16+
$this->insertDocumentWithNumber(5, 5);
17+
$this->insertDocumentWithNumber(4, 10);
18+
$this->insertDocumentWithNumber(3, 15);
19+
$this->insertDocumentWithNumber(2, 20);
20+
$this->insertDocumentWithNumber(1, 25);
1721

1822
$res = $this->r()
1923
->table('tabletest')
2024
->count()
2125
->run();
2226

23-
$this->assertInternalType('int', $res->getData());
24-
}
25-
26-
/**
27-
* @throws \Exception
28-
*/
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()
51-
{
52-
$this->insertDocument(1);
53-
$this->insertDocument(2);
54-
$this->insertDocument(3);
55-
$this->insertDocument(4);
56-
$this->insertDocument(5);
57-
58-
/** @var ResponseInterface $res */
59-
$res = $this->r()
60-
->table('tabletest')
61-
->filter(['id' => 1])
62-
->count()
63-
->run();
64-
65-
$this->assertEquals(1, $res->getData());
66-
}
67-
68-
/**
69-
* @throws \Exception
70-
*/
71-
public function testFilterAndCountMultiple()
72-
{
73-
$this->insertDocument(1);
74-
$this->insertDocument(2);
75-
$this->insertDocument(3);
76-
$this->insertDocument(4);
77-
$this->insertDocument(5);
78-
79-
/** @var ResponseInterface $res */
80-
$res = $this->r()
81-
->table('tabletest')
82-
->filter(['description' => 'A document description.'])
83-
->count()
84-
->run();
85-
8627
$this->assertEquals(5, $res->getData());
8728
}
8829
}

test/integration/Aggregation/SumTest.php

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,62 +14,18 @@ class SumTest extends AbstractTableTest
1414
*/
1515
public function testSum(): void
1616
{
17-
$this->insertDocument(5);
18-
$this->insertDocument(4);
19-
$this->insertDocument(3);
20-
$this->insertDocument(2);
21-
$this->insertDocument(1);
17+
$this->insertDocumentWithNumber(5, 5);
18+
$this->insertDocumentWithNumber(4, 10);
19+
$this->insertDocumentWithNumber(3, 15);
20+
$this->insertDocumentWithNumber(2, 20);
21+
$this->insertDocumentWithNumber(1, 25);
2222

2323
/** @var ResponseInterface $res */
2424
$res = $this->r()
2525
->table('tabletest')
2626
->sum('number')
2727
->run();
2828

29-
$this->assertInternalType('int', $res->getData());
30-
}
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());
29+
$this->assertEquals(75, $res->getData());
7430
}
7531
}

0 commit comments

Comments
 (0)