ClassUtilsTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Doctrine\Tests\Common\Util
  3. {
  4. use Doctrine\Tests\DoctrineTestCase;
  5. use Doctrine\Common\Util\ClassUtils;
  6. class ClassUtilsTest extends DoctrineTestCase
  7. {
  8. static public function dataGetClass()
  9. {
  10. return array(
  11. array('stdClass', 'stdClass'),
  12. array('Doctrine\Common\Util\ClassUtils', 'Doctrine\Common\Util\ClassUtils'),
  13. array( 'MyProject\Proxies\__CG__\stdClass', 'stdClass' ),
  14. array( 'MyProject\Proxies\__CG__\OtherProject\Proxies\__CG__\stdClass', 'stdClass' ),
  15. array( 'MyProject\Proxies\__CG__\Doctrine\Tests\Common\Util\ChildObject','Doctrine\Tests\Common\Util\ChildObject' )
  16. );
  17. }
  18. /**
  19. * @dataProvider dataGetClass
  20. */
  21. public function testGetRealClass($className, $expectedClassName)
  22. {
  23. $this->assertEquals($expectedClassName, ClassUtils::getRealClass($className));
  24. }
  25. /**
  26. * @dataProvider dataGetClass
  27. */
  28. public function testGetClass( $className, $expectedClassName )
  29. {
  30. $object = new $className();
  31. $this->assertEquals($expectedClassName, ClassUtils::getClass($object));
  32. }
  33. public function testGetParentClass()
  34. {
  35. $parentClass = ClassUtils::getParentClass( 'MyProject\Proxies\__CG__\OtherProject\Proxies\__CG__\Doctrine\Tests\Common\Util\ChildObject' );
  36. $this->assertEquals('stdClass', $parentClass);
  37. }
  38. public function testGenerateProxyClassName()
  39. {
  40. $this->assertEquals( 'Proxies\__CG__\stdClass', ClassUtils::generateProxyClassName( 'stdClass', 'Proxies' ) );
  41. }
  42. /**
  43. * @dataProvider dataGetClass
  44. */
  45. public function testNewReflectionClass( $className, $expectedClassName )
  46. {
  47. $reflClass = ClassUtils::newReflectionClass( $className );
  48. $this->assertEquals( $expectedClassName, $reflClass->getName() );
  49. }
  50. /**
  51. * @dataProvider dataGetClass
  52. */
  53. public function testNewReflectionObject( $className, $expectedClassName )
  54. {
  55. $object = new $className;
  56. $reflClass = ClassUtils::newReflectionObject( $object );
  57. $this->assertEquals( $expectedClassName, $reflClass->getName() );
  58. }
  59. }
  60. class ChildObject extends \stdClass
  61. {
  62. }
  63. }
  64. namespace MyProject\Proxies\__CG__
  65. {
  66. class stdClass extends \stdClass
  67. {
  68. }
  69. }
  70. namespace MyProject\Proxies\__CG__\Doctrine\Tests\Common\Util
  71. {
  72. class ChildObject extends \Doctrine\Tests\Common\Util\ChildObject
  73. {
  74. }
  75. }
  76. namespace MyProject\Proxies\__CG__\OtherProject\Proxies\__CG__
  77. {
  78. class stdClass extends \MyProject\Proxies\__CG__\stdClass
  79. {
  80. }
  81. }
  82. namespace MyProject\Proxies\__CG__\OtherProject\Proxies\__CG__\Doctrine\Tests\Common\Util
  83. {
  84. class ChildObject extends \MyProject\Proxies\__CG__\Doctrine\Tests\Common\Util\ChildObject
  85. {
  86. }
  87. }