RecordsTraitTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 2
Metric Value
wmc 2
eloc 21
c 2
b 1
f 2
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testReduceOldEmailsData() 0 25 1
A test_reduceEmailsByType() 0 6 1
1
<?php
2
3
namespace Nip\MailModule\Tests\EmailsTable\Traits\Cleanup;
4
5
use Mockery;
0 ignored issues
show
Bug introduced by
The type Mockery was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Nip\Database\Adapters\MySQLi;
7
use Nip\Database\Connections\Connection;
8
use Nip\MailModule\Tests\AbstractTest;
9
use Nip\MailModule\Tests\Fixtures\Models\Emails\Emails;
10
11
/**
12
 * Class RecordsTraitTest
13
 * @package Nip\MailModule\Tests\EmailsTable\Traits\Cleanup
14
 */
15
class RecordsTraitTest extends AbstractTest
16
{
17
    public function testReduceOldEmailsData()
18
    {
19
        $adapter = Mockery::mock(MySQLi::class)->makePartial();
20
        $adapter->shouldReceive('cleanData')
21
            ->andReturnUsing(function ($data) {
22
                return $data;
23
            });
24
25
        $database = Mockery::mock(Connection::class)->makePartial();
26
        $database->shouldReceive('execute')
27
            ->andReturnUsing(function ($query) {
28
                return $query->getString();
29
            });
30
        $database->setAdapter($adapter);
31
32
        $emails = new Emails();
33
        $emails->setDB($database);
34
35
        $query = $emails->reduceOldEmailsData();
36
37
        self::assertSame(
38
            'UPDATE `emails` '
39
            . 'SET `vars` = \'\', `body` = \'\', `compiled_subject` = \'\', `compiled_body` = \'\' '
40
            . 'WHERE `date_sent` <= DATE_SUB(CURRENT_DATE(), INTERVAL 500 DAY)',
41
            $query
42
        );
43
    }
44
45
    public function test_reduceEmailsByType()
46
    {
47
        $emails = new Emails();
48
        $types = $emails::reduceEmailsByType();
49
50
        self::assertSame(['*' => 365, 'donation' => 365], $types);
51
    }
52
}
53