/** * Autoload */ public function testAutoload() { $declared = get_declared_classes(); $declaredCount = count($declared); Autoloader::autoload('Foo'); $this->assertEquals($declaredCount, count(get_declared_classes()), 'PhpOffice\\PhpProject\\Autoloader::autoload() is trying to load ' . 'classes outside of the PhpOffice\\PhpProject namespace'); }
<?php /** * Header file */ use PhpOffice\PhpProject\Autoloader; use PhpOffice\PhpProject\IOFactory; error_reporting(E_ALL); define('CLI', PHP_SAPI == 'cli' ? true : false); define('EOL', CLI ? PHP_EOL : '<br />'); define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php')); define('IS_INDEX', SCRIPT_FILENAME == 'index'); require_once __DIR__ . '/../src/PhpProject/Autoloader.php'; Autoloader::register(); // Set writers $writers = array('GanttProject' => 'gan', 'MsProjectMPX' => 'mpx'); // Return to the caller script when runs by CLI if (CLI) { return; } // Set titles and names $pageHeading = str_replace('_', ' ', SCRIPT_FILENAME); $pageTitle = IS_INDEX ? 'Welcome to ' : "{$pageHeading} - "; $pageTitle .= 'PHPProject'; $pageHeading = IS_INDEX ? '' : "<h1>{$pageHeading}</h1>"; // Populate samples $files = ''; if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if (preg_match('/^Sample_\\d+_/', $file)) { $name = str_replace('_', ' ', preg_replace('/(Sample_|\\.php)/', '', $file));
date_default_timezone_set('UTC'); // defining base dir for tests if (!defined('PHPPROJECT_TESTS_BASE_DIR')) { define('PHPPROJECT_TESTS_BASE_DIR', realpath(__DIR__)); } $vendor = realpath(__DIR__ . '/../vendor'); if (file_exists($vendor . "/autoload.php")) { require $vendor . "/autoload.php"; } else { $vendor = realpath(__DIR__ . '/../../../'); if (file_exists($vendor . "/autoload.php")) { require $vendor . "/autoload.php"; } else { throw new Exception("Unable to load dependencies"); } } spl_autoload_register(function ($class) { $class = ltrim($class, '\\'); $prefix = 'PhpOffice\\PhpProject\\Tests'; if (strpos($class, $prefix) === 0) { $class = str_replace('\\', DIRECTORY_SEPARATOR, $class); $class = join(DIRECTORY_SEPARATOR, array('PhpProject', 'Tests', '_includes')) . substr($class, strlen($prefix)); $file = __DIR__ . DIRECTORY_SEPARATOR . $class . '.php'; if (file_exists($file)) { require_once $file; } } }); require_once __DIR__ . "/../src/PhpProject/Autoloader.php"; \PhpOffice\PhpProject\Autoloader::register();