EmailsCleanupRecordsTest::test_delete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 15
c 1
b 0
f 1
dl 0
loc 23
rs 9.7666
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Nip\MailModule\Tests\Console\Commands;
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\Database\Query\Delete;
9
use Nip\MailModule\Console\Commands\EmailsCleanupRecords;
10
use Nip\MailModule\Tests\AbstractTest;
11
use Nip\MailModule\Tests\Fixtures\Models\Emails\Emails;
12
use Nip\Records\Locator\ModelLocator;
13
14
/**
15
 * Class EmailsCleanupRecordsTest
16
 * @package Nip\MailModule\Tests\Console\Commands
17
 */
18
class EmailsCleanupRecordsTest extends AbstractTest
19
{
20
    public function test_delete()
21
    {
22
        $query = null;
23
24
        $adapter = Mockery::mock(MySQLi::class)->shouldAllowMockingProtectedMethods()->makePartial();
25
        $adapter->shouldReceive('cleanData')->andReturnArg(0);
26
27
        /** @var Connection|Mockery\Mock $database */
28
        $database = Mockery::mock(Connection::class)->shouldAllowMockingProtectedMethods()->makePartial();
29
        $database->shouldReceive('execute')->with(\Mockery::capture($query))->once();
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on Nip\Database\Connections\Connection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        $database->/** @scrutinizer ignore-call */ 
30
                   shouldReceive('execute')->with(\Mockery::capture($query))->once();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
        $database->setAdapter($adapter);
31
32
        $emailsTable = new Emails();
33
        $emailsTable->setDB($database);
34
        ModelLocator::set('emails', $emailsTable);
35
36
        $command = new EmailsCleanupRecords();
37
        $command->handle();
38
39
        self::assertInstanceOf(Delete::class, $query);
40
        self::assertSame(
41
            'DELETE FROM `emails` WHERE `type` = \'donation\' AND `date_sent` <= DATE_SUB(CURRENT_DATE(), INTERVAL 365 DAY) LIMIT 500',
42
            $query->getString()
0 ignored issues
show
Bug introduced by
The method getString() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
            $query->/** @scrutinizer ignore-call */ 
43
                    getString()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
        );
44
    }
45
}
46