PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/phpunit.php

http://github.com/vanillaforums/Garden
PHP | 77 lines | 24 code | 8 blank | 45 comment | 3 complexity | 17eb7125cba338a4c84b03a2d8bf5621 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, AGPL-1.0, BSD-3-Clause, MIT
  1. <?php
  2. /**
  3. * @copyright 2009-2019 Vanilla Forums Inc.
  4. * @license GPL-2.0-only
  5. */
  6. use VanillaTests\NullContainer;
  7. // Use consistent timezone for all tests.
  8. date_default_timezone_set("UTC");
  9. ini_set("default_charset", "UTF-8");
  10. error_reporting(E_ALL);
  11. // Alias classes for some limited PHPUnit v5 compatibility with v6.
  12. $classCompatibility = [
  13. 'PHPUnit\\Framework\\TestCase' => 'PHPUnit_Framework_TestCase', // See https://github.com/php-fig/log/pull/52
  14. ];
  15. foreach ($classCompatibility as $class => $legacyClass) {
  16. if (!class_exists($legacyClass) && class_exists($class)) {
  17. class_alias($class, $legacyClass);
  18. }
  19. }
  20. // Define some constants to help with testing.
  21. define('APPLICATION', 'Vanilla Tests');
  22. define('PATH_ROOT', realpath(__DIR__.'/..'));
  23. define('PATH_UPLOADS', PATH_ROOT . '/tests/cache/uploads');
  24. define("PATH_FIXTURES", PATH_ROOT . DIRECTORY_SEPARATOR . "tests" . DIRECTORY_SEPARATOR . "fixtures");
  25. // Copy the cgi-bin files.
  26. $dir = PATH_ROOT.'/cgi-bin';
  27. if (!file_exists($dir)) {
  28. mkdir($dir);
  29. }
  30. $files = glob(PATH_ROOT."/.circleci/scripts/templates/vanilla/cgi-bin/*.php");
  31. foreach ($files as $file) {
  32. $dest = $dir.'/'.basename($file);
  33. $r = copy($file, $dest);
  34. echo "Copy $file to $dest";
  35. }
  36. // ===========================================================================
  37. // Adding the minimum dependencies to support unit testing for core libraries
  38. // ===========================================================================
  39. require PATH_ROOT.'/environment.php';
  40. // Allow a test before.
  41. $bootstrapTestFile = PATH_CONF . '/bootstrap.tests.php';
  42. if (file_exists($bootstrapTestFile)) {
  43. require_once $bootstrapTestFile;
  44. }
  45. // This effectively disable the auto instanciation of a new container when calling Gdn::getContainer();
  46. Gdn::setContainer(new NullContainer());
  47. // Clear the test cache.
  48. \Gdn_FileSystem::removeFolder(PATH_ROOT.'/tests/cache');
  49. // Ensure our uploads directory exists.
  50. mkdir(PATH_ROOT.'/tests/cache', 0777);
  51. mkdir(PATH_UPLOADS, 0777);
  52. require_once PATH_LIBRARY_CORE.'/functions.validation.php';
  53. require_once PATH_LIBRARY_CORE.'/functions.render.php';
  54. // Include test utilities.
  55. $utilityFiles = array_merge(
  56. glob(PATH_ROOT.'/plugins/*/tests/Utils/*.php'),
  57. glob(PATH_ROOT.'/applications/*/tests/Utils/*.php')
  58. );
  59. foreach ($utilityFiles as $file) {
  60. require_once $file;
  61. }