CleanOldNotifsShellTest::testExecute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 20
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Tests for Clean Old Notifications 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\Command\Command;
22
use Cake\TestSuite\ConsoleIntegrationTestTrait;
23
use Cake\TestSuite\TestCase;
24
25
/**
26
 * App\Shell\CleanOldNotifsShell Test Case
27
 */
28
class CleanOldNotifsShellTest extends TestCase
29
{
30
    use ConsoleIntegrationTestTrait;
31
32
    /**
33
     * Fixtures.
34
     *
35
     * @var array
36
     */
37
    public $fixtures = [
38
        'app.Notifications',
39
        'app.Developers',
40
    ];
41
42
    public function setUp(): void
43
    {
44
        parent::setUp();
45
        $this->useCommandRunner();
46
    }
47
48
    /**
49
     * Test execute method
50
     */
51
    public function testExecute(): void
52
    {
53
        $Notifications = $this->getTableLocator()->get('Notifications');
54
55
        $conditions = ['developer_id' => 1];
56
        $currentNotificationCount
57
            = $Notifications->find('all')->where($conditions)->count();
58
        $this->assertEquals(2, $currentNotificationCount);
59
60
        // Run the shell command
61
        $this->exec('clean_old_notifs');
62
        $this->assertExitCode(Command::CODE_SUCCESS);
63
64
        $newNotificationCount
65
            = $Notifications->find('all')->where($conditions)->count();
66
        $this->assertEquals(0, $newNotificationCount);
67
68
        // Run shell command to generate zero notifications error
69
        $this->exec('clean_old_notifs');
70
        $this->assertExitCode(Command::CODE_SUCCESS);
71
    }
72
}
73