Passed
Push — master ( 083ff7...c84473 )
by William
03:02
created

StatsShellTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 35
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecute() 0 22 3
A setUp() 0 4 1
1
<?php
2
3
/**
4
 * Tests for Stats Shell.
5
 *
6
 * phpMyAdmin Error reporting server
7
 * Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
8
 *
9
 * Licensed under The MIT License
10
 * For full copyright and license information, please see the LICENSE.txt
11
 * Redistributions of files must retain the above copyright notice.
12
 *
13
 * @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
14
 * @license   https://opensource.org/licenses/mit-license.php MIT License
15
 *
16
 * @see      https://www.phpmyadmin.net/
17
 */
18
19
namespace App\Test\TestCase\Shell;
20
21
use Cake\Cache\Cache;
22
use Cake\Command\Command;
23
use Cake\TestSuite\ConsoleIntegrationTestTrait;
24
use Cake\TestSuite\TestCase;
25
26
/**
27
 * App\Shell\StatsShell Test Case
28
 */
29
class StatsShellTest extends TestCase
30
{
31
    use ConsoleIntegrationTestTrait;
32
33
    public function setUp(): void
34
    {
35
        parent::setUp();
36
        $this->useCommandRunner();
37
    }
38
39
    /**
40
     * Test execute method
41
     */
42
    public function testExecute(): void
43
    {
44
        // Clear the existing cache
45
        Cache::clear();
46
47
        // Run the shell command
48
        $this->exec('stats');
49
        $this->assertExitCode(Command::CODE_SUCCESS);
50
        $Incidents = $this->getTableLocator()->get('Incidents');
51
        foreach ($Incidents->filterTimes as $filter_string => $filter) {
52
            foreach ($Incidents->summarizableFields as $field) {
53
                // Make sure all the fields are covered
54
                $this->assertNotEquals(
55
                    false,
56
                    Cache::read($field . '_' . $filter_string)
57
                );
58
            }
59
60
            // Make sure download stats value stored
61
            $this->assertNotEquals(
62
                false,
63
                Cache::read('downloadStats_' . $filter_string)
64
            );
65
        }
66
    }
67
}
68