Advertisement
gorkamu

BaseTestCase - Clase Base para Test en PHPUnit

Apr 26th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by JetBrains PhpStorm.
  4.  * User: gorka
  5.  * Date: 3/01/14
  6.  * Time: 7:24
  7.  */
  8. namespace Modelo\BLBundle\Tests\Controller;
  9.  
  10. use Util\Constantes;
  11.  
  12. require_once Constantes::ABSOLUTE_PATH_APPKERNEL_TEST;
  13.  
  14. /**
  15.  * Class BaseTestCase
  16.  * @package Modelo\BLBundle\Tests\Controller
  17.  */
  18. class BaseTestCase extends \PHPUnit_Framework_TestCase
  19. {
  20.  
  21.     private $container;
  22.     private $app;
  23.     private $em;
  24.  
  25.     /**
  26.      * Function setUp
  27.      */
  28.     public function setUp()
  29.     {
  30.         $this->app = new \AppKernel('test', false);
  31.         $this->app->boot();
  32.         $this->container = $this->app->getContainer();
  33.         $this->em = $this->container->get('doctrine')->getManager();
  34.         $this->em->getConnection()->beginTransaction();
  35.         parent::setUp();
  36.     }
  37.  
  38.  
  39.     /**
  40.      * Function tearDown
  41.      */
  42.     public function tearDown()
  43.     {
  44.         $this->app->shutdown();
  45.         $this->em->getConnection()->rollback();
  46.         parent::tearDown();
  47.     }
  48.  
  49.  
  50.     /**
  51.      * Function getContainer
  52.      * </br>
  53.      *
  54.      * @return mixed
  55.      */
  56.     public function getContainer()
  57.     {
  58.         return $this->container;
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement