|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2011-present Mediasift Ltd |
|
5
|
|
|
* All rights reserved. |
|
6
|
|
|
* |
|
7
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
8
|
|
|
* modification, are permitted provided that the following conditions |
|
9
|
|
|
* are met: |
|
10
|
|
|
* |
|
11
|
|
|
* * Redistributions of source code must retain the above copyright |
|
12
|
|
|
* notice, this list of conditions and the following disclaimer. |
|
13
|
|
|
* |
|
14
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
|
15
|
|
|
* notice, this list of conditions and the following disclaimer in |
|
16
|
|
|
* the documentation and/or other materials provided with the |
|
17
|
|
|
* distribution. |
|
18
|
|
|
* |
|
19
|
|
|
* * Neither the names of the copyright holders nor the names of his |
|
20
|
|
|
* contributors may be used to endorse or promote products derived |
|
21
|
|
|
* from this software without specific prior written permission. |
|
22
|
|
|
* |
|
23
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
24
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
25
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
26
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
27
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
28
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
29
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
30
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
31
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
32
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
33
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
34
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
|
35
|
|
|
* |
|
36
|
|
|
* @category Libraries |
|
37
|
|
|
* @package Storyplayer/TestEnvironmentsLib |
|
38
|
|
|
* @author Stuart Herbert <[email protected]> |
|
39
|
|
|
* @copyright 2011-2015 Mediasift Ltd www.datasift.com |
|
40
|
|
|
* @copyright 2015-present Ganbaro Digital Ltd www.ganbarodigital.com |
|
41
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
42
|
|
|
* @link http://datasift.github.io/storyplayer |
|
43
|
|
|
*/ |
|
44
|
|
|
|
|
45
|
|
|
namespace DataSift\Storyplayer\TestEnvironmentsLib; |
|
46
|
|
|
|
|
47
|
|
|
use DataSift\Storyplayer\ConfigLib\WrappedConfig; |
|
48
|
|
|
use DataSift\Stone\ObjectLib\BaseObject; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* the class for a test environment's runtime config |
|
52
|
|
|
* |
|
53
|
|
|
* the runtime config is the persistent state (e.g. hosts that have been |
|
54
|
|
|
* spun up) of the test environment |
|
55
|
|
|
* |
|
56
|
|
|
* @category Libraries |
|
57
|
|
|
* @package Storyplayer/TestEnvironmentsLib |
|
58
|
|
|
* @author Stuart Herbert <[email protected]> |
|
59
|
|
|
* @copyright 2011-2015 Mediasift Ltd www.datasift.com |
|
60
|
|
|
* @copyright 2015-present Ganbaro Digital Ltd www.ganbarodigital.com |
|
61
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
62
|
|
|
* @link http://datasift.github.io/storyplayer |
|
63
|
|
|
*/ |
|
64
|
|
|
class TestEnvironmentRuntimeConfig extends WrappedConfig |
|
65
|
|
|
{ |
|
66
|
|
|
public function __construct() |
|
67
|
|
|
{ |
|
68
|
|
|
parent::__construct(self::ROOT_IS_OBJECT); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function validateConfig() |
|
72
|
|
|
{ |
|
73
|
|
|
// do we have any config? |
|
74
|
|
|
$config = $this->getConfig(); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* set the name of this config by looking at the filename |
|
79
|
|
|
* |
|
80
|
|
|
* the 'name' is used as an array key elsewhere. if we get this wrong, |
|
81
|
|
|
* then Storyplayer isn't going to be able to find our config later on |
|
82
|
|
|
* |
|
83
|
|
|
* @param string $filename |
|
84
|
|
|
* the path/to/file/name.ext where we found this config |
|
85
|
|
|
* @return void |
|
86
|
|
|
*/ |
|
87
|
|
|
protected function setNameFromFilename($filename) |
|
88
|
|
|
{ |
|
89
|
|
|
$this->setName(basename(dirname($filename))); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
// ================================================================== |
|
93
|
|
|
// |
|
94
|
|
|
// This is the old RuntimeConfigManager API from SPv1 (more or less). |
|
95
|
|
|
// |
|
96
|
|
|
// It is part of our migration from a single runtime-v2.json file to |
|
97
|
|
|
// a per-test-environment runtime.json file scheme. |
|
98
|
|
|
// |
|
99
|
|
|
// ------------------------------------------------------------------ |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* getAllTables |
|
103
|
|
|
* |
|
104
|
|
|
* Return our tables config that we can use for |
|
105
|
|
|
* in place editing |
|
106
|
|
|
* |
|
107
|
|
|
* @return BaseObject |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getAllTables() |
|
110
|
|
|
{ |
|
111
|
|
|
// make sure the storyplayer section exists |
|
112
|
|
|
if (!$this->hasData('tables')) { |
|
113
|
|
|
$this->setData('tables', new BaseObject); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
// arrow-notation ensures we get a READ-WRITE object back |
|
117
|
|
|
return $this->tables; |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* return a single table from the persistent state |
|
122
|
|
|
* |
|
123
|
|
|
* if the table does not exist, this will create an empty table |
|
124
|
|
|
* before returning it to the caller |
|
125
|
|
|
* |
|
126
|
|
|
* @param string $tableName |
|
127
|
|
|
* the name of the table we want |
|
128
|
|
|
* @return BaseObject |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getTable($tableName) |
|
131
|
|
|
{ |
|
132
|
|
|
// normalise! |
|
133
|
|
|
$tableName = lcfirst($tableName); |
|
134
|
|
|
|
|
135
|
|
|
// find it |
|
136
|
|
|
$tables = $this->getAllTables(); |
|
137
|
|
|
if (!isset($tables->$tableName)) { |
|
138
|
|
|
// make sure the caller gets a table |
|
139
|
|
|
$tables->$tableName = new BaseObject; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
// all done |
|
143
|
|
|
return $tables->$tableName; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* remove any empty tables from the runtime config |
|
148
|
|
|
* |
|
149
|
|
|
* @return void |
|
150
|
|
|
*/ |
|
151
|
|
|
public function removeEmptyTables() |
|
152
|
|
|
{ |
|
153
|
|
|
$tables = $this->getAllTables(); |
|
154
|
|
|
|
|
155
|
|
|
foreach ($tables as $tableName => $table) { |
|
156
|
|
|
if ($table instanceof BaseObject) { |
|
157
|
|
|
if (!$table->hasProperties()) { |
|
158
|
|
|
unset($tables->$tableName); |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
else if (is_array($table)) { |
|
162
|
|
|
if (empty($table)) { |
|
163
|
|
|
unset($tables->$tableName); |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
if (!$tables->hasProperties()) { |
|
169
|
|
|
$this->unsetData('tables'); |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.