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

/tests/units/classes/report/fields/runner/php/path/cli.php

http://github.com/mageekguy/atoum
PHP | 133 lines | 123 code | 10 blank | 0 comment | 0 complexity | 16d50364774645f4bb86d0490ea90ef7 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\report\fields\runner\php\path;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\locale,
  6. mageekguy\atoum\cli\prompt,
  7. mageekguy\atoum\cli\colorizer,
  8. mageekguy\atoum\tests\units,
  9. mageekguy\atoum\report\fields\runner
  10. ;
  11. require_once __DIR__ . '/../../../../../../runner.php';
  12. class cli extends atoum\test
  13. {
  14. public function testClass()
  15. {
  16. $this->testedClass->extends('mageekguy\atoum\report\fields\runner\php\path');
  17. }
  18. public function test__construct()
  19. {
  20. $this
  21. ->if($field = new runner\php\path\cli())
  22. ->then
  23. ->object($field->getPrompt())->isEqualTo(new prompt())
  24. ->object($field->getTitleColorizer())->isEqualTo(new colorizer())
  25. ->object($field->getPathColorizer())->isEqualTo(new colorizer())
  26. ->object($field->getLocale())->isEqualTo(new locale())
  27. ;
  28. }
  29. public function testSetPrompt()
  30. {
  31. $this
  32. ->if($field = new runner\php\path\cli())
  33. ->then
  34. ->object($field->setPrompt($prompt = new prompt()))->isIdenticalTo($field)
  35. ->object($field->getPrompt())->isIdenticalTo($prompt)
  36. ->object($field->setPrompt())->isIdenticalTo($field)
  37. ->object($field->getPrompt())
  38. ->isNotIdenticalTo($prompt)
  39. ->isEqualTo(new prompt())
  40. ;
  41. }
  42. public function testSetTitleColorizer()
  43. {
  44. $this
  45. ->if($field = new runner\php\path\cli())
  46. ->then
  47. ->object($field->setTitleColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  48. ->object($field->getTitleColorizer())->isIdenticalTo($colorizer)
  49. ->object($field->setTitleColorizer())->isIdenticalTo($field)
  50. ->object($field->getTitleColorizer())
  51. ->isNotIdenticalTo($colorizer)
  52. ->isEqualTo(new colorizer())
  53. ;
  54. }
  55. public function testSetPathColorizer()
  56. {
  57. $this
  58. ->if($field = new runner\php\path\cli())
  59. ->then
  60. ->object($field->setPathColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  61. ->object($field->getPathColorizer())->isIdenticalTo($colorizer)
  62. ->object($field->setPathColorizer())->isIdenticalTo($field)
  63. ->object($field->getPathColorizer())
  64. ->isNotIdenticalTo($colorizer)
  65. ->isEqualTo(new colorizer())
  66. ;
  67. }
  68. public function testHandleEvent()
  69. {
  70. $this
  71. ->if($field = new runner\php\path\cli())
  72. ->and($score = new \mock\mageekguy\atoum\runner\score())
  73. ->and($score->getMockController()->getPhpPath = $phpPath = uniqid())
  74. ->then
  75. ->boolean($field->handleEvent(atoum\runner::runStop, $runner = new atoum\runner()))->isFalse()
  76. ->variable($field->getPath())->isNull()
  77. ->if($runner->setScore($score))
  78. ->boolean($field->handleEvent(atoum\runner::runStart, $runner))->isTrue()
  79. ->string($field->getPath())->isEqualTo($phpPath)
  80. ;
  81. }
  82. public function test__toString()
  83. {
  84. $this
  85. ->if($score = new \mock\mageekguy\atoum\runner\score())
  86. ->and($score->getMockController()->getPhpPath = $phpPath = uniqid())
  87. ->and($defaultField = new runner\php\path\cli())
  88. ->then
  89. ->castToString($defaultField)->isEqualTo('PHP path: ' . PHP_EOL)
  90. ->if($runner = new atoum\runner())
  91. ->and($runner->setScore($score))
  92. ->and($defaultField->handleEvent(atoum\runner::runStart, $runner))
  93. ->then
  94. ->castToString($defaultField)->isEqualTo('PHP path:' . ' ' . $phpPath . PHP_EOL)
  95. ->if($customField = new runner\php\path\cli())
  96. ->and($customField->setPrompt($prompt = new prompt(uniqid())))
  97. ->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))
  98. ->and($customField->setPathColorizer($pathColorizer = new colorizer(uniqid(), uniqid())))
  99. ->and($customField->setLocale($locale = new locale()))
  100. ->then
  101. ->castToString($customField)->isEqualTo(
  102. $prompt .
  103. sprintf(
  104. $locale->_('%1$s: %2$s'),
  105. $titleColorizer->colorize($locale->_('PHP path')),
  106. $pathColorizer->colorize('')
  107. ) .
  108. PHP_EOL
  109. )
  110. ->if($customField->handleEvent(atoum\runner::runStart, $runner))
  111. ->then
  112. ->castToString($customField)->isEqualTo(
  113. $prompt .
  114. sprintf(
  115. $locale->_('%1$s: %2$s'),
  116. $titleColorizer->colorize($locale->_('PHP path')),
  117. $pathColorizer->colorize($phpPath)
  118. ) .
  119. PHP_EOL
  120. )
  121. ;
  122. }
  123. }