phpt-modifications.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. Index: src/PHPT/Case.php
  2. ===================================================================
  3. --- src/PHPT/Case.php (revision 691)
  4. +++ src/PHPT/Case.php (working copy)
  5. @@ -28,17 +28,14 @@
  6. {
  7. $reporter->onCaseStart($this);
  8. try {
  9. - if ($this->sections->filterByInterface('RunnableBefore')->valid()) {
  10. - foreach ($this->sections as $section) {
  11. - $section->run($this);
  12. - }
  13. + $runnable_before = $this->sections->filterByInterface('RunnableBefore');
  14. + foreach ($runnable_before as $section) {
  15. + $section->run($this);
  16. }
  17. - $this->sections->filterByInterface();
  18. $this->sections->FILE->run($this);
  19. - if ($this->sections->filterByInterface('RunnableAfter')->valid()) {
  20. - foreach ($this->sections as $section) {
  21. - $section->run($this);
  22. - }
  23. + $runnable_after = $this->sections->filterByInterface('RunnableAfter');
  24. + foreach ($runnable_after as $section) {
  25. + $section->run($this);
  26. }
  27. $reporter->onCasePass($this);
  28. } catch (PHPT_Case_VetoException $veto) {
  29. @@ -46,7 +43,6 @@
  30. } catch (PHPT_Case_FailureException $failure) {
  31. $reporter->onCaseFail($this, $failure);
  32. }
  33. - $this->sections->filterByInterface();
  34. $reporter->onCaseEnd($this);
  35. }
  36. Index: src/PHPT/Case/Validator/CgiRequired.php
  37. ===================================================================
  38. --- src/PHPT/Case/Validator/CgiRequired.php (revision 691)
  39. +++ src/PHPT/Case/Validator/CgiRequired.php (working copy)
  40. @@ -17,7 +17,6 @@
  41. public function is(PHPT_Case $case)
  42. {
  43. $return = $case->sections->filterByInterface('CgiExecutable')->valid();
  44. - $case->sections->filterByInterface();
  45. return $return;
  46. }
  47. }
  48. Index: src/PHPT/CodeRunner/CommandLine.php
  49. ===================================================================
  50. --- src/PHPT/CodeRunner/CommandLine.php (revision 691)
  51. +++ src/PHPT/CodeRunner/CommandLine.php (working copy)
  52. @@ -13,7 +13,7 @@
  53. $this->_filename = $runner->filename;
  54. $this->_ini = (string)$runner->ini;
  55. $this->_args = (string)$runner->args;
  56. - $this->_executable = str_replace(' ', '\ ', (string)$runner->executable);
  57. + $this->_executable = $runner->executable;
  58. $this->_post_filename = (string)$runner->post_filename;
  59. }
  60. Index: src/PHPT/CodeRunner/Driver/WScriptShell.php
  61. ===================================================================
  62. --- src/PHPT/CodeRunner/Driver/WScriptShell.php (revision 691)
  63. +++ src/PHPT/CodeRunner/Driver/WScriptShell.php (working copy)
  64. @@ -23,9 +23,9 @@
  65. }
  66. }
  67. if ($found == false) {
  68. - throw new PHPT_CodeRunner_InvalidExecutableException(
  69. - 'unable to locate PHP executable: ' . $this->executable
  70. - );
  71. + //throw new PHPT_CodeRunner_InvalidExecutableException(
  72. + // 'unable to locate PHP executable: ' . $this->executable
  73. + //);
  74. }
  75. }
  76. @@ -69,7 +69,7 @@
  77. $error = $this->_process->StdErr->ReadAll();
  78. if (!empty($error)) {
  79. - throw new PHPT_CodeRunner_ExecutionException($error);
  80. + throw new PHPT_CodeRunner_ExecutionException($error, $this->_commandFactory());
  81. }
  82. return $this->_process->StdOut->ReadAll();
  83. @@ -93,6 +93,7 @@
  84. {
  85. $return = '';
  86. foreach ($this->environment as $key => $value) {
  87. + $value = str_replace('&', '^&', $value);
  88. $return .= "set {$key}={$value} & ";
  89. }
  90. return $return;
  91. Index: src/PHPT/CodeRunner/Factory.php
  92. ===================================================================
  93. --- src/PHPT/CodeRunner/Factory.php (revision 691)
  94. +++ src/PHPT/CodeRunner/Factory.php (working copy)
  95. @@ -33,7 +33,13 @@
  96. 'php-cgi';
  97. }
  98. - if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
  99. + if (
  100. + strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' &&
  101. + (
  102. + $runner->executable == 'php' ||
  103. + $runner->executable == 'php-cgi'
  104. + )
  105. + ) {
  106. $runner->executable = $runner->executable . '.exe';
  107. }
  108. try {
  109. Index: src/PHPT/Section/ModifiableAbstract.php
  110. ===================================================================
  111. --- src/PHPT/Section/ModifiableAbstract.php (revision 691)
  112. +++ src/PHPT/Section/ModifiableAbstract.php (working copy)
  113. @@ -15,12 +15,10 @@
  114. public function run(PHPT_Case $case)
  115. {
  116. - $sections = clone $case->sections;
  117. - if ($sections->filterByInterface($this->_modifier_name . 'Modifier')->valid()) {
  118. - $modifyMethod = 'modify' . $this->_modifier_name;
  119. - foreach ($sections as $section) {
  120. - $section->$modifyMethod($this);
  121. - }
  122. + $modifiers = $case->sections->filterByInterface($this->_modifier_name . 'Modifier');
  123. + $modifyMethod = 'modify' . $this->_modifier_name;
  124. + foreach ($modifiers as $section) {
  125. + $section->$modifyMethod($this);
  126. }
  127. }
  128. Index: src/PHPT/Section/SKIPIF.php
  129. ===================================================================
  130. --- src/PHPT/Section/SKIPIF.php (revision 691)
  131. +++ src/PHPT/Section/SKIPIF.php (working copy)
  132. @@ -3,10 +3,12 @@
  133. class PHPT_Section_SKIPIF implements PHPT_Section_RunnableBefore
  134. {
  135. private $_data = null;
  136. + private $_runner_factory = null;
  137. public function __construct($data)
  138. {
  139. $this->_data = $data;
  140. + $this->_runner_factory = new PHPT_CodeRunner_Factory();
  141. }
  142. public function run(PHPT_Case $case)
  143. @@ -16,9 +18,7 @@
  144. // @todo refactor to PHPT_CodeRunner
  145. file_put_contents($filename, $this->_data);
  146. - $response = array();
  147. - exec('php -f ' . $filename, $response);
  148. - $response = implode("\n", $response);
  149. + $response = $this->_runner_factory->factory($case)->run($filename)->output;
  150. unlink($filename);
  151. if (preg_match('/^skip( - (.*))?/', $response, $matches)) {
  152. Index: src/PHPT/SectionList.php
  153. ===================================================================
  154. --- src/PHPT/SectionList.php (revision 691)
  155. +++ src/PHPT/SectionList.php (working copy)
  156. @@ -2,7 +2,6 @@
  157. class PHPT_SectionList implements Iterator
  158. {
  159. - private $_raw_sections = array();
  160. private $_sections = array();
  161. private $_section_map = array();
  162. private $_key_map = array();
  163. @@ -15,14 +14,12 @@
  164. }
  165. $name = strtoupper(str_replace('PHPT_Section_', '', get_class($section)));
  166. $key = $section instanceof PHPT_Section_Runnable ? $section->getPriority() . '.' . $name : $name;
  167. - $this->_raw_sections[$key] = $section;
  168. + $this->_sections[$key] = $section;
  169. $this->_section_map[$name] = $key;
  170. $this->_key_map[$key] = $name;
  171. }
  172. - ksort($this->_raw_sections);
  173. -
  174. - $this->_sections = $this->_raw_sections;
  175. + ksort($this->_sections);
  176. }
  177. public function current()
  178. @@ -52,21 +49,23 @@
  179. public function filterByInterface($interface = null)
  180. {
  181. + $ret = new PHPT_SectionList();
  182. +
  183. if (is_null($interface)) {
  184. - $this->_sections = $this->_raw_sections;
  185. - return $this;
  186. + $ret->_sections = $this->_sections;
  187. + return $ret;
  188. }
  189. $full_interface = 'PHPT_Section_' . $interface;
  190. - $this->_sections = array();
  191. - foreach ($this->_raw_sections as $name => $section) {
  192. + $ret->_sections = array();
  193. + foreach ($this->_sections as $name => $section) {
  194. if (!$section instanceof $full_interface) {
  195. continue;
  196. }
  197. - $this->_sections[$name] = $section;
  198. + $ret->_sections[$name] = $section;
  199. }
  200. - return $this;
  201. + return $ret;
  202. }
  203. public function has($name)
  204. @@ -74,11 +73,11 @@
  205. if (!isset($this->_section_map[$name])) {
  206. return false;
  207. }
  208. - return isset($this->_raw_sections[$this->_section_map[$name]]);
  209. + return isset($this->_sections[$this->_section_map[$name]]);
  210. }
  211. public function __get($key)
  212. {
  213. - return $this->_raw_sections[$this->_section_map[$key]];
  214. + return $this->_sections[$this->_section_map[$key]];
  215. }
  216. }
  217. Index: tests/CodeRunner/Driver/WScriptShell/injects-ini-settings.phpt
  218. ===================================================================
  219. --- tests/CodeRunner/Driver/WScriptShell/injects-ini-settings.phpt (revision 691)
  220. +++ tests/CodeRunner/Driver/WScriptShell/injects-ini-settings.phpt (working copy)
  221. @@ -17,9 +17,9 @@
  222. // sanity check
  223. $obj = new FoobarIni();
  224. -assert('(string)$obj == " -d display_errors=1 "');
  225. +assert('(string)$obj == " -d \"display_errors=1\" "');
  226. $obj->display_errors = 0;
  227. -assert('(string)$obj == " -d display_errors=0 "');
  228. +assert('(string)$obj == " -d \"display_errors=0\" "');
  229. unset($obj);
  230. Index: tests/Section/File/restores-case-sections.phpt
  231. ===================================================================
  232. --- tests/Section/File/restores-case-sections.phpt (revision 691)
  233. +++ tests/Section/File/restores-case-sections.phpt (working copy)
  234. @@ -1,24 +0,0 @@
  235. ---TEST--
  236. -After PHPT_Section_FILE::run(), the sections property of the provide $case object
  237. -is restored to its unfiltered state
  238. ---FILE--
  239. -<?php
  240. -
  241. -require_once dirname(__FILE__) . '/../../_setup.inc';
  242. -require_once dirname(__FILE__) . '/../_simple-test-case.inc';
  243. -require_once dirname(__FILE__) . '/_simple-file-modifier.inc';
  244. -
  245. -$case = new PHPT_SimpleTestCase();
  246. -$case->sections = new PHPT_SectionList(array(
  247. - new PHPT_Section_ARGS('foo=bar'),
  248. -));
  249. -
  250. -$section = new PHPT_Section_FILE('hello world');
  251. -$section->run($case);
  252. -
  253. -assert('$case->sections->valid()');
  254. -
  255. -?>
  256. -===DONE===
  257. ---EXPECT--
  258. -===DONE===
  259. Index: tests/SectionList/filter-by-interface.phpt
  260. ===================================================================
  261. --- tests/SectionList/filter-by-interface.phpt (revision 691)
  262. +++ tests/SectionList/filter-by-interface.phpt (working copy)
  263. @@ -17,10 +17,10 @@
  264. $data = array_merge($runnable, $non_runnable);
  265. $list = new PHPT_SectionList($data);
  266. -$list->filterByInterface('Runnable');
  267. -assert('$list->valid()');
  268. -$list->filterByInterface('EnvModifier');
  269. -assert('$list->valid() == false');
  270. +$runnable = $list->filterByInterface('Runnable');
  271. +assert('$runnable->valid()');
  272. +$env_modifier = $list->filterByInterface('EnvModifier');
  273. +assert('$env_modifier->valid() == false');
  274. ?>
  275. ===DONE===
  276. Index: tests/SectionList/filter-resets-with-null.phpt
  277. ===================================================================
  278. --- tests/SectionList/filter-resets-with-null.phpt (revision 691)
  279. +++ tests/SectionList/filter-resets-with-null.phpt (working copy)
  280. @@ -1,36 +0,0 @@
  281. ---TEST--
  282. -If you call filterByInterface() with null or no-value, the full dataset is restored
  283. ---FILE--
  284. -<?php
  285. -
  286. -require_once dirname(__FILE__) . '/../_setup.inc';
  287. -
  288. -$runnable = array(
  289. - 'ENV' => new PHPT_Section_ENV(''),
  290. - 'CLEAN' => new PHPT_Section_CLEAN(''),
  291. -);
  292. -
  293. -class PHPT_Section_FOO implements PHPT_Section { }
  294. -$non_runnable = array(
  295. - 'FOO' => new PHPT_Section_FOO(),
  296. -);
  297. -
  298. -$data = array_merge($runnable, $non_runnable);
  299. -$list = new PHPT_SectionList($data);
  300. -$list->filterByInterface('Runnable');
  301. -
  302. -// sanity check
  303. -foreach ($list as $key => $value) {
  304. - assert('$runnable[$key] == $value');
  305. -}
  306. -
  307. -$list->filterByInterface();
  308. -
  309. -foreach ($list as $key => $value) {
  310. - assert('$data[$key] == $value');
  311. -}
  312. -
  313. -?>
  314. -===DONE===
  315. ---EXPECT--
  316. -===DONE===
  317. Index: tests/Util/Code/runAsFile-executes-in-file.phpt
  318. ===================================================================
  319. --- tests/Util/Code/runAsFile-executes-in-file.phpt (revision 691)
  320. +++ tests/Util/Code/runAsFile-executes-in-file.phpt (working copy)
  321. @@ -10,7 +10,7 @@
  322. $util = new PHPT_Util_Code($code);
  323. -$file = dirname(__FILE__) . '/foobar.php';
  324. +$file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foobar.php';
  325. $result = $util->runAsFile($file);
  326. assert('$result == $file');
  327. Index: tests/Util/Code/runAsFile-returns-output-if-no-return.phpt
  328. ===================================================================
  329. --- tests/Util/Code/runAsFile-returns-output-if-no-return.phpt (revision 691)
  330. +++ tests/Util/Code/runAsFile-returns-output-if-no-return.phpt (working copy)
  331. @@ -9,7 +9,7 @@
  332. $util = new PHPT_Util_Code($code);
  333. -$file = dirname(__FILE__) . '/foobar.php';
  334. +$file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'foobar.php';
  335. $result = $util->runAsFile($file);
  336. assert('$result == $file');