GenerateScenarioTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. use Codeception\Lib\ModuleContainer;
  3. use Codeception\Util\Stub;
  4. require_once __DIR__ . DIRECTORY_SEPARATOR . 'BaseCommandRunner.php';
  5. class GenerateScenarioTest extends BaseCommandRunner
  6. {
  7. /**
  8. * @var ModuleContainer
  9. */
  10. protected $moduleContainer;
  11. protected function setUp()
  12. {
  13. $this->moduleContainer = new ModuleContainer(Stub::make('Codeception\Lib\Di'), []);
  14. $this->moduleContainer->create('EmulateModuleHelper');
  15. $this->modules = $this->moduleContainer->all();
  16. $this->actions = $this->moduleContainer->getActions();
  17. $this->filename = null;
  18. $this->makeCommand('\Codeception\Command\GenerateScenarios');
  19. $this->config = array(
  20. 'paths' => array(
  21. 'tests' => 'tests/data/claypit/tests/',
  22. 'data' => '_data',
  23. ),
  24. 'class_name' => 'DumbGuy',
  25. 'path' => 'tests/data/claypit/tests/dummy/'
  26. );
  27. }
  28. public function testBasic()
  29. {
  30. $this->execute(array('suite' => 'dummy'));
  31. $file = codecept_root_dir().'tests/data/scenarios/dummy/File_Exists.txt';
  32. $this->assertArrayHasKey($file, $this->saved);
  33. $content = $this->saved[$file];
  34. $this->assertContains('I WANT TO CHECK CONFIG EXISTS', $content);
  35. $this->assertContains('I see file found "$codeception"', $content);
  36. $this->assertContains('* File_Exists generated', $this->output);
  37. }
  38. public function testMultipleTestsGeneration()
  39. {
  40. $this->execute(['suite' => 'dummy']);
  41. $this->assertArrayHasKey(codecept_root_dir().'tests/data/scenarios/dummy/Another.optimistic.txt', $this->saved);
  42. $this->assertArrayHasKey(codecept_root_dir().'tests/data/scenarios/dummy/Another.pessimistic.txt', $this->saved);
  43. $file = codecept_root_dir().'tests/data/scenarios/dummy/File_Exists.txt';
  44. $this->assertArrayHasKey($file, $this->saved);
  45. $content = $this->saved[$file];
  46. $this->assertContains('I WANT TO CHECK CONFIG EXISTS', $content);
  47. $this->assertContains('I see file found "$codeception"', $content);
  48. $this->assertContains('* File_Exists generated', $this->output);
  49. }
  50. public function testHtml()
  51. {
  52. $this->execute(array('suite' => 'dummy', '--format' => 'html'));
  53. $file = codecept_root_dir().'tests/data/scenarios/dummy/File_Exists.html';
  54. $this->assertArrayHasKey($file, $this->saved);
  55. $content = $this->saved[$file];
  56. $this->assertContains('<html><body><h3>I WANT TO CHECK CONFIG EXISTS</h3>', $content);
  57. $this->assertContains('I see file found &quot;$codeception&quot;', strip_tags($content));
  58. $this->assertContains('* File_Exists generated', $this->output);
  59. }
  60. public function testOneFile()
  61. {
  62. $this->config['path'] = 'tests/data/claypit/tests/skipped/';
  63. $this->config['class_name'] = 'SkipGuy';
  64. $this->execute(array('suite' => 'skipped', '--single-file' => true));
  65. $this->assertEquals(codecept_root_dir().'tests/data/scenarios/skipped.txt', $this->filename);
  66. $this->assertContains('I WANT TO SKIP IT', $this->content);
  67. $this->assertContains('I WANT TO MAKE IT INCOMPLETE', $this->content);
  68. $this->assertContains('* Skip_Me rendered', $this->output);
  69. $this->assertContains('* Incomplete_Me rendered', $this->output);
  70. }
  71. public function testOneFileWithHtml()
  72. {
  73. $this->config['path'] = 'tests/data/claypit/tests/skipped/';
  74. $this->config['class_name'] = 'SkipGuy';
  75. $this->execute(array('suite' => 'skipped', '--single-file' => true, '--format' => 'html'));
  76. $this->assertEquals(codecept_root_dir().'tests/data/scenarios/skipped.html', $this->filename);
  77. $this->assertContains('<h3>I WANT TO MAKE IT INCOMPLETE</h3>', $this->content);
  78. $this->assertContains('<h3>I WANT TO SKIP IT</h3>', $this->content);
  79. $this->assertContains('<body><h3>', $this->content);
  80. $this->assertContains('</body></html>', $this->content);
  81. $this->assertContains('* Skip_Me rendered', $this->output);
  82. $this->assertContains('* Incomplete_Me rendered', $this->output);
  83. }
  84. public function testDifferentPath()
  85. {
  86. $this->execute(array('suite' => 'dummy', '--single-file' => true, '--path' => 'docs'));
  87. $this->assertEquals('docs/dummy.txt', $this->filename);
  88. $this->assertContains('I WANT TO CHECK CONFIG EXISTS', $this->content);
  89. $this->assertContains('* File_Exists rendered', $this->output);
  90. }
  91. }