Added Unit Tests and fixed bugs with Autoloader
This commit is contained in:
parent
fa77c4f159
commit
50a9ab52b0
|
|
@ -7,6 +7,7 @@ Desktop.ini
|
|||
.idea
|
||||
phpunit.xml
|
||||
composer.lock
|
||||
composer.phar
|
||||
vendor
|
||||
/.settings
|
||||
/.buildpath
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@
|
|||
"require": {
|
||||
"php": ">=5.2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "3.7.28"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"PHPWord": "src/"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="test/bootstrap.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false">
|
||||
<testsuites>
|
||||
<testsuite name="PHPWord Test Suite">
|
||||
<directory>./test/PHPWord/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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 = PHPWORD_BASE_PATH . str_replace('_', '/', $strObjectName) . '.php';
|
||||
|
||||
if ((file_exists($strObjectFilePath) === false) || (is_readable($strObjectFilePath) === false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$strObjectFilePath = __DIR__ . '/../' . str_replace('_', '/', $strObjectName) . '.php';
|
||||
if (file_exists($strObjectFilePath) && is_readable($strObjectFilePath)) {
|
||||
require_once $strObjectFilePath;
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
namespace PHPWord\Tests;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use PHPWord_Autoloader;
|
||||
|
||||
class AutoloaderTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testAutoload()
|
||||
{
|
||||
$this->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');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . "/../src/PHPWord/Autoloader.php";
|
||||
PHPWord_Autoloader::register();
|
||||
Loading…
Reference in New Issue