PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/units/classes/cli/colorizer.php

http://github.com/mageekguy/atoum
PHP | 161 lines | 150 code | 11 blank | 0 comment | 0 complexity | b13806ccbdd9d3cefc49888d409d984f MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\cli;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\cli
  6. ;
  7. require_once __DIR__ . '/../../runner.php';
  8. class colorizer extends atoum\test
  9. {
  10. public function testClass()
  11. {
  12. $this->testedClass->implements('mageekguy\atoum\writer\decorator');
  13. }
  14. public function test__construct()
  15. {
  16. $this
  17. ->if($colorizer = new cli\colorizer())
  18. ->then
  19. ->variable($colorizer->getForeground())->isNull()
  20. ->variable($colorizer->getBackground())->isNull()
  21. ->object($colorizer->getCli())->isEqualTo(new atoum\cli())
  22. ->variable($colorizer->getPattern())->isNull()
  23. ->if($colorizer = new cli\colorizer($foreground = uniqid()))
  24. ->then
  25. ->string($colorizer->getForeground())->isEqualTo($foreground)
  26. ->variable($colorizer->getBackground())->isNull()
  27. ->object($colorizer->getCli())->isEqualTo(new atoum\cli())
  28. ->variable($colorizer->getPattern())->isNull()
  29. ->variable($colorizer->getPattern())->isNull()
  30. ->if($colorizer = new cli\colorizer($foreground = rand(1, PHP_INT_MAX)))
  31. ->then
  32. ->string($colorizer->getForeground())->isEqualTo($foreground)
  33. ->variable($colorizer->getBackground())->isNull()
  34. ->object($colorizer->getCli())->isEqualTo(new atoum\cli())
  35. ->variable($colorizer->getPattern())->isNull()
  36. ->if($colorizer = new cli\colorizer($foreground = uniqid(), $background = uniqid()))
  37. ->then
  38. ->string($colorizer->getForeground())->isEqualTo($foreground)
  39. ->string($colorizer->getBackground())->isEqualTo($background)
  40. ->object($colorizer->getCli())->isEqualTo(new atoum\cli())
  41. ->variable($colorizer->getPattern())->isNull()
  42. ->if($colorizer = new cli\colorizer($foreground = uniqid(), $background = rand(1, PHP_INT_MAX)))
  43. ->then
  44. ->string($colorizer->getForeground())->isEqualTo($foreground)
  45. ->string($colorizer->getBackground())->isEqualTo($background)
  46. ->object($colorizer->getCli())->isEqualTo(new atoum\cli())
  47. ->variable($colorizer->getPattern())->isNull()
  48. ->if($colorizer = new cli\colorizer($foreground = uniqid(), $background = rand(1, PHP_INT_MAX), $cli = new atoum\cli()))
  49. ->then
  50. ->string($colorizer->getForeground())->isEqualTo($foreground)
  51. ->string($colorizer->getBackground())->isEqualTo($background)
  52. ->object($colorizer->getCli())->isIdenticalTo($cli)
  53. ->variable($colorizer->getPattern())->isNull()
  54. ;
  55. }
  56. public function testSetCli()
  57. {
  58. $this
  59. ->if($colorizer = new cli\colorizer(uniqid()))
  60. ->then
  61. ->object($colorizer->setCli($cli = new atoum\cli()))->isIdenticalTo($colorizer)
  62. ->object($colorizer->getCli())->isIdenticalTo($cli)
  63. ->object($colorizer->setCli())->isIdenticalTo($colorizer)
  64. ->object($colorizer->getCli())
  65. ->isNotIdenticalTo($cli)
  66. ->isEqualTo(new atoum\cli())
  67. ;
  68. }
  69. public function testSetForeground()
  70. {
  71. $this
  72. ->if($colorizer = new cli\colorizer(uniqid()))
  73. ->then
  74. ->object($colorizer->setForeground($foreground = uniqid()))->isIdenticalTo($colorizer)
  75. ->string($colorizer->getForeground())->isEqualTo($foreground)
  76. ->object($colorizer->setForeground($foreground = rand(1, PHP_INT_MAX)))->isIdenticalTo($colorizer)
  77. ->string($colorizer->getForeground())->isEqualTo($foreground)
  78. ;
  79. }
  80. public function testSetBackground()
  81. {
  82. $this
  83. ->if($colorizer = new cli\colorizer(uniqid()))
  84. ->then
  85. ->object($colorizer->setBackground($background = uniqid()))->isIdenticalTo($colorizer)
  86. ->string($colorizer->getBackground())->isEqualTo($background)
  87. ->object($colorizer->setBackground($background = rand(1, PHP_INT_MAX)))->isIdenticalTo($colorizer)
  88. ->string($colorizer->getBackground())->isEqualTo($background)
  89. ;
  90. }
  91. public function testSetPattern()
  92. {
  93. $this
  94. ->if($colorizer = new cli\colorizer(uniqid()))
  95. ->then
  96. ->object($colorizer->setPattern($pattern = uniqid()))->isIdenticalTo($colorizer)
  97. ->string($colorizer->getPattern())->isEqualTo($pattern)
  98. ;
  99. }
  100. public function testColorize()
  101. {
  102. $this
  103. ->if($colorizer = new cli\colorizer(null, null, $cli = new \mock\mageekguy\atoum\cli()))
  104. ->and($this->calling($cli)->isTerminal = true)
  105. ->then
  106. ->string($colorizer->colorize($string = uniqid()))->isEqualTo($string)
  107. ->if($colorizer = new cli\colorizer($foreground = uniqid(), null, $cli))
  108. ->then
  109. ->string($colorizer->colorize($string = uniqid()))->isEqualTo("\033[" . $foreground . 'm' . $string . "\033[0m")
  110. ->if($colorizer = new cli\colorizer($foreground = uniqid(), $background = uniqid(), $cli))
  111. ->then
  112. ->string($colorizer->colorize($string = uniqid()))->isEqualTo("\033[" . $foreground . 'm' . "\033[" . $background . 'm' . $string . "\033[0m")
  113. ->if($colorizer->setPattern('/^\s*([^:]+:)/'))
  114. ->then
  115. ->string($colorizer->colorize('Error:' . ($string = uniqid())))->isEqualTo("\033[" . $foreground . 'm' . "\033[" . $background . 'mError:' . "\033[0m" . $string)
  116. ->if($colorizer = new cli\colorizer(null, $background = uniqid(), $cli))
  117. ->then
  118. ->string($colorizer->colorize($string = uniqid()))->isEqualTo("\033[" . $background . 'm' . $string . "\033[0m")
  119. ->if($colorizer = new cli\colorizer($foreground = uniqid(), $background = uniqid(), $cli))
  120. ->and($this->calling($cli)->isTerminal = false)
  121. ->then
  122. ->string($colorizer->colorize($string = uniqid()))->isEqualTo($string)
  123. ->if($colorizer->setPattern('/^\s*([^:]+:)/'))
  124. ->then
  125. ->string($colorizer->colorize($string = 'Error:' . uniqid()))->isEqualTo($string)
  126. ;
  127. }
  128. public function testDecorate()
  129. {
  130. $this
  131. ->if($colorizer = new cli\colorizer(null, null, $cli = new \mock\mageekguy\atoum\cli()))
  132. ->and($this->calling($cli)->isTerminal = true)
  133. ->then
  134. ->string($colorizer->decorate($string = uniqid()))->isEqualTo($string)
  135. ->if($colorizer = new cli\colorizer($foreground = uniqid(), null, $cli))
  136. ->then
  137. ->string($colorizer->decorate($string = uniqid()))->isEqualTo("\033[" . $foreground . 'm' . $string . "\033[0m")
  138. ->if($colorizer = new cli\colorizer($foreground = uniqid(), $background = uniqid(), $cli))
  139. ->then
  140. ->string($colorizer->decorate($string = uniqid()))->isEqualTo("\033[" . $foreground . 'm' . "\033[" . $background . 'm' . $string . "\033[0m")
  141. ->if($colorizer = new cli\colorizer(null, $background = uniqid(), $cli))
  142. ->then
  143. ->string($colorizer->decorate($string = uniqid()))->isEqualTo("\033[" . $background . 'm' . $string . "\033[0m")
  144. ->if($colorizer = new cli\colorizer($foreground = uniqid(), $background = uniqid(), $cli))
  145. ->and($this->calling($cli)->isTerminal = false)
  146. ->then
  147. ->string($colorizer->decorate($string = uniqid()))->isEqualTo($string)
  148. ;
  149. }
  150. }