1
|
|
|
<?php |
2
|
|
|
namespace tests; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
use src\Controlador; |
6
|
|
|
use src\Enlace; |
7
|
|
|
use src\Metodo; |
8
|
|
|
use src\Parametros; |
9
|
|
|
use src\Peticion; |
10
|
|
|
|
11
|
|
|
define('CONTROLADOR_POR_DEFECTO','Controlador'); |
12
|
|
|
define('CONTROLADOR_DIR','controladores/'); |
13
|
|
|
define('CONTROLADOR_NAMESPACE', 'controladores\\'); |
14
|
|
|
define('METODO_POR_DEFECTO','index'); |
15
|
|
|
|
16
|
|
|
class PeticionTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
public function setUp(): void |
19
|
|
|
{ |
20
|
|
|
$this->e = new Enlace(['Controlador']); |
|
|
|
|
21
|
|
|
$this->c = new Controlador($this->e); |
|
|
|
|
22
|
|
|
$this->m = new Metodo($this->e,$this->c); |
|
|
|
|
23
|
|
|
$this->p = new Parametros($this->e,$this->m); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
//Peticion |
27
|
|
|
|
28
|
|
|
public function testPeticionDevuelvecontroladorCorrecto() |
29
|
|
|
{ |
30
|
|
|
$p = new Peticion($this->c, $this->m, $this->p); |
31
|
|
|
$this->assertSame('Controlador', $p->controlador()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testPeticionDevuelvecontroladorPorDefectoSiNoExisteElLlamado() |
35
|
|
|
{ |
36
|
|
|
$this->e = new Enlace(['Iniciosssssssss']); |
|
|
|
|
37
|
|
|
$this->c = new Controlador($this->e); |
|
|
|
|
38
|
|
|
$this->m = new Metodo($this->e,$this->c); |
|
|
|
|
39
|
|
|
$this->p = new Parametros($this->e,$this->m); |
|
|
|
|
40
|
|
|
$p = new Peticion($this->c, $this->m, $this->p); |
41
|
|
|
$this->assertSame('Controlador', $p->controlador()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testPeticionDevuelveMetodoCorrecto() |
45
|
|
|
{ |
46
|
|
|
$p = new Peticion($this->c, $this->m, $this->p); |
47
|
|
|
$this->assertSame('index', $p->metodo()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testPeticionDevuelveParametrosEnArray() |
51
|
|
|
{ |
52
|
|
|
$p = new Peticion($this->c, $this->m, $this->p); |
53
|
|
|
$this->assertIsArray($p->parametros()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
//Enlace |
57
|
|
|
|
58
|
|
|
public function testEnlaceSiempreRetornaUnArray() |
59
|
|
|
{ |
60
|
|
|
$e = new Enlace([]); |
61
|
|
|
$this->assertIsArray($e->enlace()); |
62
|
|
|
$e = new Enlace(['hola','hola2']); |
63
|
|
|
$this->assertIsArray($e->enlace()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
//Controlador |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
|
70
|
|
|
|
71
|
|
|
//Metodo |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
//Parametros |
75
|
|
|
} |