Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Autoloader fixes and initial unit test structure

  • Loading branch information...
commit 357b4ff68943ac826008b71e9b8b6595d2f52a8c 1 parent a0d5f4c
@MarkBaker MarkBaker authored
View
2  .gitignore
@@ -1,3 +1,3 @@
-
+unitTests/codeCoverage
*.project
*.buildpath
View
34 Classes/PHPPowerPoint/Autoloader.php
@@ -25,16 +25,45 @@
* @version ##VERSION##, ##DATE##
*/
+PHPPowerPoint_Autoloader::Register();
+// check mbstring.func_overload
+if (ini_get('mbstring.func_overload') & 2) {
+ throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
+}
+
+
+/**
+ * PHPPowerPoint_Autoloader
+ *
+ * @category PHPPowerPoint
+ * @package PHPPowerPoint
+ * @copyright Copyright (c) 2006 - 2012 PHPPowerPoint (https://github.com/Progi1984/PHPPowerPoint)
+ */
class PHPPowerPoint_Autoloader
{
+ /**
+ * Register the Autoloader with SPL
+ *
+ */
public static function Register() {
+ if (function_exists('__autoload')) {
+ // Register any existing autoloader function with SPL, so we don't get any clashes
+ spl_autoload_register('__autoload');
+ }
+ // Register ourselves with SPL
return spl_autoload_register(array('PHPPowerPoint_Autoloader', 'Load'));
} // function Register()
+ /**
+ * Autoload a class identified by name
+ *
+ * @param string $pClassName Name of the object to load
+ */
public static function Load($pObjectName){
if ((class_exists($pObjectName)) || (strpos($pObjectName, 'PHPPowerPoint') === False)) {
- return false;
+ // Either already loaded, or not a PHPPowerPoint class request
+ return FALSE;
}
$pObjectFilePath = PHPPOWERPOINT_ROOT.
@@ -42,7 +71,8 @@ public static function Load($pObjectName){
'.php';
if ((file_exists($pObjectFilePath) === false) || (is_readable($pObjectFilePath) === false)) {
- return false;
+ // Can't load
+ return FALSE;
}
require($pObjectFilePath);
View
56 unitTests/PHPPowerPoint/AutoloaderTest.php
@@ -0,0 +1,56 @@
+<?php
+
+
+class AutoloaderTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp()
+ {
+ if (!defined('PHPPOWERPOINT_ROOT'))
+ {
+ define('PHPPOWERPOINT_ROOT', APPLICATION_PATH . '/');
+ }
+ require_once(PHPPOWERPOINT_ROOT . 'PHPPowerPoint/Autoloader.php');
+ }
+
+ public function testAutoloaderNonPHPPowerPointClass()
+ {
+ $className = 'InvalidClass';
+
+ $result = PHPPowerPoint_Autoloader::Load($className);
+ // Must return a boolean...
+ $this->assertTrue(is_bool($result));
+ // ... indicating failure
+ $this->assertFalse($result);
+ }
+
+ public function testAutoloaderInvalidPHPPowerPointClass()
+ {
+ $className = 'PHPPowerPoint_Invalid_Class';
+
+ $result = PHPPowerPoint_Autoloader::Load($className);
+ // Must return a boolean...
+ $this->assertTrue(is_bool($result));
+ // ... indicating failure
+ $this->assertFalse($result);
+ }
+
+ public function testAutoloadValidPHPPowerPointClass()
+ {
+ $className = 'PHPPowerPoint_IOFactory';
+
+ $result = PHPPowerPoint_Autoloader::Load($className);
+ // Check that class has been loaded
+ $this->assertTrue(class_exists($className));
+ }
+
+ public function testAutoloadInstantiateSuccess()
+ {
+ $result = new PHPPowerPoint(1,2,3);
+ // Must return an object...
+ $this->assertTrue(is_object($result));
+ // ... of the correct type
+ $this->assertTrue(is_a($result,'PHPPowerPoint'));
+ }
+
+}
View
44 unitTests/bootstrap.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * $Id: bootstrap.php 2892 2011-08-14 15:11:50Z markbaker@PHPPowerPoint.net $
+ *
+ * @copyright Copyright (C) 2011-2012 PHPPowerPoint. All rights reserved.
+ * @package PHPPowerPoint
+ * @subpackage PHPPowerPoint Unit Tests
+ * @author Mark Baker
+ */
+
+// PHP 5.3 Compat
+date_default_timezone_set('Europe/London');
+
+// Define path to application directory
+defined('APPLICATION_PATH')
+ || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../Classes'));
+
+// Define path to application tests directory
+defined('APPLICATION_TESTS_PATH')
+ || define('APPLICATION_TESTS_PATH', realpath(dirname(__FILE__) ));
+
+// Define application environment
+defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'ci');
+
+// Ensure library/ is on include_path
+set_include_path(implode(PATH_SEPARATOR, array(
+ realpath(APPLICATION_PATH . '/../Classes'),
+ './',
+ get_include_path(),
+)));
+
+
+/**
+ * @todo Sort out xdebug in vagrant so that this works in all sandboxes
+ * For now, it is safer to test for it rather then remove it.
+ */
+echo "PHPPowerPoint tests beginning\n";
+
+if(extension_loaded('xdebug')) {
+ echo "Xdebug extension loaded and running\n";
+ xdebug_enable();
+} else {
+ echo 'Xdebug not found, you should run the following at the command line: echo "zend_extension=/usr/lib64/php/modules/xdebug.so" > /etc/php.d/xdebug.ini' . "\n";
+}
View
35 unitTests/phpunit.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit bootstrap="./bootstrap.php"
+ backupGlobals="true"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ syntaxCheck="true"
+ verbose="true"
+ strict="true"
+ stopOnError="false"
+ stopOnFailure="false"
+ stopOnIncomplete="false"
+ stopOnSkipped="false">
+ <php>
+ <ini name="memory_limit" value="2048M"/>
+ </php>
+ <testsuite name="PHPPowerPoint Unit Test Suite">
+ <directory suffix="Test.php">./PHPPowerPoint</directory>
+ </testsuite>
+ <filter>
+ <whitelist>
+ <directory suffix=".php">../Classes</directory>
+ </whitelist>
+ </filter>
+ <logging>
+ <log type="coverage-html" target="./codeCoverage" charset="UTF-8"
+ yui="true" highlight="false"
+ lowUpperBound="35" highLowerBound="70"/>
+ <log type="coverage-clover" target="./codeCoverage/codeCoverage.xml"/>
+ <log type="metrics-xml" target="./metrics/metrics.xml"/>
+ <log type="test-xml" target="./testResults/logfile.xml" logIncompleteSkipped="false"/>
+ </logging>
+</phpunit>
Please sign in to comment.
Something went wrong with that request. Please try again.