PageRenderTime 901ms CodeModel.GetById 654ms app.highlight 4ms RepoModel.GetById 161ms app.codeStats 0ms

/tests/phpunit.php

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