| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 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 12 class lmbTestShellUITest extends lmbTestRunnerBase 13 { 14 function setUp() 15 { 16 $this->_rmdir(LIMB_VAR_DIR); 17 mkdir(LIMB_VAR_DIR); 18 mkdir(LIMB_VAR_DIR . '/cases'); 19 $this->_createRunScript(); 20 } 21 22 function tearDown() 23 { 24 $this->_rmdir(LIMB_VAR_DIR); 25 } 26 27 function testPerformInDirWithAbsolutePath() 28 { 29 $foo = $this->_createTestCase(LIMB_VAR_DIR . '/cases/foo_test.php'); 30 $bar = $this->_createTestCase(LIMB_VAR_DIR . '/cases/a/bar_test.php'); 31 $zoo = $this->_createTestCase(LIMB_VAR_DIR . '/cases/a/z/zoo_test.php'); 32 33 $run_dir = LIMB_VAR_DIR . '/cases'; 34 $ret = $this->_execScript($run_dir, $screen); 35 if(!$this->assertEqual($ret, 0)) 36 echo $screen; 37 38 $this->assertPattern('~1\s+of\s+3\s+done\(' . $zoo->getClass() . '\)~', $screen); 39 $this->assertPattern('~2\s+of\s+3\s+done\(' . $bar->getClass() . '\)~', $screen); 40 $this->assertPattern('~3\s+of\s+3\s+done\(' . $foo->getClass() . '\)~', $screen); 41 $this->assertPattern('~OK~i', $screen); 42 $this->assertNoPattern('~Error~i', $screen); 43 } 44 45 function testPerformInDirWithRelativePath() 46 { 47 $foo = $this->_createTestCase(LIMB_VAR_DIR . '/cases/foo_test.php'); 48 $bar = $this->_createTestCase(LIMB_VAR_DIR . '/cases/a/bar_test.php'); 49 $zoo = $this->_createTestCase(LIMB_VAR_DIR . '/cases/a/z/zoo_test.php'); 50 51 $cwd = getcwd(); 52 chdir(LIMB_VAR_DIR); 53 $ret = $this->_execScript('cases', $screen); 54 55 chdir($cwd); 56 57 if(!$this->assertEqual($ret, 0)) 58 echo $screen; 59 60 $this->assertPattern('~1\s+of\s+3\s+done\(' . $zoo->getClass() . '\)~', $screen); 61 $this->assertPattern('~2\s+of\s+3\s+done\(' . $bar->getClass() . '\)~', $screen); 62 $this->assertPattern('~3\s+of\s+3\s+done\(' . $foo->getClass() . '\)~', $screen); 63 $this->assertPattern('~OK~i', $screen); 64 $this->assertNoPattern('~Error~i', $screen); 65 } 66 67 function testPerformTestsWithGlob() 68 { 69 $foo = $this->_createTestCase(LIMB_VAR_DIR . '/cases/foo_test.php'); 70 $bar = $this->_createTestCase(LIMB_VAR_DIR . '/cases/a/bar_test.php'); 71 $zoo = $this->_createTestCase(LIMB_VAR_DIR . '/cases/a/z/zoo_test.php'); 72 73 $run_dir = LIMB_VAR_DIR . '/cases/*.php'; 74 $ret = $this->_execScript($run_dir, $screen); 75 if(!$this->assertEqual($ret, 0)) 76 echo $screen; 77 78 $this->assertPattern('~1\s+of\s+1\s+done\(' . $foo->getClass() . '\)~', $screen); 79 $this->assertPattern('~OK~i', $screen); 80 $this->assertNoPattern('~Error~i', $screen); 81 } 82 83 function testPerformMultipleArgs() 84 { 85 $foo = $this->_createTestCase($foo_file = LIMB_VAR_DIR . '/cases/foo_test.php'); 86 $bar = $this->_createTestCase($bar_file = LIMB_VAR_DIR . '/cases/a/bar_test.php'); 87 $zoo = $this->_createTestCase($zoo_file = LIMB_VAR_DIR . '/cases/a/z/zoo_test.php'); 88 89 $ret = $this->_execScript("$bar_file $foo_file $zoo_file", $screen); 90 if(!$this->assertEqual($ret, 0)) 91 echo $screen; 92 93 $this->assertPattern('~1\s+of\s+3\s+done\(' . $bar->getClass() . '\)~', $screen); 94 $this->assertPattern('~2\s+of\s+3\s+done\(' . $foo->getClass() . '\)~', $screen); 95 $this->assertPattern('~3\s+of\s+3\s+done\(' . $zoo->getClass() . '\)~', $screen); 96 $this->assertPattern('~Test cases run:\s*3\/3.*~si', $screen); 97 $this->assertNoPattern('~Error~i', $screen); 98 } 99 100 function testAutoDefineConstants() 101 { 102 $c1 = "FOO_" . mt_rand(); 103 $c2 = "FOO_" . mt_rand(); 104 105 $this->_createTestCase($f = LIMB_VAR_DIR . '/cases/foo_test.php', "echo '$c1=' . $c1;echo '$c2=' . $c2;"); 106 $this->_execScript("$f $c1=hey $c2=wow", $screen); 107 108 $this->assertPattern("~$c1=hey~", $screen); 109 $this->assertPattern("~$c2=wow~", $screen); 110 } 111 112 function _createRunScript() 113 { 114 $dir = dirname(__FILE__); 115 $simpletest = SIMPLE_TEST; 116 117 $script = <<<EOD 118 <?php 119 define('SIMPLE_TEST', '$simpletest'); 120 define('LIMB_VAR_DIR', dirname(__FILE__) . '/var'); 121 require_once('$dir/../../common.inc.php'); 122 require_once('$dir/../../src/lmbTestShellUI.class.php'); 123 require_once('$dir/../../src/lmbTestShellReporter.class.php'); 124 125 \$ui = new lmbTestShellUI(); 126 \$ui->setReporter(new lmbTestShellReporter()); 127 \$ui->run(); 128 ?> 129 EOD; 130 file_put_contents($this->_runScriptName(), $script); 131 } 132 133 function _runScriptName() 134 { 135 return LIMB_VAR_DIR . '/runtests.php'; 136 } 137 138 function _execScript($args, &$screen) 139 { 140 exec('php ' . $this->_runScriptName() . ' ' . $args, $out, $ret); 141 $screen = implode("\n", $out); 142 return $ret; 143 } 144 } 145 146 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Dec 2 03:54:09 2008 | Cross-referenced by PHPXref 0.7 |