Completed
Push — master ( e2b6f6...0751d4 )
by rugk
02:57
created
source/Threema/MsgApi/Tests/CryptToolTest.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 
57 57
 			$this->assertNotNull($message);
58 58
 			$this->assertTrue($message instanceof TextMessage);
59
-			if($message instanceof TextMessage) {
59
+			if ($message instanceof TextMessage) {
60 60
 				$this->assertEquals($message->getText(), 'Dies ist eine Testnachricht. äöü');
61 61
 			}
62 62
 		});
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 
93 93
 
94 94
 	public function testDerivePublicKey() {
95
-		$this->doTest(function(CryptTool $cryptTool, $prefix){
95
+		$this->doTest(function(CryptTool $cryptTool, $prefix) {
96 96
 			$publicKey = $cryptTool->derivePublicKey($cryptTool->hex2bin(Common::getPrivateKey(Constants::myPrivateKey)));
97 97
 			$myPublicKey = $cryptTool->hex2bin(Common::getPublicKey(Constants::myPublicKey));
98 98
 
@@ -167,14 +167,14 @@  discard block
 block discarded – undo
167 167
 				$timeElapsed = [];
168 168
 				$comparisonResult = [];
169 169
 				$timeElapsedAvg = [];
170
-				foreach(array(
171
-					'length' => [$string1, $string1 . 'a'],
170
+				foreach (array(
171
+					'length' => [$string1, $string1.'a'],
172 172
 					'diff' => [$string1, $string2],
173 173
 					'same' => [$string1, $string1]
174 174
 				) as $testName => $strings) {
175 175
 					$timeMin = [null, 0];
176 176
 					$timeMax = [null, 0];
177
-					for ($i=0; $i < 3; $i++) {
177
+					for ($i = 0; $i < 3; $i++) {
178 178
 						// test run with delay
179 179
 						$timeElapsed[$testName][$i] = -microtime(true);
180 180
 						$comparisonResult[$testName][$i] = $cryptTool->stringCompare($strings[0], $strings[1]);
@@ -207,13 +207,13 @@  discard block
 block discarded – undo
207 207
 					array_splice($timeElapsed[$testName], $timeMax[1] >= $timeMin[1] ? ($timeMax[1]-1) : $timeMax[1], 1);
208 208
 
209 209
 					// calculate average (currently useless as there is only one value left, but it may be useful later)
210
-					$timeElapsedAvg[$testName] = array_sum($timeElapsed[$testName]) / count($timeElapsed[$testName]);
210
+					$timeElapsedAvg[$testName] = array_sum($timeElapsed[$testName])/count($timeElapsed[$testName]);
211 211
 				}
212 212
 
213 213
 				// check timings
214 214
 				echo 'Timing test results with '.$prefix.':'.PHP_EOL;
215
-				$timingRatio = $timeElapsedAvg['diff'] / $timeElapsedAvg['same'];
216
-				$absoluteDifference = abs($timeElapsedAvg['diff'] - $timeElapsedAvg['same']);
215
+				$timingRatio = $timeElapsedAvg['diff']/$timeElapsedAvg['same'];
216
+				$absoluteDifference = abs($timeElapsedAvg['diff']-$timeElapsedAvg['same']);
217 217
 				echo 'timing ratio: '.$timingRatio.PHP_EOL;
218 218
 				echo 'absolute difference: '.$absoluteDifference.PHP_EOL;
219 219
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 				$allowedDifferenceLow = 0.25;
222 222
 				$allowedDifferenceTop = 0.5;
223 223
 				// double value if running in a CI envoriment
224
-				if (getenv('CI') == 'true')	{
224
+				if (getenv('CI') == 'true') {
225 225
 					$allowedDifferenceLow = $allowedDifferenceLow*2;
226 226
 					$allowedDifferenceTop = $allowedDifferenceTop*2;
227 227
 				}
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	 */
240 240
 	public function testRemoveVar() {
241 241
 		$this->doTest(function(CryptTool $cryptTool, $prefix) {
242
-			foreach(array(
242
+			foreach (array(
243 243
 						'hex' => Constants::myPrivateKeyExtract,
244 244
 						'bin' => $cryptTool->hex2bin(Constants::myPrivateKeyExtract)
245 245
 					) as $key => $testVar) {
@@ -253,12 +253,12 @@  discard block
 block discarded – undo
253 253
 	}
254 254
 
255 255
 	private function doTest(\Closure $c) {
256
-		foreach(array(
256
+		foreach (array(
257 257
 					'Salt' => CryptTool::createInstance(CryptTool::TYPE_SALT),
258 258
 					'Sodium' => CryptTool::createInstance(CryptTool::TYPE_SODIUM)
259 259
 				) as $key => $instance) {
260 260
 
261
-			if($instance === null) {
261
+			if ($instance === null) {
262 262
 				echo $key.": could not instance crypt tool\n";
263 263
 				break;
264 264
 			}
Please login to merge, or discard this patch.