1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
namespace test; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use \PHPUnit\Framework\TestCase; |
7
|
|
|
use src\pdodatabase\elementos\Campos; |
8
|
|
|
use src\pdodatabase\elementos\Columna; |
9
|
|
|
use src\pdodatabase\elementos\Limite; |
10
|
|
|
use src\pdodatabase\elementos\Operador; |
11
|
|
|
use src\pdodatabase\elementos\Orden; |
12
|
|
|
use src\pdodatabase\elementos\Tabla; |
13
|
|
|
use src\pdodatabase\elementos\OrdenConLimite; |
14
|
|
|
use src\pdodatabase\elementos\Valor; |
15
|
|
|
|
16
|
|
|
class ElementosTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
//Tabla |
19
|
|
|
|
20
|
|
|
public function testSiLaTablaEstaVaciaLanzaExcepcion() |
21
|
|
|
{ |
22
|
|
|
$this->expectException(Exception::class); |
23
|
|
|
$tabla = new Tabla(''); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testTablaSoloRetornaTexto() |
27
|
|
|
{ |
28
|
|
|
$tabla = new Tabla('Hola'); |
29
|
|
|
$this->assertIsString($tabla->tabla()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
//Campos |
33
|
|
|
|
34
|
|
|
public function testSiElCampoEstaVacioLanzaExcepcion() |
35
|
|
|
{ |
36
|
|
|
$this->expectException(Exception::class); |
37
|
|
|
$campos = new Campos([]); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testCamposSoloRetornaTexto() |
41
|
|
|
{ |
42
|
|
|
$campos = new Campos(['*','78']); |
43
|
|
|
$this->assertIsString($campos->campos()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
//Columna |
47
|
|
|
|
48
|
|
|
public function testLaColumnaNoPuedeEstarVacia() |
49
|
|
|
{ |
50
|
|
|
$this->expectException(Exception::class); |
51
|
|
|
$campos = new Columna(''); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testLaColumnaSoloRetornaTexto() |
55
|
|
|
{ |
56
|
|
|
$campos = new Columna('er'); |
57
|
|
|
$this->assertIsString($campos->valor()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
//Operador |
61
|
|
|
|
62
|
|
|
public function testElOperadorNoPuedeEstarVacio() |
63
|
|
|
{ |
64
|
|
|
$this->expectException(Exception::class); |
65
|
|
|
$campos = new Operador(''); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testElOperadorSoloAceptaLosDefinidos() |
69
|
|
|
{ |
70
|
|
|
$this->expectException(Exception::class); |
71
|
|
|
$campos = new Operador('()'); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testElOperadorSoloRetornaTexto() |
75
|
|
|
{ |
76
|
|
|
$campos = new Operador('='); |
77
|
|
|
$this->assertIsString($campos->valor()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
//Valor |
81
|
|
|
|
82
|
|
|
public function testElValorNoPuedeEstarVacio() |
83
|
|
|
{ |
84
|
|
|
$this->expectException(Exception::class); |
85
|
|
|
$campos = new Valor(''); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testElValorSoloRetornaTexto() |
89
|
|
|
{ |
90
|
|
|
$campos = new Valor('1'); |
91
|
|
|
$this->assertIsString($campos->valor()); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
//Orden |
95
|
|
|
|
96
|
|
|
public function testLaSentenciaOrdenNoPuedeEstarVacia() |
97
|
|
|
{ |
98
|
|
|
$this->expectException(Exception::class); |
99
|
|
|
$orden = new Orden(''); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testLaSentenciaOrdenSoloPiedeRetornarString() |
103
|
|
|
{ |
104
|
|
|
$orden = new Orden('id'); |
105
|
|
|
$this->assertIsString($orden->parametro()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
//Limite |
109
|
|
|
|
110
|
|
|
public function testLaSentenciaLimiteNoPuedeEstarVacia() |
111
|
|
|
{ |
112
|
|
|
$this->expectException(Exception::class); |
113
|
|
|
$orden = new Limite(''); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function testLaSentenciaLimiteSoloAceptaValoresNumero() |
117
|
|
|
{ |
118
|
|
|
$this->expectException(Exception::class); |
119
|
|
|
$orden = new Limite('a'); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function testLaSentenciaLimiteSoloPuedeRetornarString() |
123
|
|
|
{ |
124
|
|
|
$orden = new Limite('1'); |
125
|
|
|
$this->assertIsString($orden->parametro()); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
//orden y limite |
129
|
|
|
|
130
|
|
|
public function testOrdenYLimiteRetornaString() |
131
|
|
|
{ |
132
|
|
|
$consulta = new OrdenConLimite(new Orden('id'), new Limite('1')); |
133
|
|
|
$this->assertIsString($consulta->parametro()); |
134
|
|
|
} |
135
|
|
|
} |