Test Failed
Push — master ( 7cde39...b3d10e )
by Mauro
05:55
created

SqliteQueryBuilderTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A it_should_returns_the_correct_multiple_insert_query() 0 15 2
B setUp() 0 27 1
A it_should_returns_the_correct_single_insert_query() 0 18 2
1
<?php
2
/**
3
 * This file is part of the DbImporter package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace DbImporter\Tests;
12
13
use DbImporter\QueryBuilder\Contracts\QueryBuilderInterface;
14
use DbImporter\QueryBuilder\SqliteQueryBuilder;
15
16
class SqliteQueryBuilderTest extends BaseTestCase
17
{
18
    /**
19
     * @var array
20
     */
21
    private $data;
22
23
    /**
24
     * @var array
25
     */
26
    private $mapping;
27
28
    public function setUp()
29
    {
30
        $this->data = [
31
            [
32
                'id_utente' => 1,
33
                'name_utente' => 'Mauro',
34
                'email_utente' => '[email protected]',
35
                'username_utente' => 'mauretto78',
36
            ],
37
            [
38
                'id_utente' => 2,
39
                'name_utente' => 'John',
40
                'email_utente' => '[email protected]',
41
                'username_utente' => 'johndoe',
42
            ],
43
            [
44
                'id_utente' => 3,
45
                'name_utente' => 'Maria',
46
                'email_utente' => '[email protected]',
47
                'username_utente' => 'maria',
48
            ]
49
        ];
50
51
        $this->mapping = [
52
            'id' => 'id_utente',
53
            'name' => 'name_utente',
54
            'username' => 'username_utente',
55
        ];
56
    }
57
58
    /**
59
     * @test
60
     */
61
    public function it_should_returns_the_correct_multiple_insert_query()
62
    {
63
        $qb = new SqliteQueryBuilder(
64
            'example_table',
65
            $this->mapping,
66
            $this->data,
67
            true
68
        );
69
70
        $queries = $qb->getQueries();
71
        foreach ($queries as $query) {
72
            $expectedQuery = 'INSERT OR IGNORE INTO `example_table` (`id`, `name`, `username`) VALUES (:id_utente_1, :name_utente_1, :username_utente_1), (:id_utente_2, :name_utente_2, :username_utente_2), (:id_utente_3, :name_utente_3, :username_utente_3)';
73
74
            $this->assertInstanceOf(QueryBuilderInterface::class, $qb);
75
            $this->assertEquals($query, $expectedQuery);
76
        }
77
    }
78
79
    /**
80
     * @test
81
     */
82
    public function it_should_returns_the_correct_single_insert_query()
83
    {
84
        $qb = new SqliteQueryBuilder(
85
            'example_table',
86
            $this->mapping,
87
            $this->data,
88
            true
89
        );
90
91
        $queries = $qb->getQueries('single');
92
        foreach ($queries as $query) {
93
            $expectedQuery = 'INSERT OR IGNORE INTO `example_table` (`id`, `name`, `username`) VALUES (:id_utente, :name_utente, :username_utente)';
94
95
            $this->assertInstanceOf(QueryBuilderInterface::class, $qb);
96
            $this->assertEquals($query, $expectedQuery);
97
        }
98
99
        $this->assertCount(3, $queries);
100
    }
101
}
102