1<?php
2/**
3 * Unit tests for HTML_QuickForm2 package
4 *
5 * PHP version 5
6 *
7 * LICENSE
8 *
9 * This source file is subject to BSD 3-Clause License that is bundled
10 * with this package in the file LICENSE and available at the URL
11 * https://raw.githubusercontent.com/pear/HTML_QuickForm2/trunk/docs/LICENSE
12 *
13 * @category  HTML
14 * @package   HTML_QuickForm2
15 * @author    Alexey Borzov <avb@php.net>
16 * @author    Bertrand Mansion <golgote@mamasam.com>
17 * @copyright 2006-2021 Alexey Borzov <avb@php.net>, Bertrand Mansion <golgote@mamasam.com>
18 * @license   https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
19 * @link      https://pear.php.net/package/HTML_QuickForm2
20 */
21
22// We need to be sure that we have sane dependencies (HTML_Common2 and PEAR_Exception)
23// So we only allow the tests to run when installed with PEAR or with composer
24
25$installed = false;
26
27if ('@' . 'package_version@' !== '2.2.2') {
28    // Installed with PEAR: we should be on the include path, use own autoloader
29    require_once 'HTML/QuickForm2/Loader.php';
30    spl_autoload_register(['HTML_QuickForm2_Loader', 'autoload']);
31    $installed = true;
32
33} else {
34    foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
35        if (file_exists($file)) {
36            require_once $file;
37            $installed = true;
38
39            break;
40        }
41    }
42
43}
44
45if (!$installed) {
46    fwrite(STDERR,
47        'As HTML_QuickForm2 has required dependencies, tests should be run either' . PHP_EOL . PHP_EOL .
48        ' - after installation of package with PEAR:' . PHP_EOL .
49        '    php ./pear-package-helper.php' . PHP_EOL .
50        '    pear install ./.pear-package/package.xml' . PHP_EOL . PHP_EOL .
51        ' - or setting up its dependencies using Composer:' . PHP_EOL .
52        '    composer install' . PHP_EOL . PHP_EOL
53    );
54
55    die(1);
56}
57
58
59
60if (strpos($_SERVER['argv'][0], 'phpunit') === false
61    && !class_exists('PHPUnit_Framework_TestCase', true)
62) {
63    require_once 'PHPUnit/Autoload.php';
64}
65
66
67// Monkey-patching of phpunit/phpunit-mock-objects package to prevent errors like
68// "Function ReflectionType::__toString() is deprecated"
69// Inspired by https://github.com/lavary/crunz/commit/8ef1370aa47009fd1945fb73f0414bd88634ada2
70if (PHP_VERSION_ID >= 50600 // probably have PHPUnit 5.7
71    && !class_exists('PHPUnit_Framework_MockObject_Generator', false) // not too late to patch?
72    && is_dir($mock = dirname(__DIR__) . '/vendor/phpunit/phpunit-mock-objects') // have mocks in local vendor dir?
73) {
74    $source = __DIR__ . '/MockObjectGenerator.' . (PHP_VERSION_ID >= 70100 ? 'patched' : 'original') . '.php';
75    file_put_contents(
76        $mock . '/src/Framework/MockObject/Generator.php',
77        file_get_contents($source)
78    );
79}
80
81?>