diff --git a/src/Symfony/Bridge/Doctrine/Test/DoctrineTestCase.php b/src/Symfony/Bridge/Doctrine/Test/DoctrineTestCase.php new file mode 100644 index 0000000000000..5252eabb03128 --- /dev/null +++ b/src/Symfony/Bridge/Doctrine/Test/DoctrineTestCase.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Doctrine\Test; + +use Doctrine\ORM\EntityManager; +use Symfony\Bundle\FrameworkBundle\Tests\Functional\WebTestCase; + +/** + * @author Thomas Royer + */ +class DoctrineTestCase extends WebTestCase +{ + /** + * @var EntityManager + */ + private $entityManager; + + public function setEntityManager(EntityManager $entityManager) + { + $this->entityManager = $entityManager; + } + + public function setUp() + { + parent::setUp(); + + $this->entityManager->beginTransaction(); + } + + public function tearDown() + { + parent::tearDown(); + + $this->entityManager->rollback(); + } +} diff --git a/src/Symfony/Bridge/Doctrine/Tests/Test/DoctrineTestCaseTest.php b/src/Symfony/Bridge/Doctrine/Tests/Test/DoctrineTestCaseTest.php new file mode 100644 index 0000000000000..4a78cef4b860e --- /dev/null +++ b/src/Symfony/Bridge/Doctrine/Tests/Test/DoctrineTestCaseTest.php @@ -0,0 +1,65 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Doctrine\Tests\Test; + +use Doctrine\ORM\Tools\SchemaTool; +use Symfony\Bridge\Doctrine\Test\DoctrineTestCase; +use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper; +use Symfony\Bridge\Doctrine\Tests\Fixtures\User; + +class DoctrineTestCaseTest extends DoctrineTestCase +{ + private static $em; + + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + self::$em = DoctrineTestHelper::createTestEntityManager(); + self::createSchema(); + } + + public function setUp() + { + $this->setEntityManager(self::$em); + + parent::setUp(); + } + + public function testItInsertsData() + { + $user = new User(1, 1, 'user'); + + self::$em->persist($user); + self::$em->flush(); + + $this->assertEquals(1, count(self::$em->getRepository(User::class)->findAll())); + } + + public function testItHasRollbacked() + { + $user = new User(1, 2, 'user'); + + self::$em->persist($user); + self::$em->flush(); + + $this->assertEquals(1, count(self::$em->getRepository(User::class)->findAll())); + } + + private static function createSchema() + { + $schemaTool = new SchemaTool(self::$em); + $schemaTool->createSchema(array( + self::$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\User'), + )); + } +}