SetupTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 tearDown()
  19. {
  20. if ( ! $this->originalIncludePath) {
  21. return;
  22. }
  23. set_include_path($this->originalIncludePath);
  24. $loaders = spl_autoload_functions();
  25. for ($i = 0; $i < count($loaders); $i++) {
  26. if ($i > $this->originalAutoloaderCount+1) {
  27. spl_autoload_unregister($loaders[$i]);
  28. }
  29. }
  30. }
  31. public function testGitAutoload()
  32. {
  33. Setup::registerAutoloadGit(__DIR__ . "/../../../../../");
  34. $this->assertEquals($this->originalAutoloaderCount + 4, count(spl_autoload_functions()));
  35. }
  36. public function testPEARAutoload()
  37. {
  38. set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . "/../../../../../lib/vendor/doctrine-common/lib");
  39. Setup::registerAutoloadPEAR();
  40. $this->assertEquals($this->originalAutoloaderCount + 2, count(spl_autoload_functions()));
  41. }
  42. public function testDirectoryAutoload()
  43. {
  44. Setup::registerAutoloadDirectory(__DIR__ . "/../../../../../lib/vendor/doctrine-common/lib");
  45. $this->assertEquals($this->originalAutoloaderCount + 2, count(spl_autoload_functions()));
  46. }
  47. public function testAnnotationConfiguration()
  48. {
  49. $config = Setup::createAnnotationMetadataConfiguration(array(), true);
  50. $this->assertInstanceOf('Doctrine\ORM\Configuration', $config);
  51. $this->assertEquals(sys_get_temp_dir(), $config->getProxyDir());
  52. $this->assertEquals('DoctrineProxies', $config->getProxyNamespace());
  53. $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\AnnotationDriver', $config->getMetadataDriverImpl());
  54. }
  55. public function testXMLConfiguration()
  56. {
  57. $config = Setup::createXMLMetadataConfiguration(array(), true);
  58. $this->assertInstanceOf('Doctrine\ORM\Configuration', $config);
  59. $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\XmlDriver', $config->getMetadataDriverImpl());
  60. }
  61. public function testYAMLConfiguration()
  62. {
  63. $config = Setup::createYAMLMetadataConfiguration(array(), true);
  64. $this->assertInstanceOf('Doctrine\ORM\Configuration', $config);
  65. $this->assertInstanceOf('Doctrine\ORM\Mapping\Driver\YamlDriver', $config->getMetadataDriverImpl());
  66. }
  67. /**
  68. * @group DDC-1350
  69. */
  70. public function testConfigureProxyDir()
  71. {
  72. $config = Setup::createAnnotationMetadataConfiguration(array(), true, "/foo");
  73. $this->assertEquals('/foo', $config->getProxyDir());
  74. }
  75. /**
  76. * @group DDC-1350
  77. */
  78. public function testConfigureCache()
  79. {
  80. $cache = new ArrayCache();
  81. $config = Setup::createAnnotationMetadataConfiguration(array(), true, null, $cache);
  82. $this->assertSame($cache, $config->getResultCacheImpl());
  83. $this->assertSame($cache, $config->getMetadataCacheImpl());
  84. $this->assertSame($cache, $config->getQueryCacheImpl());
  85. }
  86. }