GroupManagerTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace Codeception\Lib;
  3. use Codeception\Util\Stub;
  4. use Codeception\Test\Loader\Gherkin as GherkinLoader;
  5. class GroupManagerTest extends \Codeception\Test\Unit
  6. {
  7. /**
  8. * @var \Codeception\Lib\GroupManager
  9. */
  10. protected $manager;
  11. // tests
  12. public function testGroupsFromArray()
  13. {
  14. $this->manager = new GroupManager(['important' => ['UserTest.php:testName', 'PostTest.php']]);
  15. $test1 = $this->makeTestCase('UserTest.php', 'testName');
  16. $test2 = $this->makeTestCase('PostTest.php');
  17. $test3 = $this->makeTestCase('UserTest.php', 'testNot');
  18. $this->assertContains('important', $this->manager->groupsForTest($test1));
  19. $this->assertContains('important', $this->manager->groupsForTest($test2));
  20. $this->assertNotContains('important', $this->manager->groupsForTest($test3));
  21. }
  22. public function testGroupsFromFile()
  23. {
  24. $this->manager = new GroupManager(['important' => 'tests/data/test_groups']);
  25. $test1 = $this->makeTestCase('tests/UserTest.php', 'testName');
  26. $test2 = $this->makeTestCase('tests/PostTest.php');
  27. $test3 = $this->makeTestCase('tests/UserTest.php', 'testNot');
  28. $this->assertContains('important', $this->manager->groupsForTest($test1));
  29. $this->assertContains('important', $this->manager->groupsForTest($test2));
  30. $this->assertNotContains('important', $this->manager->groupsForTest($test3));
  31. }
  32. public function testGroupsFromFileOnWindows()
  33. {
  34. $this->manager = new GroupManager(['important' => 'tests/data/group_3']);
  35. $test = $this->makeTestCase('tests/WinTest.php');
  36. $this->assertContains('important', $this->manager->groupsForTest($test));
  37. }
  38. public function testGroupsFromArrayOnWindows()
  39. {
  40. $this->manager = new GroupManager(['important' => ['tests\WinTest.php']]);
  41. $test = $this->makeTestCase('tests/WinTest.php');
  42. $this->assertContains('important', $this->manager->groupsForTest($test));
  43. }
  44. public function testGroupsByPattern()
  45. {
  46. $this->manager = new GroupManager(['group_*' => 'tests/data/group_*']);
  47. $test1 = $this->makeTestCase('tests/UserTest.php');
  48. $test2 = $this->makeTestCase('tests/PostTest.php');
  49. $this->assertContains('group_1', $this->manager->groupsForTest($test1));
  50. $this->assertContains('group_2', $this->manager->groupsForTest($test2));
  51. }
  52. public function testGroupsByDifferentPattern()
  53. {
  54. $this->manager = new GroupManager(['g_*' => 'tests/data/group_*']);
  55. $test1 = $this->makeTestCase('tests/UserTest.php');
  56. $test2 = $this->makeTestCase('tests/PostTest.php');
  57. $this->assertContains('g_1', $this->manager->groupsForTest($test1));
  58. $this->assertContains('g_2', $this->manager->groupsForTest($test2));
  59. }
  60. public function testGroupsFileHandlesWhitespace()
  61. {
  62. $this->manager = new GroupManager(['whitespace_group_test' => 'tests/data/whitespace_group_test']);
  63. $goodTest = $this->makeTestCase('tests/WhitespaceTest.php');
  64. $badTest = $this->makeTestCase('');
  65. $this->assertContains('whitespace_group_test', $this->manager->groupsForTest($goodTest));
  66. $this->assertEmpty($this->manager->groupsForTest($badTest));
  67. }
  68. public function testLoadSpecificScenarioFromFile()
  69. {
  70. $this->manager = new GroupManager(['gherkinGroup1' => 'tests/data/gherkinGroup1']);
  71. $loader = new GherkinLoader();
  72. $loader->loadTests(codecept_absolute_path('tests/data/refund.feature'));
  73. $test = $loader->getTests()[0];
  74. $this->assertContains('gherkinGroup1', $this->manager->groupsForTest($test));
  75. }
  76. public function testLoadSpecificScenarioWithMultibyteStringFromFile()
  77. {
  78. $this->manager = new GroupManager(['gherkinGroup2' => 'tests/data/gherkinGroup2']);
  79. $loader = new GherkinLoader();
  80. $loader->loadTests(codecept_absolute_path('tests/data/refund2.feature'));
  81. $test = $loader->getTests()[0];
  82. $this->assertContains('gherkinGroup2', $this->manager->groupsForTest($test));
  83. }
  84. protected function makeTestCase($file, $name = '')
  85. {
  86. return Stub::make(
  87. '\Codeception\Lib\DescriptiveTestCase',
  88. [
  89. 'getReportFields' => ['file' => codecept_root_dir() . $file],
  90. 'getName' => $name
  91. ]
  92. );
  93. }
  94. }
  95. class DescriptiveTestCase extends \Codeception\Test\Unit
  96. {
  97. }