PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/units/classes/report/fields/test/memory/phing.php

https://github.com/Hywan/atoum
PHP | 148 lines | 138 code | 10 blank | 0 comment | 0 complexity | 7fc75c42eb55d0cf7821332759883548 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\report\fields\test\memory;
  3. use mageekguy\atoum;
  4. use mageekguy\atoum\cli\colorizer;
  5. use mageekguy\atoum\cli\prompt;
  6. use mageekguy\atoum\locale;
  7. use mageekguy\atoum\report\fields\test;
  8. require_once __DIR__ . '/../../../../../runner.php';
  9. class phing extends atoum\test
  10. {
  11. public function testClass()
  12. {
  13. $this->testedClass->extends(atoum\report\fields\test\memory\cli::class);
  14. }
  15. public function test__construct()
  16. {
  17. $this
  18. ->if($field = new test\memory\phing())
  19. ->then
  20. ->object($field->getPrompt())->isEqualTo(new prompt())
  21. ->object($field->getTitleColorizer())->isEqualTo(new colorizer())
  22. ->object($field->getMemoryColorizer())->isEqualTo(new colorizer())
  23. ->object($field->getLocale())->isEqualTo(new locale())
  24. ->variable($field->getValue())->isNull()
  25. ->array($field->getEvents())->isEqualTo([atoum\test::runStop])
  26. ;
  27. }
  28. public function testSetPrompt()
  29. {
  30. $this
  31. ->if($field = new test\memory\phing())
  32. ->then
  33. ->object($field->setPrompt($prompt = new prompt()))->isIdenticalTo($field)
  34. ->object($field->getPrompt())->isIdenticalTo($prompt)
  35. ->object($field->setPrompt())->isIdenticalTo($field)
  36. ->object($field->getPrompt())
  37. ->isNotIdenticalTo($prompt)
  38. ->isEqualTo(new prompt())
  39. ;
  40. }
  41. public function testSetTitleColorizer()
  42. {
  43. $this
  44. ->if($field = new test\memory\phing())
  45. ->then
  46. ->object($field->setTitleColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  47. ->object($field->getTitleColorizer())->isIdenticalTo($colorizer)
  48. ->object($field->setTitleColorizer())->isIdenticalTo($field)
  49. ->object($field->getTitleColorizer())
  50. ->isNotIdenticalTo($colorizer)
  51. ->isEqualTo(new colorizer())
  52. ;
  53. }
  54. public function testSetDurationColorizer()
  55. {
  56. $this
  57. ->if($field = new test\memory\phing())
  58. ->then
  59. ->object($field->setMemoryColorizer($colorizer = new colorizer()))->isIdenticalTo($field)
  60. ->object($field->getMemoryColorizer())->isIdenticalTo($colorizer)
  61. ->object($field->setMemoryColorizer())->isIdenticalTo($field)
  62. ->object($field->getMemoryColorizer())
  63. ->isNotIdenticalTo($colorizer)
  64. ->isEqualTo(new colorizer())
  65. ;
  66. }
  67. public function testHandleEvent()
  68. {
  69. $this
  70. ->if($field = new test\memory\phing())
  71. ->and($score = new \mock\mageekguy\atoum\score())
  72. ->and($score->getMockController()->getTotalMemoryUsage = $totalMemoryUsage = rand(0, PHP_INT_MAX))
  73. ->and($adapter = new atoum\test\adapter())
  74. ->and($adapter->class_exists = true)
  75. ->and($testController = new atoum\mock\controller())
  76. ->and($testController->getTestedClassName = uniqid())
  77. ->and($test = new \mock\mageekguy\atoum\test($adapter))
  78. ->and($test->getMockController()->getScore = $score)
  79. ->then
  80. ->boolean($field->handleEvent(atoum\test::runStart, $test))->isFalse()
  81. ->variable($field->getValue())->isNull()
  82. ->boolean($field->handleEvent(atoum\test::runStop, $test))->isTrue()
  83. ->integer($field->getValue())->isEqualTo($totalMemoryUsage)
  84. ;
  85. }
  86. public function test__toString()
  87. {
  88. $this
  89. ->if($score = new \mock\mageekguy\atoum\score())
  90. ->and($score->getMockController()->getTotalMemoryUsage = $totalMemoryUsage = rand(0, PHP_INT_MAX))
  91. ->and($adapter = new atoum\test\adapter())
  92. ->and($adapter->class_exists = true)
  93. ->and($testController = new atoum\mock\controller())
  94. ->and($testController->getTestedClassName = uniqid())
  95. ->and($test = new \mock\mageekguy\atoum\test($adapter))
  96. ->and($test->getMockController()->getScore = $score)
  97. ->and($defaultField = new test\memory\phing())
  98. ->and($customField = new test\memory\phing())
  99. ->and($customField->setPrompt($prompt = new prompt(uniqid())))
  100. ->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))
  101. ->and($customField->setMemoryColorizer($memoryColorizer = new colorizer(uniqid(), uniqid())))
  102. ->and($customField->setLocale($locale = new locale()))
  103. ->then
  104. ->castToString($defaultField)->isEqualTo($defaultField->getPrompt() . $defaultField->getLocale()->_('unknown'))
  105. ->castToString($customField)->isEqualTo(
  106. $prompt .
  107. sprintf(
  108. $locale->_('%s'),
  109. $memoryColorizer->colorize($locale->_('unknown'))
  110. )
  111. )
  112. ->if($defaultField->handleEvent(atoum\test::runStart, $test))
  113. ->then
  114. ->castToString($defaultField)->isEqualTo($defaultField->getPrompt() . $defaultField->getLocale()->_('unknown'))
  115. ->if($customField->handleEvent(atoum\test::runStart, $test))
  116. ->then
  117. ->castToString($customField)->isEqualTo(
  118. $prompt .
  119. sprintf(
  120. $locale->_('%s'),
  121. $memoryColorizer->colorize($locale->_('unknown'))
  122. )
  123. )
  124. ->if($defaultField->handleEvent(atoum\test::runStop, $test))
  125. ->then
  126. ->castToString($defaultField)->isEqualTo($defaultField->getPrompt() . sprintf($defaultField->getLocale()->_('%4.2f Mb'), $totalMemoryUsage / 1048576))
  127. ->if($customField->handleEvent(atoum\test::runStop, $test))
  128. ->then
  129. ->castToString($customField)->isEqualTo(
  130. $prompt .
  131. sprintf(
  132. $locale->_('%s'),
  133. $memoryColorizer->colorize(sprintf($locale->_('%4.2f Mb'), $totalMemoryUsage / 1048576))
  134. )
  135. )
  136. ;
  137. }
  138. }