Passed
Push — main ( 54e4df...1e4bb3 )
by Osvaldo
01:40
created

ElementosTest::testTablaSoloRetornaTexto()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace test;
5
6
use Exception;
7
use \PHPUnit\Framework\TestCase;
8
use src\pdodatabase\elementos\Campos;
9
use src\pdodatabase\elementos\CamposYTabla;
10
use src\pdodatabase\elementos\Como;
11
use src\pdodatabase\elementos\Tabla;
12
use src\pdodatabase\elementos\ValidadorDeParametrosWhereBetween;
13
use src\pdodatabase\elementos\ValidadorDeParametrosWhere;
14
use src\pdodatabase\elementos\ValidadorDeParametrosWhereAndOthers;
15
use src\pdodatabase\elementos\Where;
16
use src\pdodatabase\elementos\WhereAnd;
17
use src\pdodatabase\elementos\WhereBetween;
18
use src\pdodatabase\elementos\WhereNotBetween;
19
use src\pdodatabase\elementos\WhereOr;
20
use src\pdodatabase\sentencias\select\SentenciaSelect;
21
use src\pdodatabase\sentencias\select\SentenciaSelectWhere;
22
23
class ElementosTest extends TestCase
24
{
25
    //Clase Tabla
26
27
    public function testSiLaTablaEstaVaciaLanzaExcepcion()
28
    {
29
        $this->expectException(Exception::class);
30
        $tabla = new Tabla('');
0 ignored issues
show
Unused Code introduced by
The assignment to $tabla is dead and can be removed.
Loading history...
31
    }
32
33
    public function testTablaSoloRetornaTexto()
34
    {
35
        $tabla = new Tabla('Hola');
36
        $this->assertIsString($tabla->sql());
37
    }
38
39
    //Clase Campos
40
41
    public function testSiElCampoEstaVacioLanzaExcepcion()
42
    {
43
        $this->expectException(Exception::class);
44
        $campos = new Campos([]);
0 ignored issues
show
Unused Code introduced by
The assignment to $campos is dead and can be removed.
Loading history...
45
    }
46
47
    public function testCamposSoloRetornaTexto()
48
    {
49
        $campos = new Campos(['*','78']);
50
        $this->assertIsString($campos->sql());
51
    }
52
53
    //Clase CamposyTabla
54
55
    public function testCamposYTablaDevuelveValorCorrecto()
56
    {
57
        $tabla = new Tabla('prueba');
58
        $campos = new Campos(['a,b,c,d']);
59
60
        $camposytabla = new CamposYTabla($campos,$tabla);
61
62
        $this->assertSame('a,b,c,d FROM prueba',$camposytabla->sql());
63
    }
64
65
    //Clase ValidadorDeParametrosWhere
66
67
    public function testValidadorDeParametrosWhereElArrayNoPuedeEstarVacio()
68
    {
69
        $this->expectException(Exception::class);
70
        new ValidadorDeParametrosWhere([]);
71
    }
72
73
    public function testValidadorDeParametrosWhereLaColumnaSoloPuedeSerString()
74
    {
75
        $this->expectException(Exception::class);
76
        new ValidadorDeParametrosWhere([1,'1','2']);
77
    }
78
79
    public function testValidadorDeParametrosWhereNingunCampoPuedeEstarVacio()
80
    {
81
        $this->expectException(Exception::class);
82
        new ValidadorDeParametrosWhere(['','1','2']);
83
    }
84
85
    //Clase ValidadorDeParametrosWhereBetween
86
87
    public function testValidadorDeParametrosWhereBetweenElArrayNoPuedeEstarVacio()
88
    {
89
        $this->expectException(Exception::class);
90
        new ValidadorDeParametrosWhereBetween([]);
91
    }
92
93
    public function testValidadorDeParametrosWhereBetweenNoPuedeTenerValoresIguales()
94
    {
95
        $this->expectException(Exception::class);
96
        new ValidadorDeParametrosWhereBetween(['id','1','1']);
97
    }
98
99
    public function testValidadorDeParametrosWhereBetweenLaColumnaSoloPuedeSerString()
100
    {
101
        $this->expectException(Exception::class);
102
        new ValidadorDeParametrosWhereBetween([1,'1','2']);
103
    }
104
105
    public function testValidadorDeParametrosWhereBetweenNingunCampoPuedeEstarVacio()
106
    {
107
        $this->expectException(Exception::class);
108
        new ValidadorDeParametrosWhereBetween(['','1','2']);
109
    }
110
111
    //Clase Where
112
113
    public function testWhereArrojaStringValido()
114
    {
115
        $where = new Where(
116
            new ValidadorDeParametrosWhere(
117
                ['id','=','21']
118
            )
119
            );
120
121
        $this->assertSame('WHERE id = ?', $where->sql());
122
    }
123
124
    public function testWhereArrojaArrayEnMetodoDatos()
125
    {
126
        $where = new Where(
127
            new ValidadorDeParametrosWhere(
128
                ['id','=','21']
129
            )
130
            );
131
132
        $this->assertIsArray($where->datos());
133
    }
134
135
    //Clase ValidadorDeParametrosWhereAndOthers
136
137
    public function testValidadorDeParametrosWhereAndOthersElArrayNoPuedeEstarVacio()
138
    {
139
        $this->expectException(Exception::class);
140
        new ValidadorDeParametrosWhereAndOthers([]);
141
    }
142
143
    public function testValidadorDeParametrosWhereAndOthersNoPuedeTenerValoresIguales()
144
    {
145
        $this->expectException(Exception::class);
146
        new ValidadorDeParametrosWhereAndOthers(['id','=','1','id','=','1']);
147
    }
148
149
    public function testValidadorDeParametrosWhereAndOthersLaColumnaSoloPuedeSerString()
150
    {
151
        $this->expectException(Exception::class);
152
        new ValidadorDeParametrosWhereAndOthers([1,'=','2','1','=','2']);
153
    }
154
155
    public function testValidadorDeParametrosWhereAndOthersNingunCampoPuedeEstarVacio()
156
    {
157
        $this->expectException(Exception::class);
158
        new ValidadorDeParametrosWhereAndOthers(['','1','2','','','']);
159
    }
160
161
    //Clase Where And
162
163
    public function testWhereAndArrojaStringValido()
164
    {
165
        $where = new WhereAnd(
166
            new ValidadorDeParametrosWhereAndOthers(
167
                ['id','=','21','uno','=','1']
168
            )
169
            );
170
171
        $this->assertSame('WHERE id = ? AND uno = ?', $where->sql());
172
    }
173
174
    //Clase Where Or
175
176
    public function testWhereOrArrojaStringValido()
177
    {
178
        $where = new WhereOr(
179
            new ValidadorDeParametrosWhereAndOthers(
180
                ['id','=','21','uno','=','1']
181
            )
182
            );
183
184
        $this->assertSame('WHERE id = ? OR uno = ?', $where->sql());
185
    }
186
187
    //Clase Where Between
188
189
    public function testWhereBetweenArrojaStringValido()
190
    {
191
        $where = new WhereBetween(
192
            new ValidadorDeParametrosWhereBetween(
193
                ['id','1','21']
194
            )
195
            );
196
197
        $this->assertSame('WHERE BETWEEN id ? AND ?', $where->sql());
198
    }
199
200
    //Clase Where Not Between
201
202
    public function testWhereNotBetweenArrojaStringValido()
203
    {
204
        $where = new WhereNotBetween(
205
            new ValidadorDeParametrosWhereBetween(
206
                ['id','1','21']
207
            )
208
            );
209
210
        $this->assertSame('WHERE NOT BETWEEN id ? AND ?', $where->sql());
211
    }
212
213
    //Clase Como 
214
215
    public function testComoArrojaStringValido()
216
    {
217
        $where = new WhereNotBetween(
218
            new ValidadorDeParametrosWhereBetween(
219
                ['id','1','21']
220
            )
221
            );
222
        
223
        $como = new Como(
224
            $where
225
        );
226
227
        $this->assertSame('WHERE NOT BETWEEN id ? AND ?', $como->sql());
228
    }
229
230
    //Clase Sentencia Select Where
231
232
    public function testSentenciaSelectWhereArrojaStringValido()
233
    {
234
        $where = new WhereNotBetween(
235
            new ValidadorDeParametrosWhereBetween(
236
                ['id','1','21']
237
            )
238
            );
239
        
240
        $como = new Como(
241
            $where
242
        );
243
244
        $sentencia = new SentenciaSelectWhere(
245
            new CamposYTabla(
246
                new Campos(['*']),
247
                new Tabla('prueba')
248
            ),$como
249
        );
250
251
        $this->assertSame('SELECT * FROM prueba WHERE NOT BETWEEN id ? AND ?', $sentencia->sql());
252
    }
253
254
    //Clase SentenciaSelect
255
256
    public function testSentenciaSelectArrojaStringValido()
257
    {
258
        $sentencia = new SentenciaSelect(
259
            new CamposYTabla(
260
                new Campos(['*']),
261
                new Tabla('prueba')
262
                )
263
            );
264
265
        $this->assertSame('SELECT * FROM prueba', $sentencia->sql());
266
    }
267
}