EntityManagerMock.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /*
  3. * $Id$
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information, see
  19. * <http://www.doctrine-project.org>.
  20. */
  21. namespace Doctrine\Tests\Mocks;
  22. use Doctrine\ORM\Proxy\ProxyFactory;
  23. /**
  24. * Special EntityManager mock used for testing purposes.
  25. */
  26. class EntityManagerMock extends \Doctrine\ORM\EntityManager
  27. {
  28. private $_uowMock;
  29. private $_proxyFactoryMock;
  30. private $_idGenerators = array();
  31. /**
  32. * @override
  33. */
  34. public function getUnitOfWork()
  35. {
  36. return isset($this->_uowMock) ? $this->_uowMock : parent::getUnitOfWork();
  37. }
  38. /* Mock API */
  39. /**
  40. * Sets a (mock) UnitOfWork that will be returned when getUnitOfWork() is called.
  41. *
  42. * @param <type> $uow
  43. */
  44. public function setUnitOfWork($uow)
  45. {
  46. $this->_uowMock = $uow;
  47. }
  48. public function setProxyFactory($proxyFactory)
  49. {
  50. $this->_proxyFactoryMock = $proxyFactory;
  51. }
  52. public function getProxyFactory()
  53. {
  54. return isset($this->_proxyFactoryMock) ? $this->_proxyFactoryMock : parent::getProxyFactory();
  55. }
  56. /**
  57. * Mock factory method to create an EntityManager.
  58. *
  59. * @param unknown_type $conn
  60. * @param unknown_type $name
  61. * @param Doctrine_Configuration $config
  62. * @param Doctrine_EventManager $eventManager
  63. * @return Doctrine\ORM\EntityManager
  64. */
  65. public static function create($conn, \Doctrine\ORM\Configuration $config = null,
  66. \Doctrine\Common\EventManager $eventManager = null)
  67. {
  68. if (is_null($config)) {
  69. $config = new \Doctrine\ORM\Configuration();
  70. $config->setProxyDir(__DIR__ . '/../Proxies');
  71. $config->setProxyNamespace('Doctrine\Tests\Proxies');
  72. $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
  73. }
  74. if (is_null($eventManager)) {
  75. $eventManager = new \Doctrine\Common\EventManager();
  76. }
  77. return new EntityManagerMock($conn, $config, $eventManager);
  78. }
  79. /*
  80. public function setIdGenerator($className, $generator)
  81. {
  82. $this->_idGenerators[$className] = $generator;
  83. }
  84. */
  85. /** @override */
  86. /* public function getIdGenerator($className)
  87. {
  88. if (isset($this->_idGenerators[$className])) {
  89. return $this->_idGenerators[$className];
  90. }
  91. return parent::getIdGenerator($className);
  92. }
  93. */
  94. }