diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 59c7e38a..b3897a83 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -10,7 +10,7 @@ syntaxCheck="false"> - ./tests/PhpWord/ + ./test/PhpWord/ diff --git a/src/PhpWord/Autoloader.php b/src/PhpWord/Autoloader.php index 554d7cb1..b2012f9f 100644 --- a/src/PhpWord/Autoloader.php +++ b/src/PhpWord/Autoloader.php @@ -25,10 +25,6 @@ namespace PhpOffice\PhpWord; -if (!\defined('PHPWORD_BASE_DIR')) { - \define('PHPWORD_BASE_DIR', \realpath(__DIR__) . \DIRECTORY_SEPARATOR); -} - class Autoloader { const NAMESPACE_PREFIX = 'PhpOffice\\PhpWord\\'; @@ -38,27 +34,21 @@ class Autoloader */ public static function register() { - \spl_autoload_register(array(new self, 'autoload')); + spl_autoload_register(array(new self, 'autoload')); } /** - * @param string $fqClassName + * @param string $class */ - public static function autoload($fqClassName) + public static function autoload($class) { - $namespacePrefixLength = \strlen(self::NAMESPACE_PREFIX); - $className = \substr($fqClassName, $namespacePrefixLength); - - if (0 === \strncmp(self::NAMESPACE_PREFIX, $fqClassName, $namespacePrefixLength)) { - $fqFilename = \PHPWORD_BASE_DIR - . \str_replace('\\', \DIRECTORY_SEPARATOR, $className) - . '.php'; - - if (\file_exists($fqFilename)) { - require_once $fqFilename; - } else { - throw new \Exception("Could not instantiate class."); + $prefixLength = strlen(self::NAMESPACE_PREFIX); + if (0 === strncmp(self::NAMESPACE_PREFIX, $class, $prefixLength)) { + $file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength)); + $file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php'); + if (file_exists($file)) { + require_once $file; } } } -} +} \ No newline at end of file diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php index dd7d55d1..78002a9d 100644 --- a/src/PhpWord/PhpWord.php +++ b/src/PhpWord/PhpWord.php @@ -31,14 +31,6 @@ use PhpOffice\PhpWord\Section; use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Template; -// @codeCoverageIgnoreStart -if (!defined('PHPWORD_BASE_DIR')) { - define('PHPWORD_BASE_DIR', \realpath(__DIR__) . \DIRECTORY_SEPARATOR); - require \PHPWORD_BASE_DIR . 'Autoloader.php'; - \PhpOffice\PhpWord\Autoloader::register(); -} -// @codeCoverageIgnoreEnd - class PhpWord { const DEFAULT_FONT_COLOR = '000000'; // HEX diff --git a/src/PhpWord/Reader/Word2007.php b/src/PhpWord/Reader/Word2007.php index 634e1e76..645ba56c 100644 --- a/src/PhpWord/Reader/Word2007.php +++ b/src/PhpWord/Reader/Word2007.php @@ -30,11 +30,6 @@ use PhpOffice\PhpWord\DocumentProperties; use PhpOffice\PhpWord\Exceptions\Exception; use PhpOffice\PhpWord\Shared\File; -if (!defined('PHPWORD_BASE_DIR')) { - define('PHPWORD_BASE_DIR', \dirname(__FILE__) . '/../../'); - require(PHPWORD_BASE_DIR . 'Autoloader.php'); -} - class Word2007 extends AbstractReader implements IReader { /** diff --git a/src/PhpWord/Section.php b/src/PhpWord/Section.php index 32727d32..2f7212ad 100644 --- a/src/PhpWord/Section.php +++ b/src/PhpWord/Section.php @@ -240,7 +240,7 @@ class Section $ext = substr($ext, 0, -1); } - $iconSrc = \PHPWORD_BASE_DIR . '_staticDocParts/'; + $iconSrc = __DIR__ . '/_staticDocParts/'; if (!file_exists($iconSrc . '_' . $ext . '.png')) { $iconSrc = $iconSrc . '_default.png'; } else { diff --git a/src/PhpWord/Section/Table/Cell.php b/src/PhpWord/Section/Table/Cell.php index d94c2c4a..dc435e86 100755 --- a/src/PhpWord/Section/Table/Cell.php +++ b/src/PhpWord/Section/Table/Cell.php @@ -260,7 +260,7 @@ class Cell $ext = substr($ext, 0, -1); } - $iconSrc = \PHPWORD_BASE_DIR . '_staticDocParts/'; + $iconSrc = __DIR__ . '/../../_staticDocParts/'; if (!file_exists($iconSrc . '_' . $ext . '.png')) { $iconSrc = $iconSrc . '_default.png'; } else { diff --git a/src/PhpWord/Writer/Word2007.php b/src/PhpWord/Writer/Word2007.php index 61a8bc12..82f14eca 100755 --- a/src/PhpWord/Writer/Word2007.php +++ b/src/PhpWord/Writer/Word2007.php @@ -187,11 +187,11 @@ class Word2007 implements IWriter $objZip->addFromString('word/styles.xml', $this->getWriterPart('styles')->writeStyles($this->_document)); // Write static files - $objZip->addFile(\PHPWORD_BASE_DIR . '_staticDocParts/numbering.xml', 'word/numbering.xml'); - $objZip->addFile(\PHPWORD_BASE_DIR . '_staticDocParts/settings.xml', 'word/settings.xml'); - $objZip->addFile(\PHPWORD_BASE_DIR . '_staticDocParts/theme1.xml', 'word/theme/theme1.xml'); - $objZip->addFile(\PHPWORD_BASE_DIR . '_staticDocParts/webSettings.xml', 'word/webSettings.xml'); - $objZip->addFile(\PHPWORD_BASE_DIR . '_staticDocParts/fontTable.xml', 'word/fontTable.xml'); + $objZip->addFile(__DIR__ . '/../_staticDocParts/numbering.xml', 'word/numbering.xml'); + $objZip->addFile(__DIR__ . '/../_staticDocParts/settings.xml', 'word/settings.xml'); + $objZip->addFile(__DIR__ . '/../_staticDocParts/theme1.xml', 'word/theme/theme1.xml'); + $objZip->addFile(__DIR__ . '/../_staticDocParts/webSettings.xml', 'word/webSettings.xml'); + $objZip->addFile(__DIR__ . '/../_staticDocParts/fontTable.xml', 'word/fontTable.xml'); // Close file diff --git a/test/PhpWord/Tests/_includes/TestHelperDOCX.php b/test/PhpWord/Tests/_includes/TestHelperDOCX.php index ff40c15f..969f6c65 100644 --- a/test/PhpWord/Tests/_includes/TestHelperDOCX.php +++ b/test/PhpWord/Tests/_includes/TestHelperDOCX.php @@ -10,8 +10,9 @@ class TestHelperDOCX static protected $file; /** - * @param \PhpOffice\PhpWord\PhpWord $phpWord - * @return \PhpWord\Tests\XmlDocument + * @param \PhpOffice\PhpWord\PhpWord $phpWord + * @param string $writerName + * @return \PhpOffice\PhpWord\Tests\XmlDocument */ public static function getDocument(PhpWord $phpWord, $writerName = 'Word2007') { @@ -68,4 +69,4 @@ class TestHelperDOCX { return self::$file; } -} +} \ No newline at end of file diff --git a/test/PhpWord/Tests/_includes/XmlDocument.php b/test/PhpWord/Tests/_includes/XmlDocument.php index e868df5f..5f84c997 100644 --- a/test/PhpWord/Tests/_includes/XmlDocument.php +++ b/test/PhpWord/Tests/_includes/XmlDocument.php @@ -110,4 +110,4 @@ class XmlDocument $nodeList = $this->getNodeList($path, $file); return !($nodeList->length == 0); } -} +} \ No newline at end of file diff --git a/test/bootstrap.php b/test/bootstrap.php index ad2eec3d..172cf9e8 100755 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -1,14 +1,23 @@