PruneTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * This file allows for tests to be skipped.
  4. * For now conditions are simple.
  5. * We check if changes in the source with respect to the configured branch are limited to framework files,
  6. * if that is the case and the current framework isn't one with changed files then we skip it.
  7. */
  8. $branch ="2.5";
  9. function stderr($message)
  10. {
  11. fwrite(STDERR, $message . "\n");
  12. }
  13. $currentFramework = getenv('FRAMEWORK');
  14. if ($currentFramework === 'Codeception') {
  15. stderr('Codeception tests are always executed');
  16. die();
  17. }
  18. $files = [];
  19. // Workaround for travis #4806
  20. passthru("git fetch origin $branch:$branch --depth 1", $return);
  21. if ($return !== 0) {
  22. stderr("Git fetch failed");
  23. die($return);
  24. }
  25. exec("git diff --name-only $branch --", $files, $return);
  26. if ($return !== 0) {
  27. stderr("Git diff failed");
  28. die($return);
  29. }
  30. // Regexes for frameworks:
  31. $regexes = [
  32. 'Yii2' => '/.*Yii2.*/',
  33. 'Lumen' => '/.*(Lumen|LaravelCommon).*/',
  34. 'Laravel' => '/.*Laravel.*/',
  35. 'Phalcon' => '/.*Phalcon.*/',
  36. 'Symfony' => '/.*Symfony.*/',
  37. 'Yii1' => '/.*Yii1.*/',
  38. 'ZendExpressive' => '/.*ZendExpressive.*/',
  39. 'Zend1' => '/.*ZF1.*/',
  40. 'Zend2' => '/.*ZF2.*/',
  41. ];
  42. // First check if changes include files that are not framework files.
  43. $frameworkOnly = true;
  44. $frameworks = [];
  45. foreach ($files as $file) {
  46. $match = false;
  47. foreach ($regexes as $framework => $regex) {
  48. if (preg_match($regex, $file)) {
  49. $match = true;
  50. $frameworks[$framework] = $framework;
  51. break;
  52. }
  53. }
  54. if (!$match) {
  55. $frameworkOnly = false;
  56. break;
  57. }
  58. }
  59. if ($frameworkOnly) {
  60. stderr('Changes limited to frameworks: ' . implode(', ', $frameworks));
  61. if (!isset($frameworks[$currentFramework])) {
  62. stderr("Skipping test for framework: $currentFramework");
  63. echo "export FRAMEWORK=\n";
  64. echo "export PECL=\n";
  65. echo "export FXP=\n";
  66. echo "export CI_USER_TOKEN=\n";
  67. }
  68. }