HostRESTControllerTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace IPv4Bundle\tests\Controller\REST;
  3. use WebserviceBundle\tests\WebTestCaseBase;
  4. use IPv4Bundle\Entity\Host;
  5. /**
  6. * Class HostRESTControllerTest
  7. * @package IPv4Bundle\tests\Controller\REST
  8. * En caso de modificar las tablas solo se deberia modificar la funcion "obtainData" agregando los campos necesarios.
  9. */
  10. class HostRESTControllerTest extends BaseRESTControllerTest
  11. {
  12. /**
  13. * @var string $entity
  14. */
  15. protected $entity = 'Host';
  16. /**
  17. * @var string $field
  18. */
  19. protected $field = 'mac';
  20. /**
  21. * @var string $field_value_edited
  22. */
  23. protected $field_value_edited = 'cafecafecaff';
  24. /**
  25. * @return string Retorna la uri a consultar.
  26. */
  27. protected function getUri()
  28. {
  29. return '/api/hosts.json';
  30. }
  31. /**
  32. * @return string Retorna la uri a consultar.
  33. */
  34. protected function getPOSTUri()
  35. {
  36. return '/api/hosts.json';
  37. }
  38. /**
  39. * @return string Retorna la uri a consultar.
  40. */
  41. protected function getUriPutDelete()
  42. {
  43. return '/api/hosts/';
  44. }
  45. /**
  46. * Contiene los datos que debe retornar el webservice. La key es nombre del webservice y el
  47. * value son los datos a retornar.
  48. */
  49. protected function obtainDataWebService()
  50. {
  51. $datos = [];
  52. return $datos;
  53. }
  54. /**
  55. * Genera los datos a manipular.
  56. *
  57. * @param string $key Contiene la key a buscar en los datos.
  58. *
  59. * @return array|string Retorna el array con los datos o el valor de la key pasada como parametro.
  60. *
  61. * @throws \Exception Lanza un excepcion en caso de no encontrar la key.
  62. */
  63. protected function obtainData($key = null)
  64. {
  65. $datos = [
  66. 'mac' => 'cafecafecafe',
  67. 'options' => 'cafecafecafe',
  68. 'hostType' => null,
  69. 'state' => Host::STATE_ACTIVE,
  70. ];
  71. if ($key == null) {
  72. return $datos;
  73. } else {
  74. if (isset($datos[$key])) {
  75. return $datos[$key];
  76. } else {
  77. throw new \Exception("No se seteo la key del dato a obtener. key=" . $key);
  78. }
  79. }
  80. }
  81. }