SetupTest.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace Doctrine\Tests\ORM\Tools;
  3. use Doctrine\ORM\Tools\Setup;
  4. use Doctrine\Common\Cache\ArrayCache;
  5. require_once __DIR__ . '/../../TestInit.php';
  6. class SetupTest extends \Doctrine\Tests\OrmTestCase
  7. {
  8. private $originalAutoloaderCount;
  9. private $originalIncludePath;
  10. public function setUp()
  11. {
  12. if (strpos(\Doctrine\ORM\Version::VERSION, "DEV") === false) {
  13. $this->markTestSkipped("Test only runs in a dev-installation from Github");
  14. }
  15. $this->originalAutoloaderCount = count(spl_autoload_functions());
  16. $this->originalIncludePath = get_include_path();
  17. }
  18. public function testGitAutoload()
  19. {
  20. Setup::registerAutoloadGit(__DIR__ . "/../../../../../");
  21. $this->assertEquals($this->originalAutoloaderCount + 4, count(spl_autoload_functions()));
  22. }
  23. public function testPEARAutoload()
  24. {
  25. set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . "/../../../../../lib/vendor/doctrine-common/lib");
  26. Setup::registerAutoloadPEAR();
  27. $this->assertEquals($this->originalAutoloaderCount + 2, count(spl_autoload_functions()));
  28. }
  29. public function testDirectoryAutoload()
  30. {
  31. Setup::registerAutoloadDirectory(__DIR__ . "/../../../../../lib/vendor/doctrine-common/lib");
  32. $this->assertEquals($this->originalAutoloaderCount + 2, count(spl_autoload_functions()));
  33. }
  34. public function testAnnotationConfiguration()
  35. {
  36. $config = Setup::createAnnotationMetadataConfiguration(array(), true);
  37. $this->assertInstanceOf('Doctrine\ORM\Configuration', $config);
  38. $this->assertEquals(sys_get_temp_dir(), $config->getProxyDir());
  39. $this->assertEquals('DoctrineProxies', $config->getProxyNamespace());
  40. $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\AnnotationDriver', $config->getMetadataDriverImpl());
  41. }
  42. public function testXMLConfiguration()
  43. {
  44. $config = Setup::createXMLMetadataConfiguration(array(), true);
  45. $this->assertInstanceOf('Doctrine\ORM\Configuration', $config);
  46. $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\XmlDriver', $config->getMetadataDriverImpl());
  47. }
  48. public function testYAMLConfiguration()
  49. {
  50. $config = Setup::createYAMLMetadataConfiguration(array(), true);
  51. $this->assertInstanceOf('Doctrine\ORM\Configuration', $config);
  52. $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\YamlDriver', $config->getMetadataDriverImpl());
  53. }
  54. /**
  55. * @group DDC-1350
  56. */
  57. public function testConfigureProxyDir()
  58. {
  59. $config = Setup::createAnnotationMetadataConfiguration(array(), true, "/foo");
  60. $this->assertEquals('/foo', $config->getProxyDir());
  61. }
  62. /**
  63. * @group DDC-1350
  64. */
  65. public function testConfigureCache()
  66. {
  67. $cache = new ArrayCache();
  68. $config = Setup::createAnnotationMetadataConfiguration(array(), true, null, $cache);
  69. $this->assertSame($cache, $config->getResultCacheImpl());
  70. $this->assertSame($cache, $config->getMetadataCacheImpl());
  71. $this->assertSame($cache, $config->getQueryCacheImpl());
  72. }
  73. public function tearDown()
  74. {
  75. set_include_path($this->originalIncludePath);
  76. $loaders = spl_autoload_functions();
  77. for ($i = 0; $i < count($loaders); $i++) {
  78. if ($i > $this->originalAutoloaderCount+1) {
  79. spl_autoload_unregister($loaders[$i]);
  80. }
  81. }
  82. }
  83. }