SetupTest.php 2.8KB

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