/**
* Handle the options and arguments.
*
- * @param mixed $options An array of options.
- * @param mixed $arguments An array of arguments.
+ * @param mixed &$options An array of options.
+ * @param mixed &$arguments An array of arguments.
*
* @return NULL
*/
- public function handleArguments($options, $arguments);
+ public function handleArguments(&$options, &$arguments);
}
\ No newline at end of file
- pear [IMAP]: The PEAR-Net_IMAP driver
- roundcube [IMAP]: The roundcube IMAP driver
- mock [Mem.]: A dummy driver that uses memory."
- )
+ ),
+ 'default' => 'horde'
)
),
new Horde_Argv_Option(
'--host',
array(
'action' => 'store',
- 'help' => Horde_Kolab_Cli_Translation::t('The host that holds the data.')
+ 'help' => Horde_Kolab_Cli_Translation::t('The host that holds the data.'),
+ 'default' => 'localhost'
)
),
new Horde_Argv_Option(
'help' => Horde_Kolab_Cli_Translation::t('Produce time measurements to indicate how long the processing takes.')
)
),
+ new Horde_Argv_Option(
+ '-l',
+ '--log',
+ array(
+ 'action' => 'store',
+ 'help' => Horde_Kolab_Cli_Translation::t('Write a log file in the provided LOG location.')
+ )
+ ),
);
}
/**
* Handle the options and arguments.
*
- * @param mixed $options An array of options.
- * @param mixed $arguments An array of arguments.
+ * @param mixed &$options An array of options.
+ * @param mixed &$arguments An array of arguments.
*
* @return NULL
*/
- public function handleArguments($options, $arguments)
+ public function handleArguments(&$options, &$arguments)
{
- if (in_array($options['driver'], array('roundcube', 'php', 'pear'))) {
+ if (isset($options['driver'])
+ && in_array($options['driver'], array('roundcube', 'php', 'pear'))) {
if (defined('E_DEPRECATED')) {
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_NOTICE);
} else {
error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);
}
}
+ if (isset($options['log'])) {
+ if (class_exists('Horde_Log_Logger')) {
+ $options['logger'] = new Horde_Log_Logger(
+ new Horde_Log_Handler_Stream(
+ $options['log']
+ )
+ );
+ } else {
+ file_put_contents($options['log'], 'The Horde_Log_Logger class is not available!');
+ }
+ }
}
}
\ No newline at end of file
/**
* Handle the options and arguments.
*
- * @param mixed $options An array of options.
- * @param mixed $arguments An array of arguments.
+ * @param mixed &$options An array of options.
+ * @param mixed &$arguments An array of arguments.
*
* @return NULL
*/
- public function handleArguments($options, $arguments)
+ public function handleArguments(&$options, &$arguments)
{
}
<name>Support</name>
<channel>pear.horde.org</channel>
</package>
+ <package>
+ <name>Log</name>
+ <channel>pear.horde.org</channel>
+ </package>
</optional>
</dependencies>
<phprelease>
class Horde_Kolab_Cli_TestCase
extends PHPUnit_Framework_TestCase
{
+ private $_log_file;
+
+ public function tearDown()
+ {
+ if ($this->_log_file !== null && file_exists($this->_log_file)) {
+ unlink($this->_log_file);
+ }
+ }
+
protected function runCli()
{
ob_start();
ob_end_clean();
return $output;
}
+
+ protected function getLogFile()
+ {
+ $this->_log_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR
+ . 'Kolab_Cli_' . mt_rand() . '.log';
+ return $this->_log_file;
+ }
+
+
}
{
public function setUp()
{
+ parent::setUp();
$this->_storeErrorHandling();
}
public function tearDown()
{
$this->_restoreErrorHandling();
+ parent::tearDown();
}
public function testNotice()
public function testMissingNoticeWithRoundcubeDriver()
{
+ $options = array('driver' => 'roundcube');
+ $arguments = array();
$base = new Horde_Kolab_Cli_Module_Base();
- $base->handleArguments(array('driver' => 'roundcube'), array());
+ $base->handleArguments($options, $arguments);
$this->assertFalse((bool) (error_reporting() & E_NOTICE));
}
public function testMissingNoticeWithHordeDriver()
{
+ $options = array('driver' => 'horde');
+ $arguments = array();
$base = new Horde_Kolab_Cli_Module_Base();
- $base->handleArguments(array('driver' => 'horde'), array());
+ $base->handleArguments($options, $arguments);
$this->assertTrue((bool) (error_reporting() & E_NOTICE));
}
+ public function testLoggerOption()
+ {
+ $options = array('log' => $this->getLogFile());
+ $arguments = array();
+ $base = new Horde_Kolab_Cli_Module_Base();
+ $base->handleArguments($options, $arguments);
+ $this->assertContains('logger', array_keys($options));
+ }
+
+ public function testLoggerClass()
+ {
+ $options = array('log' => $this->getLogFile());
+ $arguments = array();
+ $base = new Horde_Kolab_Cli_Module_Base();
+ $base->handleArguments($options, $arguments);
+ $this->assertInstanceOf('Horde_Log_Logger', $options['logger']);
+ }
+
private function _storeErrorHandling()
{
$this->_error_handling = error_reporting();
$this->runCli()
);
}
+
+ public function testOptionLog()
+ {
+ $_SERVER['argv'] = array(
+ 'klb'
+ );
+ $this->assertRegExp(
+ '/-l[ ]*LOG,[ ]*--log=LOG/',
+ $this->runCli()
+ );
+ }
}