Blame view
sources/3rdparty/rackspace/php-opencloud/tests/OpenCloud/Smoke/Step.php
4.07 KB
|
6d9380f96
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
<?php
/**
* @copyright Copyright 2012-2014 Rackspace US, Inc.
See COPYING for licensing information.
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
* @version 1.5.9
* @author Glen Campbell <glen.campbell@rackspace.com>
* @author Jamie Hannaford <jamie.hannaford@rackspace.com>
*/
namespace OpenCloud\Smoke;
/**
* Description of Step
*
* @link
*/
class Step
{
const SPACE_PREFIX = ' ';
const TYPE_SPACER = 'spacer';
const TYPE_DOTTER = 'dotter';
/**
* @var string The content to be outputted.
*/
public $message;
/**
* @var string Either default, `spacer` or `dotter`.
*/
public $outputType;
/**
* @var array Child steps.
*/
public $steps = array();
/**
* @var int How far down the rabbit hole is this step?
*/
public $depth = 0;
/**
* @var int The count for this step.
*/
public $count = 1;
/**
* @var Step The parent of this step.
*/
public $parent;
/**
* Factory method for outputting basic messages.
*/
public static function factory($message, $count = 1)
{
$step = new self();
return $step->setMessage($message)->setCount($count)->output();
}
public function setMessage($message)
{
$this->message = $message;
return $this;
}
public function getMessage()
{
return $this->message;
}
public function setOutputType($outputType)
{
$this->outputType = $outputType;
return $this;
}
public function getOutputType()
{
return $this->outputType;
}
public function setDepth($depth)
{
$this->depth = $depth;
return $this;
}
public function getDepth()
{
return $this->depth;
}
public function setCount($count)
{
$this->count = $count;
return $this;
}
public function getCount()
{
return $this->count;
}
public function setParent(Step $step)
{
$this->parent = $step;
return $this;
}
public function getParent()
{
return $this->parent;
}
public function getOutput()
{
switch ($this->getOutputType()) {
default:
$leadingLine = true;
$outputString = sprintf('%d. %s', $this->getCount(), $this->getMessage());
break;
case self::TYPE_DOTTER:
$outputString = sprintf('... %s', $this->getMessage());
break;
case self::TYPE_SPACER:
$outputString = sprintf('%s', $this->getMessage());
break;
}
return ((isset($leadingLine)) ? PHP_EOL : '')
. $this->computeSpacePrefix() . $outputString;
}
private function computeSpacePrefix()
{
return str_repeat(self::SPACE_PREFIX, $this->getDepth() + 1);
}
public function output()
{
Utils::log($this->getOutput());
if (null !== ($parent = $this->getParent())) {
$parent->steps[] = $this;
}
return $this;
}
public function subStep($message)
{
$subStep = new self();
$subStep->setMessage($message)
->setDepth($this->getDepth() + 1)
->setParent($this);
return $subStep;
}
/*** FACTORY METHODS ***/
public function stepInfo()
{
$string = Utils::convertArgsToString(func_get_args());
return $this->createSubStep($string, self::TYPE_SPACER);
}
public function stepInfoDotter()
{
$string = Utils::convertArgsToString(func_get_args());
return $this->createSubStep($string, self::TYPE_DOTTER);
}
public function createSubStep($string, $outputType = null)
{
return $this->subStep($string)
->setOutputType($outputType)
->setCount($this->getCount() + 1)
->output();
}
}
|