PageRenderTime 26ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/doctrine/tests/Doctrine/Tests/ORM/EntityManagerTest.php

https://github.com/dlondero/fantamanager
PHP | 158 lines | 115 code | 28 blank | 15 comment | 0 complexity | ce3fd16e70488f5625e08ded2441f550 MD5 | raw file
  1. <?php
  2. namespace Doctrine\Tests\ORM;
  3. require_once __DIR__ . '/../TestInit.php';
  4. class EntityManagerTest extends \Doctrine\Tests\OrmTestCase
  5. {
  6. private $_em;
  7. function setUp()
  8. {
  9. parent::setUp();
  10. $this->_em = $this->_getTestEntityManager();
  11. }
  12. /**
  13. * @group DDC-899
  14. */
  15. public function testIsOpen()
  16. {
  17. $this->assertTrue($this->_em->isOpen());
  18. $this->_em->close();
  19. $this->assertFalse($this->_em->isOpen());
  20. }
  21. public function testGetConnection()
  22. {
  23. $this->assertInstanceOf('\Doctrine\DBAL\Connection', $this->_em->getConnection());
  24. }
  25. public function testGetMetadataFactory()
  26. {
  27. $this->assertInstanceOf('\Doctrine\ORM\Mapping\ClassMetadataFactory', $this->_em->getMetadataFactory());
  28. }
  29. public function testGetConfiguration()
  30. {
  31. $this->assertInstanceOf('\Doctrine\ORM\Configuration', $this->_em->getConfiguration());
  32. }
  33. public function testGetUnitOfWork()
  34. {
  35. $this->assertInstanceOf('\Doctrine\ORM\UnitOfWork', $this->_em->getUnitOfWork());
  36. }
  37. public function testGetProxyFactory()
  38. {
  39. $this->assertInstanceOf('\Doctrine\ORM\Proxy\ProxyFactory', $this->_em->getProxyFactory());
  40. }
  41. public function testGetEventManager()
  42. {
  43. $this->assertInstanceOf('\Doctrine\Common\EventManager', $this->_em->getEventManager());
  44. }
  45. public function testCreateNativeQuery()
  46. {
  47. $rsm = new \Doctrine\ORM\Query\ResultSetMapping();
  48. $query = $this->_em->createNativeQuery('SELECT foo', $rsm);
  49. $this->assertSame('SELECT foo', $query->getSql());
  50. }
  51. public function testCreateQueryBuilder()
  52. {
  53. $this->assertInstanceOf('\Doctrine\ORM\QueryBuilder', $this->_em->createQueryBuilder());
  54. }
  55. public function testCreateQueryBuilderAliasValid()
  56. {
  57. $q = $this->_em->createQueryBuilder()
  58. ->select('u')->from('Doctrine\Tests\Models\CMS\CmsUser', 'u');
  59. $q2 = clone $q;
  60. $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $q->getQuery()->getDql());
  61. $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $q2->getQuery()->getDql());
  62. $q3 = clone $q;
  63. $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $q3->getQuery()->getDql());
  64. }
  65. public function testCreateQuery_DqlIsOptional()
  66. {
  67. $this->assertInstanceOf('\Doctrine\ORM\Query', $this->_em->createQuery());
  68. }
  69. public function testGetPartialReference()
  70. {
  71. $user = $this->_em->getPartialReference('Doctrine\Tests\Models\CMS\CmsUser', 42);
  72. $this->assertTrue($this->_em->contains($user));
  73. $this->assertEquals(42, $user->id);
  74. $this->assertNull($user->getName());
  75. }
  76. public function testCreateQuery()
  77. {
  78. $q = $this->_em->createQuery('SELECT 1');
  79. $this->assertInstanceOf('\Doctrine\ORM\Query', $q);
  80. $this->assertEquals('SELECT 1', $q->getDql());
  81. }
  82. static public function dataMethodsAffectedByNoObjectArguments()
  83. {
  84. return array(
  85. array('persist'),
  86. array('remove'),
  87. array('merge'),
  88. array('refresh'),
  89. array('detach')
  90. );
  91. }
  92. /**
  93. * @dataProvider dataMethodsAffectedByNoObjectArguments
  94. * @expectedException \InvalidArgumentException
  95. * @param string $methodName
  96. */
  97. public function testThrowsExceptionOnNonObjectValues($methodName) {
  98. $this->_em->$methodName(null);
  99. }
  100. static public function dataAffectedByErrorIfClosedException()
  101. {
  102. return array(
  103. array('flush'),
  104. array('persist'),
  105. array('remove'),
  106. array('merge'),
  107. array('refresh'),
  108. );
  109. }
  110. /**
  111. * @dataProvider dataAffectedByErrorIfClosedException
  112. * @param string $methodName
  113. */
  114. public function testAffectedByErrorIfClosedException($methodName)
  115. {
  116. $this->setExpectedException('Doctrine\ORM\ORMException', 'closed');
  117. $this->_em->close();
  118. $this->_em->$methodName(new \stdClass());
  119. }
  120. /**
  121. * @group DDC-1125
  122. */
  123. public function testTransactionalAcceptsReturn()
  124. {
  125. $return = $this->_em->transactional(function ($em) {
  126. return 'foo';
  127. });
  128. $this->assertEquals('foo', $return);
  129. }
  130. }