Added Unit Tests and fixed bugs with Autoloader
This commit is contained in:
parent
fa77c4f159
commit
50a9ab52b0
|
|
@ -7,6 +7,7 @@ Desktop.ini
|
||||||
.idea
|
.idea
|
||||||
phpunit.xml
|
phpunit.xml
|
||||||
composer.lock
|
composer.lock
|
||||||
|
composer.phar
|
||||||
vendor
|
vendor
|
||||||
/.settings
|
/.settings
|
||||||
/.buildpath
|
/.buildpath
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.2.0"
|
"php": ">=5.2.0"
|
||||||
},
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "3.7.28"
|
||||||
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
"PHPWord": "src/"
|
"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 */
|
/** PHPWORD_BASE_PATH */
|
||||||
if (!defined('PHPWORD_BASE_PATH')) {
|
if (!defined('PHPWORD_BASE_PATH')) {
|
||||||
define('PHPWORD_BASE_PATH', dirname(__FILE__) . '/');
|
define('PHPWORD_BASE_PATH', dirname(__FILE__) . '/');
|
||||||
require PHPWORD_BASE_PATH . 'PHPWord/Autoloader.php';
|
require_once PHPWORD_BASE_PATH . 'PHPWord/Autoloader.php';
|
||||||
PHPWord_Autoloader::Register();
|
PHPWord_Autoloader::register();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@
|
||||||
* @version Beta 0.6.3, 08.07.2011
|
* @version Beta 0.6.3, 08.07.2011
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
define('PHPWORD_BASE_PATH', realpath(__DIR__ . '/../'));
|
||||||
|
|
||||||
class PHPWord_Autoloader
|
class PHPWord_Autoloader
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
@ -45,17 +47,12 @@ class PHPWord_Autoloader
|
||||||
*/
|
*/
|
||||||
public static function load($strObjectName)
|
public static function load($strObjectName)
|
||||||
{
|
{
|
||||||
if ((class_exists($strObjectName)) || (strpos($strObjectName, 'PHPWord') === false)) {
|
$strObjectFilePath = __DIR__ . '/../' . str_replace('_', '/', $strObjectName) . '.php';
|
||||||
return null;
|
if (file_exists($strObjectFilePath) && is_readable($strObjectFilePath)) {
|
||||||
}
|
|
||||||
|
|
||||||
$strObjectFilePath = PHPWORD_BASE_PATH . str_replace('_', '/', $strObjectName) . '.php';
|
|
||||||
|
|
||||||
if ((file_exists($strObjectFilePath) === false) || (is_readable($strObjectFilePath) === false)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once $strObjectFilePath;
|
require_once $strObjectFilePath;
|
||||||
return true;
|
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