PageRenderTime 162ms CodeModel.GetById 36ms RepoModel.GetById 2ms app.codeStats 0ms

/tests/phpunit.php

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