ExtensionsCest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. class ExtensionsCest
  3. {
  4. // tests
  5. public function useAlternativeFormatter(CliGuy $I)
  6. {
  7. $I->wantTo('use alternative formatter delivered through extensions');
  8. $I->amInPath('tests/data/sandbox');
  9. $I->executeCommand('run tests/dummy/FileExistsCept.php -c codeception_extended.yml');
  10. $I->dontSeeInShellOutput("Check config");
  11. $I->seeInShellOutput('[+] FileExistsCept');
  12. $I->seeInShellOutput('Modules used: Filesystem, DumbHelper');
  13. }
  14. public function loadExtensionByOverride(CliGuy $I)
  15. {
  16. $I->amInPath('tests/data/sandbox');
  17. $I->executeCommand('run tests/dummy/FileExistsCept.php -o "extensions: enabled: [\Codeception\Extension\SimpleReporter]"');
  18. $I->dontSeeInShellOutput("Check config");
  19. $I->seeInShellOutput('[+] FileExistsCept');
  20. }
  21. public function dynamicallyEnablingExtensions(CliGuy $I)
  22. {
  23. $I->amInPath('tests/data/sandbox');
  24. $I->executeCommand('run dummy --ext DotReporter');
  25. $I->seeInShellOutput('......');
  26. $I->dontSeeInShellOutput('Optimistic');
  27. $I->dontSeeInShellOutput('AnotherCest');
  28. }
  29. public function reRunFailedTests(CliGuy $I)
  30. {
  31. $ds = DIRECTORY_SEPARATOR;
  32. $I->amInPath('tests/data/sandbox');
  33. $I->executeCommand('run unit FailingTest.php -c codeception_extended.yml --no-exit');
  34. $I->seeInShellOutput('FAILURES');
  35. $I->seeFileFound('failed', 'tests/_output');
  36. $I->seeFileContentsEqual("tests{$ds}unit{$ds}FailingTest.php:testMe");
  37. $I->executeCommand('run -g failed -c codeception_extended.yml --no-exit');
  38. $I->seeInShellOutput('Tests: 1, Assertions: 1, Failures: 1');
  39. $failGroup = "some-failed";
  40. $I->executeCommand("run unit FailingTest.php -c codeception_extended.yml --no-exit --override \"extensions: config: Codeception\\Extension\\RunFailed: fail-group: {$failGroup}\"");
  41. $I->seeInShellOutput('FAILURES');
  42. $I->seeFileFound($failGroup, 'tests/_output');
  43. $I->seeFileContentsEqual("tests{$ds}unit{$ds}FailingTest.php:testMe");
  44. $I->executeCommand("run -g {$failGroup} -c codeception_extended.yml --no-exit --override \"extensions: config: Codeception\\Extension\\RunFailed: fail-group: {$failGroup}\"");
  45. $I->seeInShellOutput('Tests: 1, Assertions: 1, Failures: 1');
  46. }
  47. public function checkIfExtensionsReceiveCorrectOptions(CliGuy $I)
  48. {
  49. $I->wantTo('check if extensions receive correct options');
  50. $I->amInPath('tests/data/sandbox');
  51. $I->executeCommand('run tests/dummy/AnotherCest.php:optimistic -c codeception_extended.yml');
  52. $I->seeInShellOutput('Low verbosity');
  53. $I->executeCommand('run tests/dummy/AnotherCest.php:optimistic -c codeception_extended.yml -v');
  54. $I->seeInShellOutput('Medium verbosity');
  55. $I->executeCommand('run tests/dummy/AnotherCest.php:optimistic -c codeception_extended.yml -vv');
  56. $I->seeInShellOutput('High verbosity');
  57. $I->executeCommand('run tests/dummy/AnotherCest.php:optimistic -c codeception_extended.yml -vvv');
  58. $I->seeInShellOutput('Extreme verbosity');
  59. }
  60. public function runPerSuiteExtensions(CliGuy $I)
  61. {
  62. $I->amInPath('tests/data/sandbox');
  63. $I->executeCommand('run extended,scenario', false);
  64. $I->seeInShellOutput('Suite setup for extended');
  65. $I->seeInShellOutput('Test setup for Hello');
  66. $I->seeInShellOutput('Test teardown for Hello');
  67. $I->seeInShellOutput('Suite teardown for extended');
  68. $I->dontSeeInShellOutput('Suite setup for scenario');
  69. $I->seeInShellOutput('Config1: value1');
  70. $I->seeInShellOutput('Config2: value2');
  71. }
  72. public function runPerSuiteExtensionsInEnvironment(CliGuy $I)
  73. {
  74. $I->amInPath('tests/data/sandbox');
  75. $I->executeCommand('run extended --env black', false);
  76. $I->seeInShellOutput('Suite setup for extended');
  77. $I->seeInShellOutput('Test setup for Hello');
  78. $I->seeInShellOutput('Config1: black_value');
  79. $I->seeInShellOutput('Config2: value2');
  80. }
  81. }