Prepare the Stdio class for easier testing.
- create an interface that describes the basic methods - let the real stdio class implement this interface - inject the stdio instance into IDF_Scm_Monotone and do not create it in the constructor - ensure in IDF_Scm_Monotone_ZipRender that we get the proper constructor arguments On a slighly unrelated note, make _getAuthOptions() in the stdio implementation private.
This commit is contained in:
parent
5b5705fe90
commit
78a0402351
@ -36,12 +36,12 @@ class IDF_Scm_Monotone extends IDF_Scm
|
||||
private static $instances = array();
|
||||
|
||||
/**
|
||||
* @see IDF_Scm::__construct()
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($project)
|
||||
public function __construct(IDF_Project $project, IDF_Scm_Monotone_IStdio $stdio)
|
||||
{
|
||||
$this->project = $project;
|
||||
$this->stdio = new IDF_Scm_Monotone_Stdio($project);
|
||||
$this->stdio = $stdio;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -458,8 +458,9 @@ class IDF_Scm_Monotone extends IDF_Scm
|
||||
public static function factory($project)
|
||||
{
|
||||
if (!array_key_exists($project->shortname, self::$instances)) {
|
||||
$stdio = new IDF_Scm_Monotone_Stdio($project);
|
||||
self::$instances[$project->shortname] =
|
||||
new IDF_Scm_Monotone($project);
|
||||
new IDF_Scm_Monotone($project, $stdio);
|
||||
}
|
||||
return self::$instances[$project->shortname];
|
||||
}
|
||||
@ -676,8 +677,8 @@ class IDF_Scm_Monotone extends IDF_Scm
|
||||
|
||||
$parents = $this->stdio->exec(array('parents', $revs[0]));
|
||||
$res['parents'] = preg_split("/\n/", $parents, -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
$certs = $this->_getCerts($revs[0]);
|
||||
|
||||
$certs = $this->_getCerts($revs[0]);
|
||||
// FIXME: this assumes that author, date and changelog are always given
|
||||
$res['author'] = implode(', ', $certs['author']);
|
||||
|
||||
|
66
src/IDF/Scm/Monotone/IStdio.php
Normal file
66
src/IDF/Scm/Monotone/IStdio.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# This file is part of InDefero, an open source project management application.
|
||||
# Copyright (C) 2011 Céondo Ltd and contributors.
|
||||
#
|
||||
# InDefero is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# InDefero is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* Monotone stdio interface
|
||||
*
|
||||
* @author Thomas Keller <me@thomaskeller.biz>
|
||||
*/
|
||||
interface IDF_Scm_Monotone_IStdio
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(IDF_Project $project);
|
||||
|
||||
/**
|
||||
* Starts the stdio process and resets the command counter
|
||||
*/
|
||||
public function start();
|
||||
|
||||
/**
|
||||
* Stops the stdio process and closes all pipes
|
||||
*/
|
||||
public function stop();
|
||||
|
||||
/**
|
||||
* Executes a command over stdio and returns its result
|
||||
*
|
||||
* @param array Array of arguments
|
||||
* @param array Array of options as key-value pairs. Multiple options
|
||||
* can be defined in sub-arrays, like
|
||||
* "r" => array("123...", "456...")
|
||||
* @return string
|
||||
*/
|
||||
public function exec(array $args, array $options = array());
|
||||
|
||||
/**
|
||||
* Returns the last out-of-band output for a previously executed
|
||||
* command as associative array with 'e' (error), 'w' (warning),
|
||||
* 'p' (progress) and 't' (ticker, unparsed) as keys
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLastOutOfBandOutput();
|
||||
}
|
||||
|
@ -21,6 +21,8 @@
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** */
|
||||
|
||||
require_once 'IDF/Scm/Monotone/IStdio.php';
|
||||
|
||||
/**
|
||||
* Monotone stdio class
|
||||
*
|
||||
@ -29,7 +31,7 @@
|
||||
*
|
||||
* @author Thomas Keller <me@thomaskeller.biz>
|
||||
*/
|
||||
class IDF_Scm_Monotone_Stdio
|
||||
class IDF_Scm_Monotone_Stdio implements IDF_Scm_Monotone_IStdio
|
||||
{
|
||||
/** this is the most recent STDIO version. The number is output
|
||||
at the protocol start. Older versions of monotone (prior 0.47)
|
||||
@ -68,7 +70,7 @@ class IDF_Scm_Monotone_Stdio
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function _getAuthOptions()
|
||||
private function _getAuthOptions()
|
||||
{
|
||||
$prjconf = $this->project->getConf();
|
||||
$name = $prjconf->getVal('mtn_client_key_name', false);
|
||||
|
@ -24,7 +24,7 @@
|
||||
require_once(IDF_PATH.'/../contrib/zipstream-php-0.2.2/zipstream.php');
|
||||
|
||||
/**
|
||||
* Special response object to output
|
||||
* Special response object to output
|
||||
*
|
||||
* The Content-Length will not be set as it is not possible to predict it.
|
||||
*
|
||||
@ -45,7 +45,7 @@ class IDF_Scm_Monotone_ZipRender extends Pluf_HTTP_Response
|
||||
private $stdio = null;
|
||||
private $revision = null;
|
||||
|
||||
function __construct($stdio, $revision)
|
||||
function __construct(IDF_Scm_Monotone_IStdio $stdio, $revision)
|
||||
{
|
||||
parent::__construct($revision, 'application/x-zip');
|
||||
$this->stdio = $stdio;
|
||||
|
Loading…
Reference in New Issue
Block a user