PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/units/classes/scripts/treemap.php

http://github.com/mageekguy/atoum
PHP | 170 lines | 154 code | 16 blank | 0 comment | 0 complexity | d5cb8f9ca56a116321ad596f9b56b29a MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\scripts;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\scripts\treemap as testedClass,
  6. mock\mageekguy\atoum\scripts\treemap\analyzer as analyzer,
  7. mock\mageekguy\atoum\scripts\treemap\categorizer as categorizer
  8. ;
  9. require_once __DIR__ . '/../../runner.php';
  10. class treemap extends atoum\test
  11. {
  12. public function testClass()
  13. {
  14. $this->testedClass->extends('mageekguy\atoum\script\configurable');
  15. }
  16. public function testClassConstants()
  17. {
  18. $this->string(testedClass::defaultConfigFile)->isEqualTo('.treemap.php');
  19. }
  20. public function test__construct()
  21. {
  22. $this
  23. ->if($treemap = new testedClass($name = uniqid()))
  24. ->then
  25. ->string($treemap->getName())->isEqualTo($name)
  26. ->object($treemap->getAdapter())->isEqualTo(new atoum\adapter())
  27. ->object($treemap->getIncluder())->isEqualTo(new atoum\includer())
  28. ->variable($treemap->getProjectName())->isNull()
  29. ->array($treemap->getDirectories())->isEmpty()
  30. ->variable($treemap->getOutputDirectory())->isNull()
  31. ->array($treemap->getAnalyzers())->isEmpty()
  32. ->if($treemap = new testedClass($name = uniqid(), $adapter = new atoum\adapter()))
  33. ->then
  34. ->string($treemap->getName())->isEqualTo($name)
  35. ->object($treemap->getAdapter())->isIdenticalTo($adapter)
  36. ->object($treemap->getIncluder())->isEqualTo(new atoum\includer())
  37. ->variable($treemap->getProjectName())->isNull()
  38. ->array($treemap->getDirectories())->isEmpty()
  39. ->variable($treemap->getOutputDirectory())->isNull()
  40. ->array($treemap->getAnalyzers())->isEmpty()
  41. ;
  42. }
  43. public function testSetProjectName()
  44. {
  45. $this
  46. ->if($treemap = new testedClass(uniqid()))
  47. ->then
  48. ->object($treemap->setProjectName($projectName = uniqid()))->isIdenticalTo($treemap)
  49. ->string($treemap->getProjectName())->isEqualTo($projectName)
  50. ;
  51. }
  52. public function testSetProjectUrl()
  53. {
  54. $this
  55. ->if($treemap = new testedClass(uniqid()))
  56. ->then
  57. ->object($treemap->setProjectUrl($projectUrl = uniqid()))->isIdenticalTo($treemap)
  58. ->string($treemap->getProjectUrl())->isEqualTo($projectUrl)
  59. ;
  60. }
  61. public function testSetCodeUrl()
  62. {
  63. $this
  64. ->if($treemap = new testedClass(uniqid()))
  65. ->then
  66. ->object($treemap->setCodeUrl($codeUrl = uniqid()))->isIdenticalTo($treemap)
  67. ->string($treemap->getCodeUrl())->isEqualTo($codeUrl)
  68. ;
  69. }
  70. public function testAddDirectory()
  71. {
  72. $this
  73. ->if($treemap = new testedClass(uniqid()))
  74. ->then
  75. ->object($treemap->addDirectory($directory = uniqid()))->isIdenticalTo($treemap)
  76. ->array($treemap->getDirectories())->isEqualTo(array($directory))
  77. ->object($treemap->addDirectory($otherDirectory = uniqid()))->isIdenticalTo($treemap)
  78. ->array($treemap->getDirectories())->isEqualTo(array($directory, $otherDirectory))
  79. ->object($treemap->addDirectory($directory))->isIdenticalTo($treemap)
  80. ->array($treemap->getDirectories())->isEqualTo(array($directory, $otherDirectory))
  81. ;
  82. }
  83. public function testSetHtmlDirectory()
  84. {
  85. $this
  86. ->if($treemap = new testedClass(uniqid()))
  87. ->then
  88. ->object($treemap->setHtmlDirectory($directory = uniqid()))->isIdenticalTo($treemap)
  89. ->string($treemap->getHtmlDirectory())->isEqualTo($directory)
  90. ;
  91. }
  92. public function testSetOutputDirectory()
  93. {
  94. $this
  95. ->if($treemap = new testedClass(uniqid()))
  96. ->then
  97. ->object($treemap->setOutputDirectory($directory = uniqid()))->isIdenticalTo($treemap)
  98. ->string($treemap->getOutputDirectory())->isEqualTo($directory)
  99. ;
  100. }
  101. public function testGetOnlyJsonFile()
  102. {
  103. $this
  104. ->if($treemap = new testedClass(uniqid()))
  105. ->then
  106. ->boolean($treemap->getOnlyJsonFile())->isFalse()
  107. ->boolean($treemap->getOnlyJsonFile(null))->isFalse()
  108. ->boolean($treemap->getOnlyJsonFile(true))->isTrue()
  109. ->boolean($treemap->getOnlyJsonFile())->isTrue()
  110. ->boolean($treemap->getOnlyJsonFile(null))->isTrue()
  111. ->boolean($treemap->getOnlyJsonFile(false))->isFalse()
  112. ->boolean($treemap->getOnlyJsonFile())->isFalse()
  113. ->boolean($treemap->getOnlyJsonFile(null))->isFalse()
  114. ;
  115. }
  116. public function testAddAnalyzer()
  117. {
  118. $this
  119. ->if($treemap = new testedClass(uniqid()))
  120. ->then
  121. ->object($treemap->addAnalyzer($analyzer = new analyzer()))->isIdenticalTo($treemap)
  122. ->array($treemap->getAnalyzers())->isEqualTo(array($analyzer))
  123. ->object($treemap->addAnalyzer($otherAnalyzer = new analyzer()))->isIdenticalTo($treemap)
  124. ->array($treemap->getAnalyzers())->isEqualTo(array($analyzer, $otherAnalyzer))
  125. ;
  126. }
  127. public function testAddCategorizer()
  128. {
  129. $this
  130. ->if($treemap = new testedClass(uniqid()))
  131. ->then
  132. ->object($treemap->addCategorizer($categorizer = new categorizer(uniqid())))->isIdenticalTo($treemap)
  133. ->array($treemap->getCategorizers())->isEqualTo(array($categorizer))
  134. ->object($treemap->addCategorizer($otherCategorizer = new categorizer(uniqid())))->isIdenticalTo($treemap)
  135. ->array($treemap->getCategorizers())->isEqualTo(array($categorizer, $otherCategorizer))
  136. ;
  137. }
  138. public function testUseConfigFile()
  139. {
  140. $this
  141. ->if($treemap = new testedClass(uniqid()))
  142. ->and($treemap->setIncluder($includer = new \mock\atoum\includer()))
  143. ->and($this->calling($includer)->includePath = function() {})
  144. ->then
  145. ->object($treemap->useConfigFile($file = uniqid()))->isIdenticalTo($treemap)
  146. ->mock($includer)->call('includePath')->withArguments($file)->once()
  147. ->if($this->calling($includer)->includePath->throw = new atoum\includer\exception())
  148. ->then
  149. ->exception(function() use ($treemap, & $file) { $treemap->useConfigFile($file = uniqid()); })
  150. ->isInstanceOf('mageekguy\atoum\includer\exception')
  151. ->hasMessage('Unable to find configuration file \'' . $file . '\'')
  152. ;
  153. }
  154. }