Advertisement
gorkamu

UsuariosTest - Test unitario para PHPUnit

Apr 26th, 2015
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.39 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: gorka
  5.  * Date: 6/01/14
  6.  * Time: 12:21
  7.  */
  8.  
  9. namespace Modelo\BLBundle\Tests\Controller;
  10.  
  11.  
  12. use Modelo\BLBundle\Entity\Usuarios;
  13. use Util\Constantes;
  14. use Util\Fechas;
  15. use Util\Servicios;
  16.  
  17. class UsuariosTest extends BaseTestCase implements IBaseTestCase
  18. {
  19.     const _NOMBRE_MODIFICADO = "Nombre modificado";
  20.  
  21.     public function testSave()
  22.     {
  23.         $u = self::getUsuario();
  24.         $this->assertNotNull($u);
  25.         $this->assertNotNull($u->getId());
  26.     }
  27.  
  28.     public function testDelete()
  29.     {
  30.         $this->markTestIncomplete('Este test da problemas, lo dejamos para implementacion');
  31.         $u = self::getUsuario();
  32.         $id = $u->getId();
  33.         $bl = $this->getContainer()->get(Servicios::_USUARIOS_SERVICE);
  34.         $bl->delete($u);
  35.         $this->assertNull($bl->findById($id));
  36.     }
  37.  
  38.     public function testUpdate()
  39.     {
  40.         $u = self::getUsuario();
  41.         $u->setNombre(self::_NOMBRE_MODIFICADO);
  42.         $id = $u->getId();
  43.         $bl = $this->getContainer()->get(Servicios::_USUARIOS_SERVICE);
  44.         $bl->update();
  45.         $sus = $bl->findById($id);
  46.         $this->assertEquals($sus->getNombre(), self::_NOMBRE_MODIFICADO);
  47.     }
  48.  
  49.     public function testFindAll()
  50.     {
  51.         $p = self::getUsuario();
  52.         $this->assertTrue(sizeof($this->getContainer()->get(Servicios::_USUARIOS_SERVICE)->findAll()) > Constantes::_0);
  53.     }
  54.  
  55.     public function testFindById()
  56.     {
  57.         $u = self::getUsuario();
  58.         $id = $u->getId();
  59.         $bl = $this->getContainer()->get(Servicios::_USUARIOS_SERVICE);
  60.         $user = $bl->findById($id);
  61.         $this->assertNotNull($user);
  62.         $this->assertNotNull($user->getId());
  63.         $this->assertEquals($user->getId(), $id);
  64.     }
  65.  
  66.     public function testFindFirst()
  67.     {
  68.         $u = self::getUsuario();
  69.         $user = $this->getContainer()->get(Servicios::_USUARIOS_SERVICE)->findFirst();
  70.         $this->assertNotNull($user);
  71.         $this->assertNotNull($user->getId());
  72.     }
  73.  
  74.     public function testFindLatest()
  75.     {
  76.         $u = self::getUsuario();
  77.         $id = $u->getId();
  78.         $user = $this->getContainer()->get(Servicios::_USUARIOS_SERVICE)->findLast();
  79.         $this->assertNotNull($user);
  80.         $this->assertNotNull($user->getId());
  81.         $this->assertEquals($user->getid(), $id);
  82.     }
  83.  
  84.     public function testFindByUsernameAndPassword()
  85.     {
  86.         $u = self::getUsuario();
  87.         $bl = $this->getContainer()->get(Servicios::_USUARIOS_SERVICE);
  88.         $user = $bl->findOneBy(
  89.             array(
  90.                 'username' => $u->getUsername(),
  91.                 'password' => $u->getPassword()
  92.             )
  93.         );
  94.         $this->assertNotNull($user);
  95.         $this->assertNotNull($user->getId());
  96.         $this->assertEquals($user->getid(), $u->getId());
  97.     }
  98.  
  99.     public function getUsuario()
  100.     {
  101.         $u = new Usuarios();
  102.         $u->setNombre("Nombre usuario");
  103.         $u->setApellido1("Apellido 1");
  104.         $u->setApellido2("Apellido2");
  105.         $u->setIsActive(Constantes::_ACTIVO);
  106.         $u->setFechaAlta(Fechas::getSysdate());
  107.         $u->setIsAdmin(Constantes::_DESACTIVADO);
  108.         $u->setPassword("Password");
  109.         $u->setUsername("Username");
  110.         $u->setEmail("Email");
  111.         $this->getContainer()->get(Servicios::_USUARIOS_SERVICE)->save($u);
  112.         return $u;
  113.     }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement