RunCest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. <?php
  2. class RunCest
  3. {
  4. public function _before(\CliGuy $I)
  5. {
  6. $I->amInPath('tests/data/sandbox');
  7. }
  8. public function runOneFile(\CliGuy $I)
  9. {
  10. $I->wantTo('execute one test');
  11. $I->executeCommand('run tests/dummy/FileExistsCept.php');
  12. $I->seeInShellOutput("OK (");
  13. }
  14. public function runOneFileWithColors(\CliGuy $I)
  15. {
  16. $I->wantTo('execute one test');
  17. $I->executeCommand('run --colors tests/dummy/FileExistsCept.php');
  18. $I->seeInShellOutput("OK (");
  19. $I->seeInShellOutput("\033[35;1mFileExistsCept:\033[39;22m Check config exists");
  20. }
  21. /**
  22. * @group reports
  23. * @group core
  24. *
  25. * @param CliGuy $I
  26. */
  27. public function runHtml(\CliGuy $I)
  28. {
  29. $I->wantTo('execute tests with html output');
  30. $I->executeCommand('run dummy --html');
  31. $I->seeFileFound('report.html', 'tests/_output');
  32. }
  33. /**
  34. * @group reports
  35. *
  36. * @param CliGuy $I
  37. */
  38. public function runJsonReport(\CliGuy $I)
  39. {
  40. $I->wantTo('check json reports');
  41. $I->executeCommand('run dummy --json');
  42. $I->seeFileFound('report.json', 'tests/_output');
  43. $I->seeInThisFile('"suite":');
  44. $I->seeInThisFile('"dummy"');
  45. $I->assertNotNull(json_decode(file_get_contents('tests/_output/report.json')));
  46. }
  47. /**
  48. * @group reports
  49. *
  50. * @param CliGuy $I
  51. */
  52. public function runTapReport(\CliGuy $I)
  53. {
  54. $I->wantTo('check tap reports');
  55. $I->executeCommand('run dummy --tap');
  56. $I->seeFileFound('report.tap.log', 'tests/_output');
  57. }
  58. /**
  59. * @group reports
  60. *
  61. * @param CliGuy $I
  62. */
  63. public function runXmlReport(\CliGuy $I)
  64. {
  65. $I->wantTo('check xml reports');
  66. $I->executeCommand('run dummy --xml');
  67. $I->seeFileFound('report.xml', 'tests/_output');
  68. $I->seeInThisFile('<?xml');
  69. $I->seeInThisFile('<testsuite name="dummy"');
  70. $I->seeInThisFile('<testcase name="FileExists"');
  71. $I->seeInThisFile('feature="');
  72. }
  73. /**
  74. * @group reports
  75. * @param CliGuy $I
  76. */
  77. public function runXmlReportsInStrictMode(\CliGuy $I)
  78. {
  79. $I->wantTo('check xml in strict mode');
  80. $I->executeCommand('run dummy --xml -c codeception_strict_xml.yml');
  81. $I->seeFileFound('report.xml', 'tests/_output');
  82. $I->seeInThisFile('<?xml');
  83. $I->seeInThisFile('<testsuite name="dummy"');
  84. $I->seeInThisFile('<testcase name="FileExists"');
  85. $I->dontSeeInThisFile('feature="');
  86. }
  87. /**
  88. * @group reports
  89. *
  90. * @param CliGuy $I
  91. */
  92. public function runPhpUnitXmlReport(\CliGuy $I)
  93. {
  94. $I->wantTo('check phpunit xml reports');
  95. $I->executeCommand('run dummy --phpunit-xml');
  96. $I->seeInShellOutput('PHPUNIT-XML report generated in');
  97. $I->seeFileFound('phpunit-report.xml', 'tests/_output');
  98. $I->seeInThisFile('<?xml');
  99. if (\PHPUnit\Runner\Version::series() < 6) {
  100. $I->seeInThisFile('<testsuite name="dummy" tests="6" assertions="3" failures="0" errors="0" time=');
  101. } else {
  102. $I->seeInThisFile('<testsuite name="dummy" tests="6" assertions="3" errors="0" failures="0" skipped="0" time=');
  103. }
  104. $I->seeThisFileMatches('/<testsuite name="AnotherCest" file=".*?AnotherCest.php"/');
  105. $I->seeThisFileMatches('/<testsuite name="AnotherTest" file=".*?AnotherTest.php"/');
  106. if (\PHPUnit\Runner\Version::series() < 6) {
  107. $I->seeThisFileMatches('/<testsuite name="AnotherTest" file=".*?AnotherTest.php" tests="2" assertions="2" failures="0" errors="0" time=/');
  108. } else {
  109. $I->seeThisFileMatches('/<testsuite name="AnotherTest" file=".*?AnotherTest.php" tests="2" assertions="2" errors="0" failures="0" skipped="0" time=/');
  110. }
  111. //FileExistsCept file
  112. $I->seeInThisFile('<testsuite name="FileExists"');
  113. $I->seeInThisFile('<testcase name="FileExists"');
  114. $I->seeInThisFile('feature="');
  115. }
  116. /**
  117. * @group reports
  118. * @param CliGuy $I
  119. */
  120. public function runPhpUnitXmlReportsInStrictMode(\CliGuy $I)
  121. {
  122. $I->wantTo('check phpunit xml in strict mode');
  123. $I->executeCommand('run dummy --phpunit-xml -c codeception_strict_xml.yml');
  124. $I->seeInShellOutput('PHPUNIT-XML report generated in');
  125. $I->seeFileFound('phpunit-report.xml', 'tests/_output');
  126. $I->seeInThisFile('<?xml');
  127. if (\PHPUnit\Runner\Version::series() < 6) {
  128. $I->seeInThisFile('<testsuite name="dummy" tests="6" assertions="3" failures="0" errors="0" time=');
  129. } else {
  130. $I->seeInThisFile('<testsuite name="dummy" tests="6" assertions="3" errors="0" failures="0" skipped="0" time=');
  131. }
  132. $I->seeThisFileMatches('/<testsuite name="AnotherCest" file=".*?AnotherCest.php"/');
  133. $I->seeThisFileMatches('/<testsuite name="AnotherTest" file=".*?AnotherTest.php"/');
  134. if (\PHPUnit\Runner\Version::series() < 6) {
  135. $I->seeThisFileMatches('/<testsuite name="AnotherTest" file=".*?AnotherTest.php" tests="2" assertions="2" failures="0" errors="0" time=/');
  136. } else {
  137. $I->seeThisFileMatches('/<testsuite name="AnotherTest" file=".*?AnotherTest.php" tests="2" assertions="2" errors="0" failures="0" skipped="0" time=/');
  138. }
  139. //FileExistsCept file
  140. $I->seeInThisFile('<testsuite name="FileExists"');
  141. $I->seeInThisFile('<testcase name="FileExists"');
  142. $I->dontSeeInThisFile('feature="');
  143. }
  144. /**
  145. * @group reports
  146. *
  147. * @param CliGuy $I
  148. */
  149. public function runCustomReport(\CliGuy $I)
  150. {
  151. if (\PHPUnit\Runner\Version::series() >= 7) {
  152. throw new \Codeception\Exception\Skip('Not for PHPUnit 7');
  153. }
  154. $I->executeCommand('run dummy --report -c codeception_custom_report.yml');
  155. $I->seeInShellOutput('FileExistsCept: Check config exists');
  156. $I->dontSeeInShellOutput('Ok');
  157. }
  158. public function runOneGroup(\CliGuy $I)
  159. {
  160. $I->executeCommand('run skipped -g notorun');
  161. $I->seeInShellOutput('Skipped Tests (1)');
  162. $I->seeInShellOutput("IncompleteMeCept");
  163. $I->dontSeeInShellOutput("SkipMeCept");
  164. }
  165. public function skipRunOneGroup(\CliGuy $I)
  166. {
  167. $I->executeCommand('run skipped --skip-group notorun');
  168. $I->seeInShellOutput('Skipped Tests (2)');
  169. $I->seeInShellOutput("SkipMeCept");
  170. $I->dontSeeInShellOutput("IncompleteMeCept");
  171. }
  172. public function skipGroupOfCest(\CliGuy $I)
  173. {
  174. $I->executeCommand('run dummy');
  175. $I->seeInShellOutput('Optimistic');
  176. $I->seeInShellOutput('Dummy Tests (6)');
  177. $I->executeCommand('run dummy --skip-group ok');
  178. $I->seeInShellOutput('Pessimistic');
  179. $I->seeInShellOutput('Dummy Tests (5)');
  180. $I->dontSeeInShellOutput('Optimistic');
  181. }
  182. public function runTwoSuites(\CliGuy $I)
  183. {
  184. $I->executeCommand('run skipped,dummy --no-exit');
  185. $I->seeInShellOutput("Skipped Tests (3)");
  186. $I->seeInShellOutput("Dummy Tests (6)");
  187. $I->dontSeeInShellOutput("Remote Tests");
  188. }
  189. public function skipSuites(\CliGuy $I)
  190. {
  191. $I->executeCommand(
  192. 'run dummy --skip skipped --skip remote --skip remote_server --skip order --skip unit '
  193. . '--skip powers --skip math --skip messages'
  194. );
  195. $I->seeInShellOutput("Dummy Tests");
  196. $I->dontSeeInShellOutput("Remote Tests");
  197. $I->dontSeeInShellOutput("Remote_server Tests");
  198. $I->dontSeeInShellOutput("Order Tests");
  199. }
  200. public function runOneTestFromUnit(\CliGuy $I)
  201. {
  202. $I->executeCommand('run tests/dummy/AnotherTest.php:testFirst');
  203. $I->seeInShellOutput("AnotherTest: First");
  204. $I->seeInShellOutput('OK');
  205. $I->dontSeeInShellOutput('AnotherTest: Second');
  206. }
  207. public function runOneTestFromCest(\CliGuy $I)
  208. {
  209. $I->executeCommand('run tests/dummy/AnotherCest.php:optimistic');
  210. $I->seeInShellOutput("Optimistic");
  211. $I->dontSeeInShellOutput('Pessimistic');
  212. }
  213. public function runTestWithDataProviders(\CliGuy $I)
  214. {
  215. $I->executeCommand('run tests/unit/DataProvidersTest.php');
  216. $I->seeInShellOutput('Is triangle | "real triangle"');
  217. $I->seeInShellOutput('Is triangle | #0');
  218. $I->seeInShellOutput('Is triangle | #1');
  219. $I->seeInShellOutput('DataProvidersTest');
  220. $I->seeInShellOutput("OK");
  221. }
  222. public function runOneGroupWithDataProviders(\CliGuy $I)
  223. {
  224. $I->executeCommand('run unit -g data-providers');
  225. $I->seeInShellOutput('Is triangle | "real triangle"');
  226. $I->seeInShellOutput('Is triangle | #0');
  227. $I->seeInShellOutput('Is triangle | #1');
  228. $I->seeInShellOutput('DataProvidersTest');
  229. $I->seeInShellOutput("OK");
  230. }
  231. public function runTestWithFailFast(\CliGuy $I)
  232. {
  233. $I->executeCommand('run unit --skip-group error --no-exit');
  234. $I->seeInShellOutput('FailingTest: Me');
  235. $I->seeInShellOutput("PassingTest: Me");
  236. $I->executeCommand('run unit --fail-fast --skip-group error --no-exit');
  237. $I->seeInShellOutput('There was 1 failure');
  238. $I->dontSeeInShellOutput("PassingTest: Me");
  239. }
  240. public function runWithCustomOutputPath(\CliGuy $I)
  241. {
  242. $I->executeCommand('run dummy --xml myverycustom.xml --html myownhtmlreport.html');
  243. $I->seeFileFound('myverycustom.xml', 'tests/_output');
  244. $I->seeInThisFile('<?xml');
  245. $I->seeInThisFile('<testsuite name="dummy"');
  246. $I->seeInThisFile('<testcase name="FileExists"');
  247. $I->seeFileFound('myownhtmlreport.html', 'tests/_output');
  248. $I->dontSeeFileFound('report.xml', 'tests/_output');
  249. $I->dontSeeFileFound('report.html', 'tests/_output');
  250. }
  251. public function runTestsWithDependencyInjections(\CliGuy $I)
  252. {
  253. $I->executeCommand('run math');
  254. $I->seeInShellOutput('MathCest: Test addition');
  255. $I->seeInShellOutput('MathCest: Test subtraction');
  256. $I->seeInShellOutput('MathCest: Test square');
  257. $I->seeInShellOutput('MathTest: All');
  258. $I->seeInShellOutput('OK (');
  259. $I->dontSeeInShellOutput('fail');
  260. $I->dontSeeInShellOutput('error');
  261. }
  262. public function runErrorTest(\CliGuy $I)
  263. {
  264. $I->executeCommand('run unit ErrorTest --no-exit');
  265. $I->seeInShellOutput('There was 1 error');
  266. $I->seeInShellOutput('Array to string conversion');
  267. $I->seeInShellOutput('ErrorTest.php');
  268. }
  269. public function runTestWithException(\CliGuy $I)
  270. {
  271. $I->executeCommand('run unit ExceptionTest --no-exit -v');
  272. $I->seeInShellOutput('There was 1 error');
  273. $I->seeInShellOutput('Helllo!');
  274. $I->expect('Exceptions are not wrapped into ExceptionWrapper');
  275. $I->dontSeeInShellOutput('PHPUnit_Framework_ExceptionWrapper');
  276. $I->seeInShellOutput('RuntimeException');
  277. }
  278. public function runTestsWithSteps(\CliGuy $I)
  279. {
  280. $I->executeCommand('run scenario SuccessCept --steps');
  281. $I->seeInShellOutput(<<<EOF
  282. Scenario --
  283. I am in path "."
  284. I see file found "scenario.suite.yml"
  285. PASSED
  286. EOF
  287. );
  288. }
  289. /**
  290. * @param CliGuy $I
  291. */
  292. public function runTestWithFailedScenario(\CliGuy $I, $scenario)
  293. {
  294. if (!extension_loaded('xdebug') && !defined('HHVM_VERSION')) {
  295. $scenario->skip("Xdebug not loaded");
  296. }
  297. $I->executeCommand('run scenario FailedCept --steps --no-exit');
  298. $I->seeInShellOutput(<<<EOF
  299. FailedCept: Fail when file is not found
  300. Signature: FailedCept
  301. Test: tests/scenario/FailedCept.php
  302. Scenario --
  303. I am in path "."
  304. I see file found "games.zip"
  305. FAIL
  306. EOF
  307. );
  308. $I->expect('to see scenario trace');
  309. $I->seeInShellOutput(<<<EOF
  310. Scenario Steps:
  311. 2. \$I->seeFileFound("games.zip") at tests/scenario/FailedCept.php:5
  312. 1. \$I->amInPath(".") at tests/scenario/FailedCept.php:4
  313. EOF
  314. );
  315. }
  316. /**
  317. * @param CliGuy $I
  318. */
  319. public function runTestWithSubSteps(\CliGuy $I, $scenario)
  320. {
  321. if (!extension_loaded('xdebug') && !defined('HHVM_VERSION')) {
  322. $scenario->skip("Xdebug not loaded");
  323. }
  324. $file = "codeception" . DIRECTORY_SEPARATOR . "c3";
  325. $I->executeCommand('run scenario SubStepsCept --steps');
  326. $I->seeInShellOutput(<<<EOF
  327. Scenario --
  328. I am in path "."
  329. I see code coverage files are present
  330. EOF
  331. );
  332. // I split this assertion into two, because extra space is printed after "present" on HHVM
  333. $I->seeInShellOutput(<<<EOF
  334. I see file found "c3.php"
  335. I see file found "composer.json"
  336. I see in this file "$file"
  337. EOF
  338. );
  339. }
  340. public function runDependentCest(CliGuy $I)
  341. {
  342. $I->executeCommand('run order DependentCest --no-exit');
  343. $I->seeInShellOutput('Skipped: 1');
  344. }
  345. public function runDependentTest(CliGuy $I)
  346. {
  347. $I->executeCommand('run unit DependsTest --no-exit');
  348. $I->seeInShellOutput('Skipped: 1');
  349. $I->executeCommand('run unit --no-exit');
  350. $I->seeInShellOutput('Skipped: 2');
  351. }
  352. public function runGherkinTest(CliGuy $I)
  353. {
  354. $I->executeCommand('run scenario File.feature --steps');
  355. $I->seeInShellOutput(<<<EOF
  356. In order to test a feature
  357. As a user
  358. I need to be able to see output
  359. EOF
  360. );
  361. $I->seeInShellOutput('Given i have terminal opened');
  362. $I->seeInShellOutput('When i am in current directory');
  363. $I->seeInShellOutput('Then there is a file "scenario.suite.yml"');
  364. $I->seeInShellOutput('And there are keywords in "scenario.suite.yml"');
  365. $I->seeInShellOutput(<<<EOF
  366. | class_name | ScenarioGuy |
  367. | enabled | Filesystem |
  368. EOF
  369. );
  370. $I->seeInShellOutput('PASSED');
  371. }
  372. public function reportsCorrectFailedStep(CliGuy $I)
  373. {
  374. $I->executeCommand('run scenario File.feature -v');
  375. $I->seeInShellOutput('OK, but incomplete');
  376. $I->seeInShellOutput('Step definition for `I have only idea of what\'s going on here` not found in contexts');
  377. }
  378. public function runFailingGherkinTest(CliGuy $I)
  379. {
  380. $I->executeCommand('run scenario Fail.feature -v --no-exit');
  381. $I->seeInShellOutput('Step I see file "games.zip"');
  382. $I->seeInShellOutput('Step I see file "tools.zip"');
  383. }
  384. public function runGherkinScenarioWithMultipleStepDefinitions(CliGuy $I)
  385. {
  386. $I->executeCommand('run scenario "File.feature:Check file once more" --steps');
  387. $I->seeInShellOutput('When there is a file "scenario.suite.yml"');
  388. $I->seeInShellOutput('Then i see file "scenario.suite.yml"');
  389. $I->dontSeeInShellOutput('Step definition for `I see file "scenario.suite.yml"` not found in contexts');
  390. $I->seeInShellOutput('PASSED');
  391. }
  392. public function runGherkinScenarioOutline(CliGuy $I)
  393. {
  394. $I->executeCommand('run scenario FileExamples.feature -v');
  395. $I->seeInShellOutput('OK (3 tests');
  396. }
  397. /**
  398. * @param CliGuy $I
  399. * @after checkExampleFiles
  400. */
  401. public function runTestWithAnnotationExamples(CliGuy $I)
  402. {
  403. $I->executeCommand('run scenario ExamplesCest:filesExistsAnnotation --steps');
  404. }
  405. /**
  406. * @param CliGuy $I
  407. * @after checkExampleFiles
  408. */
  409. public function runTestWithJsonExamples(CliGuy $I)
  410. {
  411. $I->executeCommand('run scenario ExamplesCest:filesExistsByJson --steps');
  412. }
  413. /**
  414. * @param CliGuy $I
  415. * @after checkExampleFiles
  416. */
  417. public function runTestWithArrayExamples(CliGuy $I)
  418. {
  419. $I->executeCommand('run scenario ExamplesCest:filesExistsByArray --steps');
  420. }
  421. protected function checkExampleFiles(CliGuy $I)
  422. {
  423. $I->seeInShellOutput('OK (3 tests');
  424. $I->seeInShellOutput('I see file found "scenario.suite.yml"');
  425. $I->seeInShellOutput('I see file found "dummy.suite.yml"');
  426. $I->seeInShellOutput('I see file found "unit.suite.yml"');
  427. }
  428. public function runTestWithComplexExample(CliGuy $I)
  429. {
  430. $I->executeCommand('run scenario ExamplesCest:filesExistsComplexJson --debug');
  431. $I->seeInShellOutput('Files exists complex json | {"path":"."');
  432. $I->seeInShellOutput('OK (1 test');
  433. $I->seeInShellOutput('I see file found "scenario.suite.yml"');
  434. $I->seeInShellOutput('I see file found "dummy.suite.yml"');
  435. $I->seeInShellOutput('I see file found "unit.suite.yml"');
  436. }
  437. public function overrideConfigOptionsToChangeReporter(CliGuy $I)
  438. {
  439. if (!class_exists('PHPUnit_Util_Log_TeamCity')) {
  440. throw new \Codeception\Exception\Skip('Reporter does not exist for this PHPUnit version');
  441. }
  442. $I->executeCommand('run scenario --report -o "reporters: report: PHPUnit_Util_Log_TeamCity" --no-exit');
  443. $I->seeInShellOutput('##teamcity[testStarted');
  444. $I->dontSeeInShellOutput('............Ok');
  445. }
  446. public function overrideModuleOptions(CliGuy $I)
  447. {
  448. $I->executeCommand('run powers PowerIsRisingCept --no-exit');
  449. $I->seeInShellOutput('FAILURES');
  450. $I->executeCommand('run powers PowerIsRisingCept -o "modules: config: PowerHelper: has_power: true" --no-exit');
  451. $I->dontSeeInShellOutput('FAILURES');
  452. }
  453. public function runTestWithAnnotationExamplesFromGroupFileTest(CliGuy $I)
  454. {
  455. $I->executeCommand('run scenario -g groupFileTest1 --steps');
  456. $I->seeInShellOutput('OK (3 tests');
  457. }
  458. public function testsWithConditionalFails(CliGuy $I)
  459. {
  460. $I->executeCommand('run scenario ConditionalCept --no-exit');
  461. $I->seeInShellOutput('There were 3 failures');
  462. $I->seeInShellOutput('Fail File "not-a-file" not found');
  463. $I->seeInShellOutput('Fail File "not-a-dir" not found');
  464. $I->seeInShellOutput('Fail File "nothing" not found');
  465. }
  466. public function runTestWithAnnotationDataprovider(CliGuy $I)
  467. {
  468. $I->executeCommand('run scenario -g dataprovider --steps');
  469. $I->seeInShellOutput('OK (15 tests');
  470. }
  471. public function runFailedTestAndCheckOutput(CliGuy $I)
  472. {
  473. $I->executeCommand('run scenario FailedCept', false);
  474. $testPath = implode(DIRECTORY_SEPARATOR, ['tests', 'scenario', 'FailedCept.php']);
  475. $I->seeInShellOutput('1) FailedCept: Fail when file is not found');
  476. $I->seeInShellOutput('Test ' . $testPath);
  477. $I->seeInShellOutput('Step See file found "games.zip"');
  478. $I->seeInShellOutput('Fail File "games.zip" not found at ""');
  479. }
  480. public function runTestWithCustomSetupMethod(CliGuy $I)
  481. {
  482. $I->executeCommand('run powers PowerUpCest');
  483. $I->dontSeeInShellOutput('FAILURES');
  484. }
  485. public function runCestWithTwoFailedTest(CliGuy $I)
  486. {
  487. $I->executeCommand('run scenario PartialFailedCest', false);
  488. $I->seeInShellOutput('See file found "testcasetwo.txt"');
  489. $I->seeInShellOutput('See file found "testcasethree.txt"');
  490. $I->seeInShellOutput('Tests: 3,');
  491. $I->seeInShellOutput('Failures: 2.');
  492. }
  493. public function runWarningTests(CliGuy $I)
  494. {
  495. $I->executeCommand('run unit WarningTest.php', false);
  496. $I->seeInShellOutput('There was 1 warning');
  497. $I->seeInShellOutput('WarningTest::testWarningInvalidDataProvider');
  498. $I->seeInShellOutput('Tests: 1,');
  499. $I->seeInShellOutput('Warnings: 1.');
  500. }
  501. /**
  502. * @group shuffle
  503. * @param CliGuy $I
  504. */
  505. public function showSeedNumberOnShuffle(CliGuy $I)
  506. {
  507. $I->executeCommand('run unit -o "settings: shuffle: true"', false);
  508. $I->seeInShellOutput('Seed');
  509. $I->executeCommand('run unit', false);
  510. $I->dontSeeInShellOutput('Seed');
  511. }
  512. /**
  513. * @group shuffle
  514. * @param CliGuy $I
  515. */
  516. public function showSameOrderOfFilesOnSeed(CliGuy $I, \Codeception\Scenario $s)
  517. {
  518. if (DIRECTORY_SEPARATOR === '\\') {
  519. $s->skip('Failing on Windows. Need to investigate');
  520. }
  521. $I->executeCommand('run unit -o "settings: shuffle: true"', false);
  522. $I->seeInShellOutput('Seed');
  523. $output = $I->grabFromOutput('/---\n((.|\n)*?)---/m');
  524. $output = preg_replace('~\(\d\.\d+s\)~m', '', $output);
  525. $seed = $I->grabFromOutput('~\[Seed\] (.*)~');
  526. $I->executeCommand('run unit -o "settings: shuffle: true" --seed ' . $seed, false);
  527. $newOutput = $I->grabFromOutput('/---\n((.|\n)*?)---/m');
  528. $newOutput = preg_replace('~\(\d\.\d+s\)~m', '', $newOutput);
  529. $I->assertEquals($output, $newOutput, 'order of tests is the same');
  530. $I->executeCommand('run unit -o "settings: shuffle: true"', false);
  531. $newOutput = $I->grabFromOutput('/---\n((.|\n)*?)---/m');
  532. $newOutput = preg_replace('~\(\d\.\d+s\)~m', '', $newOutput);
  533. $I->assertNotEquals($output, $newOutput, 'order of tests is the same');
  534. }
  535. }