TravisValidateCommitMsgTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace Elgg;
  3. /**
  4. * Tests the travis shell script
  5. */
  6. class TravisValidateCommitMsgTest extends CommitMessageGitHookTest {
  7. protected $travisScript;
  8. public function setUp() {
  9. parent::setUp();
  10. $this->travisScript = $this->scriptsDir . 'travis/check_commit_msgs.sh';
  11. $this->markTestSkipped('Testing against particular SHAs is too flaky.');
  12. }
  13. /**
  14. * Test the TRAVIS_COMMIT_RANGE env var
  15. */
  16. /**
  17. * Range with valid msgs
  18. */
  19. public function testRange() {
  20. // baf2df9355a5fc63679ad1aa80f363d00a51572b..3749dda1411437bc8029b1facfe5922059a247f1
  21. $cmd = "bash {$this->travisScript}";
  22. $result = $this->runCmd($cmd, $output, array(
  23. 'TRAVIS_COMMIT_RANGE' => "baf2df9355a5fc63679ad1aa80f363d00a51572b...3749dda1411437bc8029b1facfe5922059a247f1",
  24. ));
  25. $this->assertTrue($result, $output);
  26. // and with two dots
  27. $cmd = "bash {$this->travisScript}";
  28. $result = $this->runCmd($cmd, $output, array(
  29. 'TRAVIS_COMMIT_RANGE' => "baf2df9355a5fc63679ad1aa80f363d00a51572b..3749dda1411437bc8029b1facfe5922059a247f1",
  30. ));
  31. $this->assertTrue($result, $output);
  32. }
  33. /**
  34. * Range with all invalid msgs
  35. */
  36. public function testFailingRange() {
  37. // 10e85ea6eff9921d5bed5d501750d660825e9304..fc62de7a6b03c3ca11f2a057db20fe2414c47d1f
  38. $cmd = "bash {$this->travisScript}";
  39. $result = $this->runCmd($cmd, $output, array(
  40. 'TRAVIS_COMMIT_RANGE' => '10e85ea6eff9921d5bed5d501750d660825e9304..fc62de7a6b03c3ca11f2a057db20fe2414c47d1f',
  41. ));
  42. $this->assertFalse($result, $output);
  43. }
  44. /**
  45. * Range with some failing msgs
  46. */
  47. public function testSomeFailingRange() {
  48. // 6d3886c6b6a01399891f11b3c675fa9135786bd1..6448bb95497db21923542a10983915023c1c2d32
  49. $cmd = "bash {$this->travisScript}";
  50. $result = $this->runCmd($cmd, $output, array(
  51. 'TRAVIS_COMMIT_RANGE' => '6d3886c6b6a01399891f11b3c675fa9135786bd1..6448bb95497db21923542a10983915023c1c2d32',
  52. ));
  53. $this->assertFalse($result, $output);
  54. }
  55. /**
  56. * Test the TRAVIS_COMMIT env var
  57. */
  58. /**
  59. * Single commit with valid msg
  60. */
  61. public function testCommit() {
  62. // https://github.com/Elgg/Elgg/commit/6c84d2f394530bcaceb377e734c075c227923cb7
  63. $cmd = "bash {$this->travisScript}";
  64. $result = $this->runCmd($cmd, $output, array(
  65. 'TRAVIS_COMMIT' => '6c84d2f394530bcaceb377e734c075c227923cb7',
  66. ));
  67. $this->assertTrue($result, $output);
  68. }
  69. /**
  70. * Single commit with invalid msg
  71. */
  72. public function testFailingCommit() {
  73. // https://github.com/Elgg/Elgg/commit/8f420a15d8fe567d78dca0ee97bc71305842c995
  74. $cmd = "bash {$this->travisScript}";
  75. $result = $this->runCmd($cmd, $output, array(
  76. 'TRAVIS_COMMIT' => '8f420a15d8fe567d78dca0ee97bc71305842c995',
  77. ));
  78. $this->assertFalse($result, $output);
  79. }
  80. /**
  81. * Test PR with all valid msgs
  82. */
  83. public function testPrMerge() {
  84. // https://github.com/Elgg/Elgg/commit/9a54813f36ba019e11561ba4f685021a0f4dbf9a
  85. $cmd = "bash {$this->travisScript}";
  86. $result = $this->runCmd($cmd, $output, array(
  87. 'TRAVIS_COMMIT' => '9a54813f36ba019e11561ba4f685021a0f4dbf9a',
  88. ));
  89. $this->assertTrue($result, $output);
  90. }
  91. /**
  92. * PR with invalid messages
  93. */
  94. public function testFailingPrMerge() {
  95. // https://github.com/Elgg/Elgg/commit/cfc2a3fb9e97488e36f5a5771c816fff90e3691f
  96. $cmd = "bash {$this->travisScript}";
  97. $result = $this->runCmd($cmd, $output, array(
  98. 'TRAVIS_COMMIT' => 'cfc2a3fb9e97488e36f5a5771c816fff90e3691f',
  99. ));
  100. $this->assertFalse($result, $output);
  101. }
  102. /**
  103. * Test passing commits as an argument
  104. */
  105. /**
  106. * Single commit
  107. */
  108. public function testSHAAsArg() {
  109. $sha = '6c84d2f394530bcaceb377e734c075c227923cb7';
  110. $cmd = "bash {$this->travisScript} $sha";
  111. $result = $this->runCmd($cmd, $output);
  112. $this->assertTrue($result, $output);
  113. }
  114. /**
  115. * Range
  116. */
  117. public function testRangeAsArg() {
  118. $range = "baf2df9355a5fc63679ad1aa80f363d00a51572b..3749dda1411437bc8029b1facfe5922059a247f1";
  119. $cmd = "bash {$this->travisScript} $range";
  120. $result = $this->runCmd($cmd, $output);
  121. $this->assertTrue($result, $output);
  122. }
  123. public function testPrAsArg() {
  124. $sha = '9a54813f36ba019e11561ba4f685021a0f4dbf9a';
  125. $cmd = "bash {$this->travisScript} $sha";
  126. $result = $this->runCmd($cmd, $output);
  127. $this->assertTrue($result, $output);
  128. }
  129. }