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 |
|
|
|
|
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"); |
|
|
|
|
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"); |
|
|
|
|
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"); |
|
|
|
|
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(); |
|
|
|
|
77
|
|
|
$adapterMock->shouldReceive('cleanData')->andReturnUsing(function ($data) { |
78
|
|
|
return $data; |
79
|
|
|
}); |
80
|
|
|
$manager = new Connection(false); |
|
|
|
|
81
|
|
|
$manager->setAdapter($adapterMock); |
82
|
|
|
$this->object->setManager($manager); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths