Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix autoloading for composer use case without breaking pear #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
{
"name": "horde/test",
"description": "Unit testing library",
"type": "library",
"type": "horde-library",
"homepage": "https://www.horde.org/libraries/Horde_Test",
"license": "LGPL-2.1",
"authors": [
{
"name": "Chuck Hagenbuch",
"email": "chuck@horde.org",
"name": "Jan Schneider",
"email": "jan@horde.org",
"role": "lead"
},
{
"name": "Jan Schneider",
"email": "jan@horde.org",
"name": "Chuck Hagenbuch",
"email": "chuck@horde.org",
"role": "lead"
}
],
"version": "2.6.4",
"time": "2017-11-11",
"time": "2019-05-02",
"repositories": [
{
"type": "pear",
"url": "https://pear.horde.org"
"type": "composer",
"url": "https://horde-satis.maintaina.com"
}
],
"require": {
"horde/horde-installer-plugin": "dev-master",
"php": "^5.3.3 || ^7",
"pear-pear.horde.org/Horde_Support": "^2",
"pear-pear.horde.org/Horde_Util": "^2"
"horde/support": "dev-master",
"horde/util": "dev-master"
},
"suggest": {
"pear-pear.horde.org/Horde_Cli": "^2",
"pear-pear.horde.org/Horde_Log": "^2",
"horde/cli": "^2",
"horde/log": "^2",
"ext-dom": "*",
"ext-json": "*"
},
"replace": {
"pear-pear.horde.org/Horde_Test": "2.*",
"pear-horde/Horde_Test": "2.*"
},
"autoload": {
"psr-0": {
"Horde_Test": "lib/"
}
}
}
}
17 changes: 16 additions & 1 deletion doc/Horde/Test/template/packagetest/AllTests.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<?php
require_once 'Horde/Test/AllTests.php';
$rootDir = dirname(__FILE__);

// composer case: search for root dir recursively
// Load composer autoloader if found
while ($rootDir != '/')
{
if (file_exists("$rootDir/vendor/autoload.php")) {
require_once "$rootDir/vendor/autoload.php";
break;
}
$rootDir = dirname($rootDir);
}
// otherwise try classic PEAR/include path loading
if ($rootDir == '/') {
require_once 'Horde/Test/AllTests.php';
}
Horde_Test_AllTests::init(__FILE__)->run();
4 changes: 3 additions & 1 deletion doc/Horde/Test/template/packagetest/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php
require_once 'Horde/Test/Bootstrap.php';
if (!class_exists('Horde_Test_Bootstrap')) {
require_once 'Horde/Test/Bootstrap.php';
}
Horde_Test_Bootstrap::bootstrap(dirname(__FILE__));
7 changes: 5 additions & 2 deletions lib/Horde/Test/AllTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ public function setup()
$base . PATH_SEPARATOR . $base . '/../lib' . PATH_SEPARATOR . get_include_path()
);
}

require_once 'Horde/Test/Bootstrap.php';
// In case of composer, this relative path won't work and the external
// autoloader should deal with it.
if (!class_exists('Horde_Test_Bootstrap')) {
require_once 'Horde/Test/Bootstrap.php';
}
Horde_Test_Bootstrap::bootstrap($this->_dir);

if (file_exists($this->_dir . '/Autoload.php')) {
Expand Down
6 changes: 5 additions & 1 deletion lib/Horde/Test/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ public static function bootstrap($dir, $no_autoload = false)
$base . PATH_SEPARATOR . $base . '/../lib' . PATH_SEPARATOR . get_include_path()
);
}
require_once 'Horde/Test/Autoload.php';
// In case of composer, this should already be autoloaded by the
// caller and the relative path would not work
if (!class_exists('Horde_Test_Autoload')) {
require_once 'Horde/Test/Autoload.php';
}
Horde_Test_Autoload::init();
}

Expand Down