File: //opt/cloudlinux/alt-php54/root/usr/share/pear/test/HTML_QuickForm2/TestHelper.php
<?php
/**
* Unit tests for HTML_QuickForm2 package
*
* PHP version 5
*
* LICENSE
*
* This source file is subject to BSD 3-Clause License that is bundled
* with this package in the file LICENSE and available at the URL
* https://raw.githubusercontent.com/pear/HTML_QuickForm2/trunk/docs/LICENSE
*
* @category HTML
* @package HTML_QuickForm2
* @author Alexey Borzov <avb@php.net>
* @author Bertrand Mansion <golgote@mamasam.com>
* @copyright 2006-2021 Alexey Borzov <avb@php.net>, Bertrand Mansion <golgote@mamasam.com>
* @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
* @link https://pear.php.net/package/HTML_QuickForm2
*/
// We need to be sure that we have sane dependencies (HTML_Common2 and PEAR_Exception)
// So we only allow the tests to run when installed with PEAR or with composer
$installed = false;
if ('@' . 'package_version@' !== '2.2.2') {
// Installed with PEAR: we should be on the include path, use own autoloader
require_once 'HTML/QuickForm2/Loader.php';
spl_autoload_register(['HTML_QuickForm2_Loader', 'autoload']);
$installed = true;
} else {
foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
if (file_exists($file)) {
require_once $file;
$installed = true;
break;
}
}
}
if (!$installed) {
fwrite(STDERR,
'As HTML_QuickForm2 has required dependencies, tests should be run either' . PHP_EOL . PHP_EOL .
' - after installation of package with PEAR:' . PHP_EOL .
' php ./pear-package-helper.php' . PHP_EOL .
' pear install ./.pear-package/package.xml' . PHP_EOL . PHP_EOL .
' - or setting up its dependencies using Composer:' . PHP_EOL .
' composer install' . PHP_EOL . PHP_EOL
);
die(1);
}
if (strpos($_SERVER['argv'][0], 'phpunit') === false
&& !class_exists('PHPUnit_Framework_TestCase', true)
) {
require_once 'PHPUnit/Autoload.php';
}
// Monkey-patching of phpunit/phpunit-mock-objects package to prevent errors like
// "Function ReflectionType::__toString() is deprecated"
// Inspired by https://github.com/lavary/crunz/commit/8ef1370aa47009fd1945fb73f0414bd88634ada2
if (PHP_VERSION_ID >= 50600 // probably have PHPUnit 5.7
&& !class_exists('PHPUnit_Framework_MockObject_Generator', false) // not too late to patch?
&& is_dir($mock = dirname(__DIR__) . '/vendor/phpunit/phpunit-mock-objects') // have mocks in local vendor dir?
) {
$source = __DIR__ . '/MockObjectGenerator.' . (PHP_VERSION_ID >= 70100 ? 'patched' : 'original') . '.php';
file_put_contents(
$mock . '/src/Framework/MockObject/Generator.php',
file_get_contents($source)
);
}
?>