/tests/units/classes/autoloader.php

https://github.com/tharkun/atoum · PHP · 149 lines · 140 code · 9 blank · 0 comment · 0 complexity · 2135e1ccab1376da37279cf879e77175 MD5 · raw file

  1. <?php
  2. namespace mageekguy\atoum\tests\units;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\autoloader as testedClass
  6. ;
  7. require_once __DIR__ . '/../runner.php';
  8. class autoloader extends atoum\test
  9. {
  10. public function testClassConstants()
  11. {
  12. $this
  13. ->string(testedClass::defaultCacheFileName)->isEqualTo('%s.atoum.cache')
  14. ->string(testedClass::defaultFileSuffix)->isEqualTo('.php')
  15. ;
  16. }
  17. public function test__construct()
  18. {
  19. $this
  20. ->if($autoloader = new testedClass())
  21. ->then
  22. ->array($autoloader->getClasses())->isEmpty()
  23. ->variable($autoloader->getCacheFileForInstance())->isEqualTo(testedClass::getCacheFile())
  24. ->array($autoloader->getDirectories())->isEqualTo(array(
  25. 'mageekguy\atoum\\' => array(
  26. array(
  27. atoum\directory . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR,
  28. testedClass::defaultFileSuffix
  29. )
  30. )
  31. )
  32. )
  33. ->array($autoloader->getNamespaceAliases())->isEqualTo(array('atoum\\' => 'mageekguy\\atoum\\'))
  34. ;
  35. }
  36. public function testAddNamespaceAlias()
  37. {
  38. $this
  39. ->if($autoloader = new testedClass())
  40. ->then
  41. ->object($autoloader->addNamespaceAlias($alias = uniqid(), $target = uniqid()))->isIdenticalTo($autoloader)
  42. ->array($autoloader->getNamespaceAliases())->isEqualTo(array(
  43. 'atoum\\' => 'mageekguy\\atoum\\',
  44. $alias . '\\' => $target . '\\'
  45. )
  46. )
  47. ->object($autoloader->addNamespaceAlias($alias, $target))->isIdenticalTo($autoloader)
  48. ->array($autoloader->getNamespaceAliases())->isEqualTo(array(
  49. 'atoum\\' => 'mageekguy\\atoum\\',
  50. $alias . '\\' => $target . '\\'
  51. )
  52. )
  53. ->object($autoloader->addNamespaceAlias('\\' . ($otherAlias = uniqid()), '\\' . ($otherTarget = uniqid())))->isIdenticalTo($autoloader)
  54. ->array($autoloader->getNamespaceAliases())->isEqualTo(array(
  55. 'atoum\\' => 'mageekguy\\atoum\\',
  56. $alias . '\\' => $target . '\\',
  57. $otherAlias . '\\' => $otherTarget . '\\'
  58. )
  59. )
  60. ->object($autoloader->addNamespaceAlias('\\' . ($anOtherAlias = uniqid()) . '\\', '\\' . ($anOtherTarget = uniqid()) . '\\'))->isIdenticalTo($autoloader)
  61. ->array($autoloader->getNamespaceAliases())->isEqualTo(array(
  62. 'atoum\\' => 'mageekguy\\atoum\\',
  63. $alias . '\\' => $target . '\\',
  64. $otherAlias . '\\' => $otherTarget . '\\',
  65. $anOtherAlias . '\\' => $anOtherTarget . '\\'
  66. )
  67. )
  68. ->object($autoloader->addNamespaceAlias('FOO', ($fooTarget = uniqid())))->isIdenticalTo($autoloader)
  69. ->array($autoloader->getNamespaceAliases())->isEqualTo(array(
  70. 'atoum\\' => 'mageekguy\\atoum\\',
  71. $alias . '\\' => $target . '\\',
  72. $otherAlias . '\\' => $otherTarget . '\\',
  73. $anOtherAlias . '\\' => $anOtherTarget . '\\',
  74. 'foo\\' => $fooTarget . '\\'
  75. )
  76. )
  77. ;
  78. }
  79. public function testAddClassAlias()
  80. {
  81. $this
  82. ->if($autoloader = new testedClass())
  83. ->then
  84. ->object($autoloader->addClassAlias($alias = uniqid(), $target = uniqid()))->isIdenticalTo($autoloader)
  85. ->array($autoloader->getClassAliases())->isEqualTo(array(
  86. 'atoum' => 'mageekguy\\atoum\\test',
  87. $alias => $target
  88. )
  89. )
  90. ->object($autoloader->addClassAlias($alias, $target))->isIdenticalTo($autoloader)
  91. ->array($autoloader->getClassAliases())->isEqualTo(array(
  92. 'atoum' => 'mageekguy\\atoum\\test',
  93. $alias => $target
  94. )
  95. )
  96. ->object($autoloader->addClassAlias('\\' . ($otherAlias = uniqid()), '\\' . ($otherTarget = uniqid())))->isIdenticalTo($autoloader)
  97. ->array($autoloader->getClassAliases())->isEqualTo(array(
  98. 'atoum' => 'mageekguy\\atoum\\test',
  99. $alias => $target,
  100. $otherAlias => $otherTarget
  101. )
  102. )
  103. ->object($autoloader->addClassAlias('\\' . ($anOtherAlias = uniqid()) . '\\', '\\' . ($anOtherTarget = uniqid()) . '\\'))->isIdenticalTo($autoloader)
  104. ->array($autoloader->getClassAliases())->isEqualTo(array(
  105. 'atoum' => 'mageekguy\\atoum\\test',
  106. $alias => $target,
  107. $otherAlias => $otherTarget,
  108. $anOtherAlias => $anOtherTarget
  109. )
  110. )
  111. ->object($autoloader->addClassAlias('FOO', '\\' . ($fooTarget = uniqid()) . '\\'))->isIdenticalTo($autoloader)
  112. ->array($autoloader->getClassAliases())->isEqualTo(array(
  113. 'atoum' => 'mageekguy\\atoum\\test',
  114. $alias => $target,
  115. $otherAlias => $otherTarget,
  116. $anOtherAlias => $anOtherTarget,
  117. 'foo' => $fooTarget
  118. )
  119. )
  120. ;
  121. }
  122. public function testGetCacheFile()
  123. {
  124. $this
  125. ->string(testedClass::getCacheFile())->isEqualTo(rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . sprintf(testedClass::defaultCacheFileName, md5($this->getTestedClassPath())))
  126. ->if(testedClass::setCacheFile($cacheFile = uniqid()))
  127. ->then
  128. ->string(testedClass::getCacheFile())->isEqualTo($cacheFile)
  129. ;
  130. }
  131. public function testSetCacheFileForInstance()
  132. {
  133. $this
  134. ->if($autoloader = new testedClass())
  135. ->then
  136. ->object($autoloader->setCacheFileForInstance($path = uniqid()))->isIdenticalTo($autoloader)
  137. ->string($autoloader->getCacheFileForInstance())->isEqualTo($path)
  138. ;
  139. }
  140. }