InsertTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 33
c 2
b 0
f 0
dl 0
loc 69
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testOnDuplicate() 0 12 1
A test_null() 0 8 1
A testMultiple() 0 16 2
A setUp() 0 12 1
1
<?php
2
3
namespace Nip\Database\Tests\Query;
4
5
use Mockery as m;
6
use Nip\Database\Connections\Connection;
7
use Nip\Database\Query\Insert;
8
use Nip\Database\Tests\AbstractTest;
9
10
/**
11
 * Class InsertTest
12
 * @package Nip\Database\Tests\Query
13
 */
14
class InsertTest extends AbstractTest
15
{
16
    /**
17
     * @var \UnitTester
0 ignored issues
show
Bug introduced by
The type UnitTester 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...
18
     */
19
    protected $tester;
20
21
    /**
22
     * @var Insert
23
     */
24
    protected $object;
25
26
    public function test_null()
27
    {
28
        $this->object->table("table");
0 ignored issues
show
Bug introduced by
'table' of type string is incompatible with the type array expected by parameter $| of Nip\Database\Query\AbstractQuery::table(). ( Ignorable by Annotation )

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

28
        $this->object->table(/** @scrutinizer ignore-type */ "table");
Loading history...
29
        $this->object->data(["id" => 3, "name" => null]);
30
31
        static::assertEquals(
32
            "INSERT INTO `table` (`id`,`name`) VALUES (3, NULL)",
33
            $this->object->assemble()
34
        );
35
    }
36
37
    public function testOnDuplicate()
38
    {
39
        $this->object->table("table");
0 ignored issues
show
Bug introduced by
'table' of type string is incompatible with the type array expected by parameter $| of Nip\Database\Query\AbstractQuery::table(). ( Ignorable by Annotation )

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

39
        $this->object->table(/** @scrutinizer ignore-type */ "table");
Loading history...
40
        $this->object->data(["id" => 3, "name" => "Lorem Ipsum"]);
41
        $this->object->onDuplicate([
42
            "id" => ["VALUES(`id`)", false],
43
            "name" => ["VALUES(`name`)", false]
44
        ]);
45
46
        static::assertEquals(
47
            "INSERT INTO `table` (`id`,`name`) VALUES (3, 'Lorem Ipsum') ON DUPLICATE KEY UPDATE `id` = VALUES(`id`), `name` = VALUES(`name`)",
48
            $this->object->assemble()
49
        );
50
    }
51
52
    public function testMultiple()
53
    {
54
        $this->object->table("table");
0 ignored issues
show
Bug introduced by
'table' of type string is incompatible with the type array expected by parameter $| of Nip\Database\Query\AbstractQuery::table(). ( Ignorable by Annotation )

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

54
        $this->object->table(/** @scrutinizer ignore-type */ "table");
Loading history...
55
56
        $items = [
57
            ["name" => "Lorem Ipsum", "telephone" => 1234],
58
            ["name" => "Dolor sit amet", "telephone" => 5678]
59
        ];
60
61
        foreach ($items as $item) {
62
            $this->object->data($item);
63
        }
64
65
        static::assertEquals(
66
            "INSERT INTO `table` (`name`,`telephone`) VALUES ('Lorem Ipsum', 1234), ('Dolor sit amet', 5678)",
67
            $this->object->assemble()
68
        );
69
    }
70
71
    protected function setUp(): void
72
    {
73
        parent::setUp();
74
        $this->object = new Insert();
75
76
        $adapterMock = m::mock('Nip\Database\Adapters\MySQLi')->shouldDeferMissing();
0 ignored issues
show
Deprecated Code introduced by
The function Mockery\LegacyMockInterface::shouldDeferMissing() has been deprecated: 2.0.0 Please use makePartial() instead ( Ignorable by Annotation )

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

76
        $adapterMock = /** @scrutinizer ignore-deprecated */ m::mock('Nip\Database\Adapters\MySQLi')->shouldDeferMissing();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
77
        $adapterMock->shouldReceive('cleanData')->andReturnUsing(function ($data) {
78
            return $data;
79
        });
80
        $manager = new Connection(false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type Closure|PDO expected by parameter $pdo of Nip\Database\Connections\Connection::__construct(). ( Ignorable by Annotation )

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

80
        $manager = new Connection(/** @scrutinizer ignore-type */ false);
Loading history...
81
        $manager->setAdapter($adapterMock);
82
        $this->object->setManager($manager);
83
    }
84
}
85