37 if (!file_exists($configPath) || is_file($configPath)) {
38 throw new \Exception(
'Configuration path '.$configPath.
' is not a directory. '.
39 'Did you forget to generate code from the model?');
48 $configuration->addConfiguration(
'config.ini');
49 $configuration->addConfiguration(
'test.ini');
66 $types = $persistenceFacade->getKnownTypes();
67 $mapper = $persistenceFacade->getMapper($types[0]);
68 $pdo = $mapper->getConnection()->getConnection();
71 $params = $mapper->getConnectionParams();
72 if ($params[
'dbType'] ==
'sqlite') {
73 $numTables = $pdo->query(
'SELECT count(*) FROM sqlite_master WHERE type = "table"')->fetchColumn();
74 if ($numTables == 0) {
75 $schema = file_get_contents(WCMF_BASE.
'install/tables_sqlite.sql');
79 $params[
'connection'] = $pdo;
88 public static function startServer($documentRoot, $router=
'') {
89 if (!is_dir($documentRoot)) {
90 throw new \Exception(
'Document root '.$documentRoot.
' does not exist');
92 define(
'SERVER_HOST',
'localhost');
93 define(
'SERVER_PORT', 8500);
94 $cmd = sprintf(
'php -S %s:%d -t %s %s', SERVER_HOST, SERVER_PORT, $documentRoot, $router);
96 $descriptorspec = array(
97 0 => array(
'pipe',
'r'),
98 1 => array(
'pipe',
'w'),
99 2 => array(
'pipe',
'a')
102 if (self::isWindows()) {
103 $resource = proc_open(
"start /B ".$cmd, $descriptorspec, $pipes);
106 $resource = proc_open(
"nohup ".$cmd, $descriptorspec, $pipes);
108 if (!is_resource($resource)) {
109 throw new \Exception(
"Failed to execute ".$cmd);
113 register_shutdown_function(
function() use ($resource) {
114 $status = proc_get_status($resource);
115 $pid = $status[
'pid'];
117 $output = array_filter(explode(
" ", shell_exec(
"wmic process get parentprocessid,processid | find \"$pid\"")));
120 exec(
"taskkill /F /T /PID $pid");
124 exec(
"kill -9 $pid");
136 $request->setFormat(
'null');
137 $request->setResponseFormat(
'null');
141 $actionMapper->reset();
142 $response = $actionMapper->processAction($request);
156 $authUser = $authManager->login($user, $password);
159 $session->setAuthUser($authUser);
162 throw new \RuntimeException(
"Session could not be started for user '$user'");
164 return $session->getID();
173 $session->__destruct();
182 $config->setValue($key, $value, $section);
192 $className = get_class($instance);
193 $class = new \ReflectionClass($className);
194 $method = $class->getMethod($methodName);
195 $method->setAccessible(
true);
198 return $method->invokeArgs($instance, $args);
201 return $method->invoke($instance);
206 $startMemory = memory_get_usage();
207 $var = unserialize(serialize($var));
208 return memory_get_usage() - $startMemory - PHP_INT_SIZE * 8;
218 $mapper->enableProfiler();
229 $profiler = $mapper->getProfiler();
232 foreach ($profiler->getQueryProfiles() as $query) {
233 echo $query->getElapsedSecs().
"s: ".$query->getQuery().
"\n";
236 $totalTime = $profiler->getTotalElapsedSecs();
237 $queryCount = $profiler->getTotalNumQueries();
239 $longestQuery = null;
240 foreach ($profiler->getQueryProfiles() as $query) {
241 if ($query->getElapsedSecs() > $longestTime) {
242 $longestTime = $query->getElapsedSecs();
243 $longestQuery = $query->getQuery();
247 echo
'Executed '.$queryCount.
' queries in '.$totalTime.
' seconds'.
"\n";
248 echo
'Average query length: '.$totalTime/$queryCount.
' seconds'.
"\n";
249 echo
'Queries per second: '.$queryCount/$totalTime.
"\n";
250 echo
'Longest query length: '.$longestTime.
"\n";
251 echo
"Longest query: \n".$longestQuery.
"\n";
255 return (substr(php_uname(), 0, 7) ==
"Windows");
DefaultFactory is used to create service instances.
RDBMapper maps objects of one type to a relational database schema.
static callProtectedMethod($instance, $methodName, $args=null)
Call a protected/private method of an instance (PHP >= 5.3.2)
static enableProfiler($type)
Enable the Zend_Db_Profiler for a given entity type.
static getInstance($name, $dynamicConfiguration=array())
static setConfigValue($key, $value, $section)
Set a configuration value.
static createDatabase()
Create the test database, if sqlite is configured.
static startServer($documentRoot, $router='')
Start the built-in webserver.
static startSession($user, $password)
Start a session.
static registerInstance($name, $instance)
static endSession()
End a session.
static printProfile($type)
Print the profile of the operations on a given entity type.
static simulateRequest($request)
Process a request as if it was sent to main.php.
static initFramework($configPath)
Set up the wcmf framework.
InifileConfiguration reads the application configuraiton from ini files.
TestUtil provides helper methods for testing wCMF functionality.
MonologFileLogger is a wrapper for the Monolog library that logs to files.
static configure(Factory $factory)
Configure the factory.
static configure(Logger $logger)
Configure the manager.