diff --git a/.gitignore b/.gitignore index 4553eaa2..23e11e8e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ Desktop.ini .idea phpunit.xml composer.lock +composer.phar vendor /.settings /.buildpath diff --git a/composer.json b/composer.json index 3d111441..80cb3484 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,9 @@ "require": { "php": ">=5.2.0" }, + "require-dev": { + "phpunit/phpunit": "3.7.28" + }, "autoload": { "psr-0": { "PHPWord": "src/" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e69de29b..edb893a7 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -0,0 +1,16 @@ + + + + ./test/PHPWord/ + + + \ No newline at end of file diff --git a/src/PHPWord.php b/src/PHPWord.php index 6ff77a0a..78dec75d 100644 --- a/src/PHPWord.php +++ b/src/PHPWord.php @@ -28,8 +28,8 @@ /** PHPWORD_BASE_PATH */ if (!defined('PHPWORD_BASE_PATH')) { define('PHPWORD_BASE_PATH', dirname(__FILE__) . '/'); - require PHPWORD_BASE_PATH . 'PHPWord/Autoloader.php'; - PHPWord_Autoloader::Register(); + require_once PHPWORD_BASE_PATH . 'PHPWord/Autoloader.php'; + PHPWord_Autoloader::register(); } diff --git a/src/PHPWord/Autoloader.php b/src/PHPWord/Autoloader.php index dc48ef91..7c39830c 100644 --- a/src/PHPWord/Autoloader.php +++ b/src/PHPWord/Autoloader.php @@ -25,6 +25,8 @@ * @version Beta 0.6.3, 08.07.2011 */ +define('PHPWORD_BASE_PATH', realpath(__DIR__ . '/../')); + class PHPWord_Autoloader { /** @@ -45,17 +47,12 @@ class PHPWord_Autoloader */ public static function load($strObjectName) { - if ((class_exists($strObjectName)) || (strpos($strObjectName, 'PHPWord') === false)) { - return null; + $strObjectFilePath = __DIR__ . '/../' . str_replace('_', '/', $strObjectName) . '.php'; + if (file_exists($strObjectFilePath) && is_readable($strObjectFilePath)) { + require_once $strObjectFilePath; + return true; } - $strObjectFilePath = PHPWORD_BASE_PATH . str_replace('_', '/', $strObjectName) . '.php'; - - if ((file_exists($strObjectFilePath) === false) || (is_readable($strObjectFilePath) === false)) { - return null; - } - - require_once $strObjectFilePath; - return true; + return null; } } \ No newline at end of file diff --git a/test/PHPWord/Tests/AutoloaderTest.php b/test/PHPWord/Tests/AutoloaderTest.php new file mode 100644 index 00000000..cdfcf68e --- /dev/null +++ b/test/PHPWord/Tests/AutoloaderTest.php @@ -0,0 +1,14 @@ +assertNull(PHPWord_Autoloader::load('Foo'), 'PHPWord_Autoloader::load() is trying to load classes outside of the PHPWord namespace'); + $this->assertTrue(PHPWord_Autoloader::load('PHPWord'), 'PHPWord_Autoloader::load() failed to autoload the PHPWord class'); + } +} \ No newline at end of file diff --git a/test/PHPWord/Tests/_files/.gitkeep b/test/PHPWord/Tests/_files/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/bootstrap.php b/test/bootstrap.php new file mode 100644 index 00000000..564f3f76 --- /dev/null +++ b/test/bootstrap.php @@ -0,0 +1,4 @@ +