PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/tr/tests/cases/lmbTestShellUITest.class.php

https://bitbucket.org/idler/mmp/
PHP | 210 lines | 165 code | 38 blank | 7 comment | 8 complexity | 1c759ab84047ae7ab679d7531d000fca MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0
  1. <?php
  2. /*
  3. * Limb PHP Framework
  4. *
  5. * @link http://limb-project.com
  6. * @copyright Copyright &copy; 2004-2009 BIT(http://bit-creative.com)
  7. * @license LGPL http://www.gnu.org/copyleft/lesser.html
  8. */
  9. require_once(dirname(__FILE__) . '/../common.inc.php');
  10. require_once(dirname(__FILE__) . '/../../src/lmbTestShellUI.class.php');
  11. class lmbTestShellUITest extends lmbTestRunnerBase
  12. {
  13. function setUp()
  14. {
  15. $this->_rmdir(LIMB_VAR_DIR);
  16. mkdir(LIMB_VAR_DIR);
  17. mkdir(LIMB_VAR_DIR . '/cases');
  18. $this->_createRunScript();
  19. }
  20. function tearDown()
  21. {
  22. $this->_rmdir(LIMB_VAR_DIR);
  23. }
  24. function testPerformInDirWithAbsolutePath()
  25. {
  26. $foo = $this->_createTestCase(LIMB_VAR_DIR . '/cases/foo_test.php');
  27. $bar = $this->_createTestCase(LIMB_VAR_DIR . '/cases/a/bar_test.php');
  28. $zoo = $this->_createTestCase(LIMB_VAR_DIR . '/cases/a/z/zoo_test.php');
  29. $run_dir = LIMB_VAR_DIR . '/cases';
  30. $ret = $this->_execScript($run_dir, $screen);
  31. if(!$this->assertEqual($ret, 0))
  32. echo $screen;
  33. $this->assertPattern('~1\s+of\s+3\s+done\(' . $zoo->getClass() . '\)~', $screen);
  34. $this->assertPattern('~2\s+of\s+3\s+done\(' . $bar->getClass() . '\)~', $screen);
  35. $this->assertPattern('~3\s+of\s+3\s+done\(' . $foo->getClass() . '\)~', $screen);
  36. $this->assertPattern('~OK~i', $screen);
  37. $this->assertNoPattern('~Error~i', $screen);
  38. }
  39. function testPerformInDirWithRelativePath()
  40. {
  41. $foo = $this->_createTestCase(LIMB_VAR_DIR . '/cases/foo_test.php');
  42. $bar = $this->_createTestCase(LIMB_VAR_DIR . '/cases/a/bar_test.php');
  43. $zoo = $this->_createTestCase(LIMB_VAR_DIR . '/cases/a/z/zoo_test.php');
  44. $cwd = getcwd();
  45. chdir(LIMB_VAR_DIR);
  46. $ret = $this->_execScript('cases', $screen);
  47. chdir($cwd);
  48. if(!$this->assertEqual($ret, 0))
  49. echo $screen;
  50. $this->assertPattern('~1\s+of\s+3\s+done\(' . $zoo->getClass() . '\)~', $screen);
  51. $this->assertPattern('~2\s+of\s+3\s+done\(' . $bar->getClass() . '\)~', $screen);
  52. $this->assertPattern('~3\s+of\s+3\s+done\(' . $foo->getClass() . '\)~', $screen);
  53. $this->assertPattern('~OK~i', $screen);
  54. $this->assertNoPattern('~Error~i', $screen);
  55. }
  56. function testPerformTestsWithGlob()
  57. {
  58. $foo = $this->_createTestCase(LIMB_VAR_DIR . '/cases/foo_test.php');
  59. $bar = $this->_createTestCase(LIMB_VAR_DIR . '/cases/a/bar_test.php');
  60. $zoo = $this->_createTestCase(LIMB_VAR_DIR . '/cases/a/z/zoo_test.php');
  61. $run_dir = LIMB_VAR_DIR . '/cases/*.php';
  62. $ret = $this->_execScript($run_dir, $screen);
  63. if(!$this->assertEqual($ret, 0))
  64. echo $screen;
  65. $this->assertPattern('~1\s+of\s+1\s+done\(' . $foo->getClass() . '\)~', $screen);
  66. $this->assertPattern('~OK~i', $screen);
  67. $this->assertNoPattern('~Error~i', $screen);
  68. }
  69. function testPerformMultipleArgs()
  70. {
  71. $foo = $this->_createTestCase($foo_file = LIMB_VAR_DIR . '/cases/foo_test.php');
  72. $bar = $this->_createTestCase($bar_file = LIMB_VAR_DIR . '/cases/a/bar_test.php');
  73. $zoo = $this->_createTestCase($zoo_file = LIMB_VAR_DIR . '/cases/a/z/zoo_test.php');
  74. $ret = $this->_execScript("$bar_file $foo_file $zoo_file", $screen);
  75. if(!$this->assertEqual($ret, 0))
  76. echo $screen;
  77. $this->assertPattern('~1\s+of\s+3\s+done\(' . $bar->getClass() . '\)~', $screen);
  78. $this->assertPattern('~2\s+of\s+3\s+done\(' . $foo->getClass() . '\)~', $screen);
  79. $this->assertPattern('~3\s+of\s+3\s+done\(' . $zoo->getClass() . '\)~', $screen);
  80. $this->assertPattern('~Test cases run:\s*3\/3.*~si', $screen);
  81. $this->assertNoPattern('~Error~i', $screen);
  82. }
  83. function testPerformOnlySelectedTests()
  84. {
  85. $foo = $this->_createTestCase($foo_file = LIMB_VAR_DIR . '/cases/foo_test.php');
  86. $bar = $this->_createTestCase($bar_file = LIMB_VAR_DIR . '/cases/bar_test.php');
  87. $zoo = $this->_createTestCase($zoo_file = LIMB_VAR_DIR . '/cases/zoo_test.php');
  88. $ret = $this->_execScript("--tests=" . $foo->getClass(). "," . $zoo->getClass(). " $foo_file $bar_file $zoo_file", $screen);
  89. if(!$this->assertEqual($ret, 0))
  90. echo $screen;
  91. $this->assertPattern('~1\s+of\s+2\s+done\(' . $foo->getClass() . '\)~', $screen);
  92. $this->assertPattern('~2\s+of\s+2\s+done\(' . $zoo->getClass() . '\)~', $screen);
  93. }
  94. function testPerformOnlySelectedMethods()
  95. {
  96. $foo_body = '%class_header%';
  97. $foo_body .= 'function testFoo(){echo "foo";}';
  98. $foo_body .= 'function testJunk(){echo "junk";}';
  99. $foo_body .= '%class_footer%';
  100. $bar_body = '%class_header%';
  101. $bar_body .= 'function testBar(){echo "bar";}';
  102. $bar_body .= 'function testJunk(){echo "junk";}';
  103. $bar_body .= '%class_footer%';
  104. $foo = $this->_createTestCase($foo_file = LIMB_VAR_DIR . '/cases/foo_test.php', $foo_body);
  105. $bar = $this->_createTestCase($bar_file = LIMB_VAR_DIR . '/cases/bar_test.php', $bar_body);
  106. $ret = $this->_execScript("--methods=testFoo,testBar $foo_file $bar_file", $screen);
  107. if(!$this->assertEqual($ret, 0))
  108. echo $screen;
  109. $this->assertPattern('~foo1\s+of\s+2\s+done\(' . $foo->getClass() . '\)~', $screen);
  110. $this->assertPattern('~bar2\s+of\s+2\s+done\(' . $bar->getClass() . '\)~', $screen);
  111. }
  112. function testPerformOnlySelectedGroupsOfTests()
  113. {
  114. $foo = $this->_createTestCase($foo_file = LIMB_VAR_DIR . '/cases/foo_test.php', "/**\n* @group foo\n*/ %class%");
  115. $bar = $this->_createTestCase($bar_file = LIMB_VAR_DIR . '/cases/bar_test.php', "/**\n* @group bar,foo\n*/ %class%");
  116. $junk = $this->_createTestCase($junk_file = LIMB_VAR_DIR . '/cases/junk_test.php', "/*\n* @group junk\n*/ %class%");
  117. $ret = $this->_execScript("--groups=foo,bar $foo_file $bar_file $junk_file", $screen);
  118. if(!$this->assertEqual($ret, 0))
  119. echo $screen;
  120. $this->assertPattern('~1\s+of\s+2\s+done\(' . $foo->getClass() . '\)~', $screen);
  121. $this->assertPattern('~2\s+of\s+2\s+done\(' . $bar->getClass() . '\)~', $screen);
  122. $this->assertNoPattern('~' . $junk->getClass() . '~', $screen);
  123. }
  124. function testAutoDefineConstants()
  125. {
  126. $c1 = "FOO_" . mt_rand() . "_H" . mt_rand();
  127. $c2 = "FOO_" . mt_rand() . "_K" . mt_rand();
  128. $this->_createTestCase($f = LIMB_VAR_DIR . '/cases/foo_test.php', "%class%\n echo '$c1=' . $c1;echo '$c2=' . $c2;");
  129. $this->_execScript("$f $c1=hey $c2=wow", $screen);
  130. $this->assertPattern("~$c1=hey~", $screen);
  131. $this->assertPattern("~$c2=wow~", $screen);
  132. }
  133. function testCoverageSummaryReporter()
  134. {
  135. if(!extension_loaded('xdebug'))
  136. {
  137. echo "Skipping coverage test since xdebug is not loaded\n";
  138. return;
  139. }
  140. $this->_createTestCase($f = LIMB_VAR_DIR . '/cases/cover_test.php');
  141. $this->_execScript("-C" . LIMB_VAR_DIR . "/cases $f", $screen);
  142. $this->assertPattern("~Code\s+Coverage:\s+100%~", $screen);
  143. }
  144. function _createRunScript()
  145. {
  146. $dir = dirname(__FILE__);
  147. $simpletest = SIMPLE_TEST;
  148. $script = <<<EOD
  149. <?php
  150. define('SIMPLE_TEST', '$simpletest');
  151. define('LIMB_VAR_DIR', dirname(__FILE__) . '/var');
  152. require_once('$dir/../../common.inc.php');
  153. require_once('$dir/../../src/lmbTestShellUI.class.php');
  154. require_once('$dir/../../src/lmbTestShellReporter.class.php');
  155. \$ui = new lmbTestShellUI();
  156. \$ui->setReporter(new lmbTestShellReporter());
  157. \$ui->run();
  158. ?>
  159. EOD;
  160. file_put_contents($this->_runScriptName(), $script);
  161. }
  162. function _runScriptName()
  163. {
  164. return LIMB_VAR_DIR . '/runtests.php';
  165. }
  166. function _execScript($args, &$screen)
  167. {
  168. exec('php ' . $this->_runScriptName() . ' ' . $args, $out, $ret);
  169. $screen = implode("\n", $out);
  170. return $ret;
  171. }
  172. }