@@ -58,70 +58,70 @@ |
||
58 | 58 | */ |
59 | 59 | class Tale_Loader |
60 | 60 | { |
61 | - /** |
|
62 | - * singleton - do not instantiate |
|
63 | - * @codeCoverageIgnore |
|
64 | - */ |
|
65 | - protected function __construct() |
|
66 | - { |
|
67 | - // do nothing |
|
68 | - } |
|
61 | + /** |
|
62 | + * singleton - do not instantiate |
|
63 | + * @codeCoverageIgnore |
|
64 | + */ |
|
65 | + protected function __construct() |
|
66 | + { |
|
67 | + // do nothing |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * load a story, throwing exceptions if problems are detected |
|
72 | - * |
|
73 | - * @param string $filename |
|
74 | - * path to the PHP file containing the story |
|
75 | - * @return Story |
|
76 | - * the story object |
|
77 | - */ |
|
78 | - static public function loadTale($filename) |
|
79 | - { |
|
80 | - if (!file_exists($filename)) { |
|
81 | - throw new E5xx_InvalidStoryListFile("Cannot find file '{$filename}' to load"); |
|
82 | - } |
|
70 | + /** |
|
71 | + * load a story, throwing exceptions if problems are detected |
|
72 | + * |
|
73 | + * @param string $filename |
|
74 | + * path to the PHP file containing the story |
|
75 | + * @return Story |
|
76 | + * the story object |
|
77 | + */ |
|
78 | + static public function loadTale($filename) |
|
79 | + { |
|
80 | + if (!file_exists($filename)) { |
|
81 | + throw new E5xx_InvalidStoryListFile("Cannot find file '{$filename}' to load"); |
|
82 | + } |
|
83 | 83 | |
84 | - // load the contents |
|
85 | - $contents = file_get_contents($filename); |
|
84 | + // load the contents |
|
85 | + $contents = file_get_contents($filename); |
|
86 | 86 | |
87 | - // does it decode? |
|
88 | - $tale = json_decode($contents); |
|
89 | - if (!$tale) { |
|
90 | - throw new E4xx_InvalidStoryListFile("Story list '{$filename}' does not contain valid JSON"); |
|
91 | - } |
|
87 | + // does it decode? |
|
88 | + $tale = json_decode($contents); |
|
89 | + if (!$tale) { |
|
90 | + throw new E4xx_InvalidStoryListFile("Story list '{$filename}' does not contain valid JSON"); |
|
91 | + } |
|
92 | 92 | |
93 | - // does it have the elements we require? |
|
94 | - if (!isset($tale->stories)) { |
|
95 | - throw new E4xx_InvalidStoryListFile("Story list '{$filename}' does not contain a 'stories' element"); |
|
96 | - } |
|
97 | - if (!is_array($tale->stories)) { |
|
98 | - throw new E4xx_InvalidStoryListFile("The 'stories' element in the story list '{$filename}' must be an array"); |
|
99 | - } |
|
100 | - if (count($tale->stories) == 0) { |
|
101 | - throw new E4xx_InvalidStoryListFile("The 'stories' element in the story list '{$filename}' cannot be an empty array"); |
|
102 | - } |
|
93 | + // does it have the elements we require? |
|
94 | + if (!isset($tale->stories)) { |
|
95 | + throw new E4xx_InvalidStoryListFile("Story list '{$filename}' does not contain a 'stories' element"); |
|
96 | + } |
|
97 | + if (!is_array($tale->stories)) { |
|
98 | + throw new E4xx_InvalidStoryListFile("The 'stories' element in the story list '{$filename}' must be an array"); |
|
99 | + } |
|
100 | + if (count($tale->stories) == 0) { |
|
101 | + throw new E4xx_InvalidStoryListFile("The 'stories' element in the story list '{$filename}' cannot be an empty array"); |
|
102 | + } |
|
103 | 103 | |
104 | - // our base directory to search from |
|
105 | - $storiesBasedir = dirname($filename); |
|
104 | + // our base directory to search from |
|
105 | + $storiesBasedir = dirname($filename); |
|
106 | 106 | |
107 | - // do all of the stories in the list exist? |
|
108 | - foreach ($tale->stories as $index => $storyFile) { |
|
109 | - $realStoryFile = $storiesBasedir . DIRECTORY_SEPARATOR . $storyFile; |
|
110 | - if (file_exists($realStoryFile)) { |
|
111 | - throw new E4xx_InvalidStoryListFile("Cannot find the story file '{$realStoryFile}' on disk"); |
|
112 | - } |
|
113 | - $tale->stories[$index] = $realStoryFile; |
|
114 | - } |
|
107 | + // do all of the stories in the list exist? |
|
108 | + foreach ($tale->stories as $index => $storyFile) { |
|
109 | + $realStoryFile = $storiesBasedir . DIRECTORY_SEPARATOR . $storyFile; |
|
110 | + if (file_exists($realStoryFile)) { |
|
111 | + throw new E4xx_InvalidStoryListFile("Cannot find the story file '{$realStoryFile}' on disk"); |
|
112 | + } |
|
113 | + $tale->stories[$index] = $realStoryFile; |
|
114 | + } |
|
115 | 115 | |
116 | - // inject defaults for optional fields |
|
117 | - if (!isset($tale->options)) { |
|
118 | - $tale->options = new stdClass(); |
|
119 | - } |
|
120 | - if (!isset($tale->options->reuseTestEnvironment)) { |
|
121 | - $tale->options->reuseTestEnvironment = false; |
|
122 | - } |
|
116 | + // inject defaults for optional fields |
|
117 | + if (!isset($tale->options)) { |
|
118 | + $tale->options = new stdClass(); |
|
119 | + } |
|
120 | + if (!isset($tale->options->reuseTestEnvironment)) { |
|
121 | + $tale->options->reuseTestEnvironment = false; |
|
122 | + } |
|
123 | 123 | |
124 | - // all done |
|
125 | - return $tale; |
|
126 | - } |
|
124 | + // all done |
|
125 | + return $tale; |
|
126 | + } |
|
127 | 127 | } |
128 | 128 | \ No newline at end of file |
@@ -103,8 +103,7 @@ |
||
103 | 103 | |
104 | 104 | // now we need to play whatever runs against this |
105 | 105 | // test environment |
106 | - foreach ($this->wrappedPlayers as $wrappedPlayer) |
|
107 | - { |
|
106 | + foreach ($this->wrappedPlayers as $wrappedPlayer) { |
|
108 | 107 | // play the wrapped item |
109 | 108 | // |
110 | 109 | // this is normally a story |
@@ -175,8 +175,8 @@ |
||
175 | 175 | |
176 | 176 | // build the command for Ansible |
177 | 177 | $command = 'ansible-playbook -i "' . $inventoryFile . '"' |
178 | - . ' "--private-key=' . $sshKeyFile . '"' |
|
179 | - . ' "--user=' . $sshUsername . '"'; |
|
178 | + . ' "--private-key=' . $sshKeyFile . '"' |
|
179 | + . ' "--user=' . $sshUsername . '"'; |
|
180 | 180 | |
181 | 181 | $command .= ' "' . $ansibleSettings->dir . DIRECTORY_SEPARATOR . $ansibleSettings->playbook . '"'; |
182 | 182 |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | if (isset($machine->params)) { |
87 | 87 | $params = []; |
88 | 88 | foreach ($machine->params as $paramName => $paramValue) { |
89 | - $params[$paramName] = fromConfig()->get('hosts.' . $hostId . '.params.'.$paramName); |
|
89 | + $params[$paramName] = fromConfig()->get('hosts.' . $hostId . '.params.' . $paramName); |
|
90 | 90 | } |
91 | 91 | if (count($params)) { |
92 | 92 | usingProvisioningDefinition($provDef)->addParams($params)->toHost($hostId); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $rolesToHosts = array(); |
112 | 112 | |
113 | 113 | // build up the list of roles |
114 | - foreach($hosts as $hostId => $hostProps) { |
|
114 | + foreach ($hosts as $hostId => $hostProps) { |
|
115 | 115 | // what is the host's IP address? |
116 | 116 | $ipAddress = fromHost($hostId)->getIpAddress(); |
117 | 117 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $sshKeyFile = null; |
155 | 155 | |
156 | 156 | // now we need to write out the host files |
157 | - foreach($hosts as $hostId => $hostProps) { |
|
157 | + foreach ($hosts as $hostId => $hostProps) { |
|
158 | 158 | // what is the host's IP address? |
159 | 159 | $ipAddress = fromHost($hostId)->getIpAddress(); |
160 | 160 | $sshUsername = fromHost($hostId)->getSshUsername(); |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | // does the target folder exist? |
237 | 237 | $hostVarsFolder = dirname($filename); |
238 | 238 | if (!file_exists($hostVarsFolder)) { |
239 | - mkdir ($hostVarsFolder); |
|
239 | + mkdir($hostVarsFolder); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | // write the data |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | if (isset($machine->params)) { |
89 | 89 | $params = []; |
90 | 90 | foreach ($machine->params as $paramName => $paramValue) { |
91 | - $params[$paramName] = fromConfig()->get('hosts.' . $hostId . '.params.'.$paramName); |
|
91 | + $params[$paramName] = fromConfig()->get('hosts.' . $hostId . '.params.' . $paramName); |
|
92 | 92 | } |
93 | 93 | if (count($params)) { |
94 | 94 | usingProvisioningDefinition($provDef)->addParams($params)->toHost($hostId); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $dsbuildParams = new BaseObject; |
111 | 111 | |
112 | 112 | // build up the list of settings to write out |
113 | - foreach($hosts as $hostId => $hostProps) { |
|
113 | + foreach ($hosts as $hostId => $hostProps) { |
|
114 | 114 | // what is the host's IP address? |
115 | 115 | $ipAddress = fromHost($hostId)->getIpAddress(); |
116 | 116 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | // at this point, we are ready to attempt provisioning |
133 | 133 | // |
134 | 134 | // provision each host in the order that they're listed |
135 | - foreach($hosts as $hostId => $hostProps) { |
|
135 | + foreach ($hosts as $hostId => $hostProps) { |
|
136 | 136 | // which dsbuildfile are we going to run? |
137 | 137 | $hostDir = fromHost($hostId)->getLocalFolder(); |
138 | 138 | $dsbuildFilename = $this->getDsbuildFilename($hostDir, $provConfig, $hostId); |
@@ -148,11 +148,11 @@ discard block |
||
148 | 148 | // copy the dsbuildparams files to the target machine using scp |
149 | 149 | // NOTE: the "vagrant rsync" command seems not working with some Vagrant provisioners (e.g. OpenStack) |
150 | 150 | $command = 'scp' |
151 | - .' '.$dsbuildParams->{'hosts_'.$hostId.'_scpOptions_0'} |
|
152 | - .' '.$dsbuildParams->{'hosts_'.$hostId.'_scpOptions_1'} |
|
151 | + .' ' . $dsbuildParams->{'hosts_' . $hostId . '_scpOptions_0'} |
|
152 | + .' ' . $dsbuildParams->{'hosts_' . $hostId . '_scpOptions_1'} |
|
153 | 153 | .' dsbuildparams.*' |
154 | - .' '.$dsbuildParams->{'hosts_'.$hostId.'_sshUsername'} |
|
155 | - .'@'.$dsbuildParams->{'hosts_'.$hostId.'_ipAddress'} |
|
154 | + .' ' . $dsbuildParams->{'hosts_' . $hostId . '_sshUsername'} |
|
155 | + .'@' . $dsbuildParams->{'hosts_' . $hostId . '_ipAddress'} |
|
156 | 156 | .':/vagrant/'; |
157 | 157 | $result = $commandRunner->runSilently($command); |
158 | 158 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @return array |
230 | 230 | * the flattened data |
231 | 231 | */ |
232 | - protected function flattenData($inputData, $prefix="") |
|
232 | + protected function flattenData($inputData, $prefix = "") |
|
233 | 233 | { |
234 | 234 | $retval = []; |
235 | 235 |
@@ -233,8 +233,7 @@ |
||
233 | 233 | { |
234 | 234 | $retval = []; |
235 | 235 | |
236 | - foreach ($inputData as $name => $dataToFlatten) |
|
237 | - { |
|
236 | + foreach ($inputData as $name => $dataToFlatten) { |
|
238 | 237 | if (is_object($dataToFlatten) || is_array($dataToFlatten)) { |
239 | 238 | $retval = array_merge($retval, $this->flattenData($dataToFlatten, $prefix . $name . "_")); |
240 | 239 | } |
@@ -130,40 +130,40 @@ discard block |
||
130 | 130 | public function endStoryplayer($duration) |
131 | 131 | { |
132 | 132 | // generate the XML |
133 | - $junitxml = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL; |
|
133 | + $junitxml = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL; |
|
134 | 134 | $junitxml .= '<testsuite' |
135 | - .' id="'.$this->testsuite['id'].'"' |
|
136 | - .' name="'.$this->testsuite['name'].'"' |
|
137 | - .' tests="'.$this->testsuite['tests'].'"' |
|
138 | - .' disabled="'.$this->testsuite['disabled'].'"' |
|
139 | - .' errors="'.$this->testsuite['errors'].'"' |
|
140 | - .' failures="'.$this->testsuite['failures'].'"' |
|
141 | - .' skipped="'.$this->testsuite['skipped'].'"' |
|
142 | - .' time="'.round($duration, 6).'"' |
|
143 | - .' timestamp="'.$this->testsuite['timestamp'].'">'.PHP_EOL; |
|
135 | + .' id="' . $this->testsuite['id'] . '"' |
|
136 | + .' name="' . $this->testsuite['name'] . '"' |
|
137 | + .' tests="' . $this->testsuite['tests'] . '"' |
|
138 | + .' disabled="' . $this->testsuite['disabled'] . '"' |
|
139 | + .' errors="' . $this->testsuite['errors'] . '"' |
|
140 | + .' failures="' . $this->testsuite['failures'] . '"' |
|
141 | + .' skipped="' . $this->testsuite['skipped'] . '"' |
|
142 | + .' time="' . round($duration, 6) . '"' |
|
143 | + .' timestamp="' . $this->testsuite['timestamp'] . '">' . PHP_EOL; |
|
144 | 144 | |
145 | 145 | foreach ($this->testsuite['testcase'] as $testcase) { |
146 | - $junitxml .= "\t".'<testcase' |
|
147 | - .' name="'.$testcase['name'].'"' |
|
148 | - .' assertions="'.$testcase['assertions'].'"' |
|
149 | - .' classname="'.$testcase['classname'].'"' |
|
150 | - .' status="'.$testcase['status'].'"' |
|
151 | - .' time="'.round($testcase['time'], 6).'">'.PHP_EOL; |
|
146 | + $junitxml .= "\t" . '<testcase' |
|
147 | + .' name="' . $testcase['name'] . '"' |
|
148 | + .' assertions="' . $testcase['assertions'] . '"' |
|
149 | + .' classname="' . $testcase['classname'] . '"' |
|
150 | + .' status="' . $testcase['status'] . '"' |
|
151 | + .' time="' . round($testcase['time'], 6) . '">' . PHP_EOL; |
|
152 | 152 | |
153 | 153 | if ($testcase['skipped']) { |
154 | - $junitxml .= "\t\t".'<skipped/>'.PHP_EOL; |
|
154 | + $junitxml .= "\t\t" . '<skipped/>' . PHP_EOL; |
|
155 | 155 | } |
156 | 156 | if ($testcase['failure']) { |
157 | - $junitxml .= "\t\t".'<failure/>'.PHP_EOL; |
|
157 | + $junitxml .= "\t\t" . '<failure/>' . PHP_EOL; |
|
158 | 158 | } |
159 | 159 | if ($testcase['error']) { |
160 | - $junitxml .= "\t\t".'<error/>'.PHP_EOL; |
|
160 | + $junitxml .= "\t\t" . '<error/>' . PHP_EOL; |
|
161 | 161 | } |
162 | 162 | |
163 | - $junitxml .= "\t".'</testcase>'.PHP_EOL; |
|
163 | + $junitxml .= "\t" . '</testcase>' . PHP_EOL; |
|
164 | 164 | } |
165 | 165 | |
166 | - $junitxml .= '</testsuite>'.PHP_EOL; |
|
166 | + $junitxml .= '</testsuite>' . PHP_EOL; |
|
167 | 167 | |
168 | 168 | file_put_contents($this->filename, $junitxml); |
169 | 169 | } |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | $name = htmlspecialchars($name, ENT_QUOTES | ENT_XML1, 'UTF-8'); |
181 | 181 | $this->testcase = array( |
182 | 182 | 'name' => $name, |
183 | - 'assertions' => 0, // number of assertions in the test case |
|
183 | + 'assertions' => 0, // number of assertions in the test case |
|
184 | 184 | 'classname' => $name, // full class name for the class the test method is in |
185 | - 'status' => '', // result status string |
|
186 | - 'time' => 0, // time taken (in seconds) to execute the test |
|
185 | + 'status' => '', // result status string |
|
186 | + 'time' => 0, // time taken (in seconds) to execute the test |
|
187 | 187 | 'skipped' => false, |
188 | 188 | 'failure' => false, |
189 | 189 | 'error' => false, |
@@ -100,7 +100,8 @@ |
||
100 | 100 | $this->silentActivity = true; |
101 | 101 | } |
102 | 102 | |
103 | - public function __construct($args) { |
|
103 | + public function __construct($args) |
|
104 | + { |
|
104 | 105 | if (isset($args['filename'])) { |
105 | 106 | $this->filename = $args['filename']; |
106 | 107 | } |
@@ -71,14 +71,14 @@ |
||
71 | 71 | { |
72 | 72 | // defaults for the local computer |
73 | 73 | $rolesConfig = new BaseObject; |
74 | - $rolesConfig->roles = [ '*' ]; |
|
74 | + $rolesConfig->roles = ['*']; |
|
75 | 75 | |
76 | 76 | $config = &$this->newConfig('localhost')->getConfig(); |
77 | 77 | $config->groups = new BaseObject; |
78 | 78 | $config->groups->{'0'} = new BaseObject; |
79 | 79 | $config->groups->{'0'}->type = "Blackboxes"; |
80 | 80 | $config->groups->{'0'}->details = new BaseObject; |
81 | - $config->groups->{'0'}->details->machines = [ $rolesConfig ]; |
|
81 | + $config->groups->{'0'}->details->machines = [$rolesConfig]; |
|
82 | 82 | |
83 | 83 | // all done |
84 | 84 | } |
@@ -143,7 +143,7 @@ |
||
143 | 143 | if (!isset($machine->params)) { |
144 | 144 | $machine->params = new BaseObject; |
145 | 145 | } |
146 | - else if (! $machine->params instanceof BaseObject) { |
|
146 | + else if (!$machine->params instanceof BaseObject) { |
|
147 | 147 | $tmp = new BaseObject; |
148 | 148 | $tmp->mergeFrom($machine->params); |
149 | 149 | $machine->params = $tmp; |
@@ -72,16 +72,16 @@ |
||
72 | 72 | // we need a valid PHP class |
73 | 73 | if (!class_exists($value)) |
74 | 74 | { |
75 | - $result->addError(static::MSG_NOTVALIDCLASS); |
|
76 | - return $result; |
|
75 | + $result->addError(static::MSG_NOTVALIDCLASS); |
|
76 | + return $result; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | // the class must be a StoryTemplate |
80 | 80 | $refClass = new ReflectionClass($value); |
81 | 81 | if (!$refClass->isSubclassOf('DataSift\Storyplayer\PlayerLib\StoryTemplate')) |
82 | 82 | { |
83 | - $result->addError(static::MSG_NOTVALIDTEMPLATE); |
|
84 | - return $result; |
|
83 | + $result->addError(static::MSG_NOTVALIDTEMPLATE); |
|
84 | + return $result; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | // all done |
@@ -64,22 +64,19 @@ |
||
64 | 64 | |
65 | 65 | public function validate($value, ValidationResult $result = null) |
66 | 66 | { |
67 | - if ($result === null) |
|
68 | - { |
|
67 | + if ($result === null) { |
|
69 | 68 | $result = new ValidationResult($value); |
70 | 69 | } |
71 | 70 | |
72 | 71 | // we need a valid PHP class |
73 | - if (!class_exists($value)) |
|
74 | - { |
|
72 | + if (!class_exists($value)) { |
|
75 | 73 | $result->addError(static::MSG_NOTVALIDCLASS); |
76 | 74 | return $result; |
77 | 75 | } |
78 | 76 | |
79 | 77 | // the class must be a StoryTemplate |
80 | 78 | $refClass = new ReflectionClass($value); |
81 | - if (!$refClass->isSubclassOf('Storyplayer\Stories\StoryTemplate')) |
|
82 | - { |
|
79 | + if (!$refClass->isSubclassOf('Storyplayer\Stories\StoryTemplate')) { |
|
83 | 80 | $result->addError(static::MSG_NOTVALIDTEMPLATE); |
84 | 81 | return $result; |
85 | 82 | } |