public function __construct($dbConfig, $logger) { require_once 'Phigrate/Logger.php'; $logger = Phigrate_Logger::instance(PHIGRATE_BASE . '/tests/logs/tests.log'); $this->_conn = new pdoTaskMock(); $this->setLogger($logger); }
public function testClose() { $this->object->close(); $msg = 'msg de test 6'; $expected = '/^\\w+ \\d+ \\d+:\\d+:\\d+ \\[UNKNOWN\\] ' . $msg . '$/'; $this->object->log($msg, 'unknown'); $file = file(self::$_filename); $this->assertNotRegExp($expected, $file[count($file) - 1]); }
/** * load all tasks * * @return void * @throws Phigrate_Exception_Argument */ private function _loadAllTasks() { $this->_logger->debug(__METHOD__ . ' Start'); if (!isset($this->_tasksDir)) { $msg = 'Please: you must specify the directory of tasks!'; $this->_logger->err($msg); throw new Phigrate_Exception_Argument($msg); } foreach ($this->_tasksDir as $index => $taskDir) { $namespaces = scandir($taskDir); $this->_logger->debug('Tasks dir[' . $index . ']: ' . $taskDir); //$this->_tasks = array(); foreach ($namespaces as $namespace) { //skip over invalid files if ($namespace == '.' || $namespace == '..' || !is_dir($taskDir . '/' . $namespace)) { continue; } $this->_logger->debug('Namespace: ' . $namespace); $files = scandir($taskDir . '/' . $namespace); foreach ($files as $file) { $ext = substr($file, -4); //skip over invalid files if ($file == '.' || $file == '..' || $ext != '.php') { continue; } $this->_logger->debug('include ' . $namespace . '/' . $file); require_once $taskDir . '/' . $namespace . '/' . $file; $class = Phigrate_Util_Naming::classFromFileName($taskDir . '/' . $namespace . '/' . $file); $refl = new ReflectionClass($class); if ($refl->isInstantiable()) { $this->_logger->debug('className ' . $class); $taskName = Phigrate_Util_Naming::taskFromClassName($class); $this->_logger->debug('TaskName: ' . $taskName); $taskObj = new $class($this->getAdapter()); $this->_logger->debug('obj: ' . get_class($taskObj)); $this->registerTask($taskName, $taskObj); } } } } $this->_logger->debug(__METHOD__ . ' End'); }
public static function setUpBeforeClass() { self::_saveConfigFiles(); require_once 'Phigrate/Logger.php'; self::$_logger = Phigrate_Logger::instance(PHIGRATE_BASE . '/tests/logs/tests.log'); }
/** * Initialize and return an instance of logger * * @return Phigrate_Logger */ private function _initLogger() { //initialize logger $logDir = '/tmp/'; $config = $this->getConfig(); if (isset($this->_logDir)) { // First in arguments of command line $logDir = $this->_logDir; } elseif (isset($config->log) && isset($config->log->dir)) { // Second in config file $logDir = $config->log->dir; } $tmp = $logDir; $logDir = $this->_fileWithRealPath($logDir); if (!is_dir($logDir)) { require_once 'Phigrate/Exception/InvalidLog.php'; throw new Phigrate_Exception_InvalidLog($tmp . ' does not exists.'); } if (is_dir($logDir) && !is_writable($logDir)) { require_once 'Phigrate/Exception/InvalidLog.php'; throw new Phigrate_Exception_InvalidLog('Cannot write to log directory: ' . $logDir . '. Check permissions.'); } $logger = Phigrate_Logger::instance($logDir . '/' . $this->_env . '.log'); $priority = 99; if (isset($config->log->priority)) { $priority = $config->log->priority; } elseif ($this->_env == 'development') { $priority = Phigrate_Logger::DEBUG; } elseif ($this->_env == 'production') { $priority = Phigrate_Logger::INFO; } $logger->setPriority($priority); return $logger; }
/** * close a file logs * * @return void */ public function close() { $this->debug(__METHOD__); if ($this->_fp) { $closed = fclose($this->_fp); if ($closed) { $this->_fp = null; self::$_instance = null; } else { echo 'Error closing the log file'; } } }
public static function setUpBeforeClass() { self::$_dsn = array('host' => 'localhost', 'port' => 3306, 'database' => 'phigrate_test', 'user' => USER_MYSQL_DEFAULT, 'password' => PASSWORD_MYSQL_DEFAULT); require_once 'Phigrate/Logger.php'; self::$_logger = Phigrate_Logger::instance(PHIGRATE_BASE . '/tests/logs/tests.log'); }