/** * Create or grab a reference to a static xPDO/modX instance. * * The instances can be reused by multiple tests and test suites. * * @param string $class A fixture class to get an instance of. * @param string $name A unique identifier for the fixture. * @param boolean $new * @param array $options An array of configuration options for the fixture. * @return object|null An instance of the specified fixture class or null on failure. */ public static function &getFixture($class, $name, $new = false, array $options = array()) { if (!$new && array_key_exists($name, self::$fixtures) && self::$fixtures[$name] instanceof $class) { $fixture =& self::$fixtures[$name]; } else { $properties = array(); include_once dirname(dirname(dirname(__FILE__))) . '/core/model/modx/modx.class.php'; include dirname(__FILE__) . '/properties.inc.php'; self::$properties = $properties; if (array_key_exists('debug', self::$properties)) { self::$debug = (bool) self::$properties['debug']; } $fixture = null; $driver = self::$properties['xpdo_driver']; switch ($class) { case 'modX': if (!defined('MODX_REQP')) { define('MODX_REQP', false); } if (!defined('MODX_CONFIG_KEY')) { define('MODX_CONFIG_KEY', array_key_exists('config_key', self::$properties) ? self::$properties['config_key'] : 'test'); } $fixture = new modX(null, self::$properties["{$driver}_array_options"]); if ($fixture instanceof modX) { $logLevel = array_key_exists('logLevel', self::$properties) ? self::$properties['logLevel'] : modX::LOG_LEVEL_WARN; $logTarget = array_key_exists('logTarget', self::$properties) ? self::$properties['logTarget'] : (XPDO_CLI_MODE ? 'ECHO' : 'HTML'); $fixture->setLogLevel($logLevel); $fixture->setLogTarget($logTarget); if (!empty(self::$debug)) { $fixture->setDebug(self::$properties['debug']); } $fixture->initialize(self::$properties['context']); $fixture->user = $fixture->newObject('modUser'); $fixture->user->set('id', $fixture->getOption('modx.test.user.id', null, 1)); $fixture->user->set('username', $fixture->getOption('modx.test.user.username', null, 'test')); $fixture->getRequest(); $fixture->getParser(); $fixture->request->loadErrorHandler(); } break; case 'xPDO': $fixture = new xPDO(self::$properties["{$driver}_string_dsn_test"], self::$properties["{$driver}_string_username"], self::$properties["{$driver}_string_password"], self::$properties["{$driver}_array_options"], self::$properties["{$driver}_array_driverOptions"]); if ($fixture instanceof xPDO) { $logLevel = array_key_exists('logLevel', self::$properties) ? self::$properties['logLevel'] : xPDO::LOG_LEVEL_WARN; $logTarget = array_key_exists('logTarget', self::$properties) ? self::$properties['logTarget'] : (XPDO_CLI_MODE ? 'ECHO' : 'HTML'); $fixture->setLogLevel($logLevel); $fixture->setLogTarget($logTarget); if (!empty(self::$debug)) { $fixture->setDebug(self::$properties['debug']); } } break; default: $fixture = new $class($options); break; } if ($fixture !== null && $fixture instanceof $class) { self::$fixtures[$name] = $fixture; } else { die("Error setting fixture {$name} of expected class {$class}."); } } return $fixture; }
<?php $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $tstart = $mtime; $properties = array(); include_once dirname(dirname(dirname(__FILE__))) . '/xpdo/xpdo.class.php'; require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.core.php'; require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/_build/build.properties.php'; foreach (array('mysql', 'sqlsrv') as $driver) { $xpdo = new xPDO($properties["{$driver}_string_dsn_nodb"], $properties["{$driver}_string_username"], $properties["{$driver}_string_password"], $properties["{$driver}_array_options"], $properties["{$driver}_array_driverOptions"]); $xpdo->setPackage('modx', dirname(XPDO_CORE_PATH) . '/model/'); $xpdo->setDebug(true); $manager = $xpdo->getManager(); $generator = $manager->getGenerator(); $generator->classTemplate = <<<EOD <?php /** * [+phpdoc-package+] * [+phpdoc-subpackage+] */ /** * [+phpdoc-package+] * [+phpdoc-subpackage+] */ class [+class+] extends [+extends+] { } EOD; $generator->platformTemplate = <<<EOD <?php
<p>Adjust the permissions and try again.</p>', $d)); exit; } } if ($verbose) { print_msg(sprintf('<br/><strong>Ok:</strong> The necessary directories exist and have the correct permissions inside of <br/> <code>%s</code>', $package_dir)); } // Delete/regenerate map files? if (file_exists($xml_schema_file) && !$regenerate_schema && $verbose) { print_msg(sprintf('<br/><strong>Ok:</strong> Using existing XML schema file:<br/><code>%s</code>', $xml_schema_file)); } $xpdo = new xPDO("mysql:host={$database_server};dbname={$dbase}", $database_user, $database_password, $table_prefix); // Set the package name and root path of that package $xpdo->setPackage($package_name, $package_dir, $package_dir); $xpdo->setDebug($debug); $manager = $xpdo->getManager(); $generator = $manager->getGenerator(); //Use this to create an XML schema from an existing database if ($regenerate_schema) { $xml = $generator->writeSchema($xml_schema_file, $package_name, 'xPDOObject', $table_prefix, $restrict_prefix); if ($verbose) { print_msg(sprintf('<br/><strong>Ok:</strong> XML schema file generated: <code>%s</code>', $xml_schema_file)); } } // Use this to generate classes and maps from your schema if ($regenerate_classes) { print_msg('<br/>Attempting to remove/regenerate class files...'); delete_class_files($class_dir); delete_class_files($mysql_class_dir); }
/** * Sets the debugging features of the modX instance. * * @param boolean|int $debug Boolean or bitwise integer describing the * debug state and/or PHP error reporting level. * @param boolean $stopOnNotice Indicates if processing should stop when * encountering PHP errors of type E_NOTICE. * @return boolean|int The previous value. */ public function setDebug($debug = true, $stopOnNotice = false) { $oldValue = $this->getDebug(); if ($debug === true) { error_reporting(-1); parent::setDebug(true); } elseif ($debug === false) { error_reporting(0); parent::setDebug(false); } else { error_reporting(intval($debug)); parent::setDebug(intval($debug)); } $this->stopOnNotice = $stopOnNotice; return $oldValue; }