GroupManagerTest.php 3.5 KB

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