mirror of
https://github.com/retailcrm/Fetch.git
synced 2024-11-24 20:16:03 +03:00
Updated autoloader to support test cases, and bootstrapper to support composer autoloader
This commit is contained in:
parent
e6eb65fbd5
commit
bcf57ce903
14
autoload.php
14
autoload.php
@ -9,11 +9,17 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
spl_autoload_register(function($class)
|
spl_autoload_register(function($class) {
|
||||||
{
|
$base = '/src/';
|
||||||
$file = __DIR__.'/src/'.strtr($class, '\\', '/').'.php';
|
|
||||||
|
if (strpos($class, 'Fetch\Test') === 0) {
|
||||||
|
$base = '/tests/';
|
||||||
|
}
|
||||||
|
|
||||||
|
$file = __DIR__.$base.strtr($class, '\\', '/').'.php';
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
require $file;
|
require $file;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
@ -13,18 +13,17 @@ define('TESTING', true);
|
|||||||
|
|
||||||
error_reporting(-1);
|
error_reporting(-1);
|
||||||
|
|
||||||
spl_autoload_register(function($class) {
|
$filename = __DIR__ .'/../vendor/autoload.php';
|
||||||
if (0 === strpos($class, 'Fetch\\Test\\')) {
|
|
||||||
$file = __DIR__ . '/../tests/' . str_replace('\\', '/', $class) . '.php';
|
if (!file_exists($filename)) {
|
||||||
if (file_exists($file)) {
|
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" . PHP_EOL;
|
||||||
require_once $file;
|
echo " You need to execute `composer install` before running the tests. " . PHP_EOL;
|
||||||
return true;
|
echo " Vendors are required for complete test execution. " . PHP_EOL;
|
||||||
}
|
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" . PHP_EOL . PHP_EOL;
|
||||||
} elseif (0 === strpos($class, 'Fetch\\')) {
|
$filename = __DIR__ .'/../autoload.php';
|
||||||
$file = __DIR__ . '/../src/' . str_replace('\\', '/', $class) . '.php';
|
require_once $filename;
|
||||||
if (file_exists($file)) {
|
}else{
|
||||||
require_once $file;
|
$loader = require_once $filename;
|
||||||
return true;
|
$loader->add('Fetch\\Test', __DIR__);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
Loading…
Reference in New Issue
Block a user