PageRenderTime 64ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/core/src/test/php/net/xp_framework/unittest/reflection/ClassFromDynamicDefinitionTest.class.php

http://github.com/xp-framework/xp-framework
PHP | 105 lines | 70 code | 12 blank | 23 comment | 0 complexity | f8237b19d745e3354ceb407200bf2ac3 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php namespace net\xp_framework\unittest\reflection;
  2. use lang\DynamicClassLoader;
  3. /**
  4. * TestCase for classloading
  5. *
  6. * @see xp://lang.DynamicClassLoader#loadUri
  7. */
  8. class ClassFromDynamicDefinitionTest extends ClassFromUriTest {
  9. /**
  10. * Creates fixture
  11. *
  12. * @return lang.IClassLoader
  13. */
  14. protected function newFixture() {
  15. return DynamicClassLoader::instanceFor('test');
  16. }
  17. /**
  18. * Creates underlying base for class loader, e.g. a directory or a .XAR file
  19. *
  20. * @return net.xp_framework.unittest.reflection.ClassFromUriBase
  21. */
  22. protected static function baseImpl() {
  23. return newinstance('net.xp_framework.unittest.reflection.ClassFromUriBase', array(), '{
  24. protected $t= NULL;
  25. public function create() {
  26. // NOOP
  27. }
  28. public function delete() {
  29. // NOOP
  30. }
  31. public function newType($type, $name) {
  32. if (FALSE === ($p= strrpos($name, "."))) {
  33. $class= $name;
  34. $ns= "";
  35. } else {
  36. $class= substr($name, $p + 1);
  37. $ns= "namespace ".strtr(substr($name, 0, $p), ".", "\\\\").";";
  38. }
  39. \lang\DynamicClassLoader::instanceFor("test")->setClassBytes($name, sprintf(
  40. "%s %s %s extends \lang\Object { }",
  41. $ns,
  42. $type,
  43. $class
  44. ));
  45. }
  46. public function newFile($name, $contents) {
  47. // Not supported
  48. }
  49. public function path() {
  50. return "dyn://";
  51. }
  52. }');
  53. }
  54. #[@test]
  55. public function provides_a_relative_path_in_root() {
  56. $this->assertTrue($this->fixture->providesUri('dyn://CLT1'));
  57. }
  58. #[@test]
  59. public function load_from_a_relative_path_in_root() {
  60. $this->assertEquals(
  61. $this->fixture->loadClass('CLT1'),
  62. $this->fixture->loadUri('dyn://CLT1')
  63. );
  64. }
  65. #[@test]
  66. public function from_a_relative_path() {
  67. $this->assertEquals(
  68. $this->fixture->loadClass('net.xp_framework.unittest.reflection.CLT2'),
  69. $this->fixture->loadUri('dyn://net.xp_framework.unittest.reflection.CLT2')
  70. );
  71. }
  72. #[@test, @ignore('Not applicablle for DynamicClassLoader\'s URIs')]
  73. public function from_a_relative_path_with_dot() {
  74. }
  75. #[@test, @ignore('Not applicablle for DynamicClassLoader\'s URIs')]
  76. public function from_a_relative_path_with_dot_dot() {
  77. }
  78. #[@test, @ignore('Not applicablle for DynamicClassLoader\'s URIs')]
  79. public function from_a_relative_path_with_multiple_directory_separators() {
  80. }
  81. #[@test, @ignore('Not applicablle for DynamicClassLoader\'s URIs')]
  82. public function from_an_absolute_path_in_root() {
  83. }
  84. #[@test, @ignore('Not applicablle for DynamicClassLoader\'s URIs')]
  85. public function from_an_absolute_path() {
  86. }
  87. }