mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-04 03:38:42 +00:00
fix tests
This commit is contained in:
parent
ea2ba6aa7d
commit
397696c122
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 8.1
|
* PHP Version 8.1
|
||||||
*
|
*
|
||||||
* @package Tests\PHPUnit
|
* @package tests
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 2.0
|
* @license OMS License 2.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -12,26 +12,61 @@
|
||||||
*/
|
*/
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Tests\PHPUnit;
|
namespace tests;
|
||||||
|
|
||||||
\spl_autoload_register('\Tests\PHPUnit\Autoloader::defaultAutoloader');
|
\spl_autoload_register('\tests\Autoloader::defaultAutoloader');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Autoloader class.
|
* Autoloader class.
|
||||||
*
|
*
|
||||||
* @package Tests\PHPUnit
|
* @package tests\PHPUnit
|
||||||
* @license OMS License 2.0
|
* @license OMS License 2.0
|
||||||
* @link https://jingga.app
|
* @link https://jingga.app
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class Autoloader
|
class Autoloader
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Base paths for autoloading
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private static $paths = [
|
||||||
|
__DIR__ . '/../',
|
||||||
|
__DIR__ . '/../../',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add base path for autoloading
|
||||||
|
*
|
||||||
|
* @param string $path Absolute base path with / at the end
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function addPath(string $path) : void
|
||||||
|
{
|
||||||
|
self::$paths[] = \rtrim($path, '/\\') . '/';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loading classes by namespace + class name.
|
* Loading classes by namespace + class name.
|
||||||
*
|
*
|
||||||
* @param string $class Class path
|
* @param string $class Class path
|
||||||
*
|
*
|
||||||
* @example Autoloader::defaultAutoloader('\Tests\PHPUnit\Autoloader') // void
|
* @example Autoloader::defaultAutoloader('\phpOMS\Autoloader') // void
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
|
|
@ -39,33 +74,29 @@ class Autoloader
|
||||||
*/
|
*/
|
||||||
public static function defaultAutoloader(string $class) : void
|
public static function defaultAutoloader(string $class) : void
|
||||||
{
|
{
|
||||||
$class = \ltrim($class, '\\');
|
$class = \ltrim($class, '\\');
|
||||||
$class = \strtr($class, '_\\', '//');
|
$class = \strtr($class, '_\\', '//');
|
||||||
|
$class2 = $class;
|
||||||
|
|
||||||
if (!\is_file($path = __DIR__ . '/../../' . $class . '.php')) {
|
$pos = \stripos($class, '/');
|
||||||
return;
|
if ($pos !== false) {
|
||||||
|
$pos = \stripos($class, '/', $pos + 1);
|
||||||
|
|
||||||
|
if ($pos !== false) {
|
||||||
|
$class2 = \substr($class, $pos + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @noinspection PhpIncludeInspection */
|
foreach (self::$paths as $path) {
|
||||||
include_once $path;
|
if (\is_file($file = $path . $class2 . '.php')) {
|
||||||
}
|
include_once $file;
|
||||||
|
|
||||||
/**
|
return;
|
||||||
* Check if class exists.
|
} elseif (\is_file($file = $path . $class . '.php')) {
|
||||||
*
|
include_once $file;
|
||||||
* @param string $class Class path
|
|
||||||
*
|
|
||||||
* @example Autoloader::exists('\Tests\PHPUnit\Autoloader') // true
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public static function exists(string $class) : bool
|
|
||||||
{
|
|
||||||
$class = \ltrim($class, '\\');
|
|
||||||
$class = \strtr($class, '_\\', '//');
|
|
||||||
|
|
||||||
return \is_file(__DIR__ . '/../../' . $class . '.php');
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user