Completed
Push — master ( 21fef4...f7e2e6 )
by Tomasz
05:34
created
tests/Gendoria/CruftFlake/Config/DoctrineConfigTest.php 2 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -10,8 +10,6 @@
 block discarded – undo
10 10
 
11 11
 use Doctrine\DBAL\Connection;
12 12
 use Doctrine\DBAL\DriverManager;
13
-use Doctrine\DBAL\Schema\Schema;
14
-use Doctrine\DBAL\Types\Type;
15 13
 use PDO;
16 14
 use PHPUnit_Extensions_Database_TestCase;
17 15
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -136,7 +136,7 @@
 block discarded – undo
136 136
         $conn = $this->getDatabaseTester()->getConnection();
137 137
         
138 138
         $machines = array();
139
-        for ($k=0; $k<1024; $k++) {
139
+        for ($k = 0; $k < 1024; $k++) {
140 140
             $machines[$k] = new DoctrineConfig($this->connection);
141 141
             $this->assertEquals($k, $machines[$k]->getMachine());
142 142
         }
Please login to merge, or discard this patch.
tests/Gendoria/CruftFlake/GeneratorTest.php 3 patches
Doc Comments   +8 added lines patch added patch discarded remove patch
@@ -57,6 +57,7 @@  discard block
 block discarded – undo
57 57
     /**
58 58
      * Get generator for normal tests.
59 59
      * 
60
+     * @param integer $newMachineId
60 61
      * @return Generator
61 62
      */
62 63
     private function buildSystemUnderTestHeartbeat($newMachineId)
@@ -70,12 +71,19 @@  discard block
 block discarded – undo
70 71
         return new Generator($this->config, $this->timer);
71 72
     }
72 73
         
74
+    /**
75
+     * @param string $id
76
+     */
73 77
     private function assertId($id)
74 78
     {
75 79
         $this->assertTrue(is_string($id));
76 80
         $this->assertTrue(ctype_digit($id));
77 81
     }
78 82
     
83
+    /**
84
+     * @param string $v1
85
+     * @param string $v2
86
+     */
79 87
     private function assertReallyNotEquals($v1, $v2)
80 88
     {
81 89
         $this->assertTrue($v1 !== $v2);
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
     private function buildSystemUnderTest()
33 33
     {
34 34
         $this->config->expects($this->once())
35
-                     ->method('getMachine')
36
-                     ->will($this->returnValue($this->machineId));
35
+                        ->method('getMachine')
36
+                        ->will($this->returnValue($this->machineId));
37 37
         return new Generator($this->config, $this->timer);
38 38
     }
39 39
     
@@ -45,8 +45,8 @@  discard block
 block discarded – undo
45 45
     private function buildSystemUnderTest32Bit()
46 46
     {
47 47
         $this->config->expects($this->once())
48
-                     ->method('getMachine')
49
-                     ->will($this->returnValue($this->machineId));
48
+                        ->method('getMachine')
49
+                        ->will($this->returnValue($this->machineId));
50 50
         $generator = $this->getMock('Gendoria\CruftFlake\Generator\Generator', array('is32Bit'), array($this->config, $this->timer));
51 51
         $generator->expects($this->any())
52 52
             ->method('is32Bit')
@@ -62,11 +62,11 @@  discard block
 block discarded – undo
62 62
     private function buildSystemUnderTestHeartbeat($newMachineId)
63 63
     {
64 64
         $this->config->expects($this->exactly(2))
65
-                     ->method('getMachine')
66
-                     ->will($this->onConsecutiveCalls($this->machineId, $newMachineId));
65
+                        ->method('getMachine')
66
+                        ->will($this->onConsecutiveCalls($this->machineId, $newMachineId));
67 67
         $this->config->expects($this->once())
68
-                     ->method('heartbeat')
69
-                     ->will($this->returnValue(true));
68
+                        ->method('heartbeat')
69
+                        ->will($this->returnValue(true));
70 70
         return new Generator($this->config, $this->timer);
71 71
     }
72 72
         
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
         $cf = $this->buildSystemUnderTest();
179 179
         
180 180
         $ids = array();
181
-        for ($i=0; $i<4095; $i++) {
181
+        for ($i = 0; $i < 4095; $i++) {
182 182
             $id = $cf->generate();
183 183
             $ids[$id] = 1;
184 184
         }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
         $cf = $this->buildSystemUnderTest();
195 195
         
196 196
         $ids = array();
197
-        for ($i=0; $i<4096; $i++) {
197
+        for ($i = 0; $i < 4096; $i++) {
198 198
             $id = $cf->generate();
199 199
             $ids[$id] = 1;
200 200
         }
Please login to merge, or discard this patch.
tests/bootstrap.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 call_user_func(function() {
4
-    if (!is_file($autoloadFile = __DIR__ . '/../vendor/autoload.php')) {
4
+    if (!is_file($autoloadFile = __DIR__.'/../vendor/autoload.php')) {
5 5
         throw new LogicException('Could not find vendor/autoload.php. Did you forget to run "composer install --dev"?');
6 6
     }
7 7
     require $autoloadFile;
Please login to merge, or discard this patch.
tests/Gendoria/CruftFlake/LocalClientTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,6 +48,6 @@
 block discarded – undo
48 48
         $status = $cf->status();
49 49
         
50 50
         $this->assertInstanceOf('Gendoria\CruftFlake\Generator\GeneratorStatus', $status);
51
-        $this->assertEquals(1,  $status->sequence);
51
+        $this->assertEquals(1, $status->sequence);
52 52
     }
53 53
 }
Please login to merge, or discard this patch.
tests/Gendoria/CruftFlake/Config/ConsulConfigTest.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
                 static $invCount = 0;
309 309
                 if ($url == '/kv/'.$kvPrefix.'?acquire='.$sessionId.'&flags=0') {
310 310
                     return true;
311
-                } elseif($url == '/session/renew') {
311
+                } elseif ($url == '/session/renew') {
312 312
                     return false;
313 313
                 } elseif ($url == '/session/create') {
314 314
                     if ($invCount == 0) {
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
                 static $invCount = 0;
340 340
                 if ($url == '/kv/'.$kvPrefix.'?acquire='.$sessionId.'&flags=0') {
341 341
                     return true;
342
-                } elseif($url == '/session/renew') {
342
+                } elseif ($url == '/session/renew') {
343 343
                     return false;
344 344
                 } elseif ($url == '/session/create') {
345 345
                     if ($invCount == 0) {
Please login to merge, or discard this patch.
src/Gendoria/CruftFlake/Config/DoctrineConfig.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
     public function heartbeat()
111 111
     {
112 112
         //If we have last successfull check recently new, we don't have to do anything
113
-        if ($this->lastSuccessfullCheck !== null && time() - $this->lastSuccessfullCheck < $this->sessionTTL / 2) {
113
+        if ($this->lastSuccessfullCheck !== null && time()-$this->lastSuccessfullCheck < $this->sessionTTL / 2) {
114 114
             return false;
115 115
         }
116 116
         
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
      */
244 244
     private function gc()
245 245
     {
246
-        $lastAccess = time() - $this->sessionTTL;
246
+        $lastAccess = time()-$this->sessionTTL;
247 247
         $qb = $this->connection->createQueryBuilder();
248 248
         $qb->delete($this->tableName)
249 249
             ->where('last_access < ?')
Please login to merge, or discard this patch.
src/Gendoria/CruftFlake/Config/ConsulConfig.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     {
78 78
         $this->curl = $curl;
79 79
         $this->kvPrefix = $kvPrefix;
80
-        $this->sessionTTL = (int)$sessionTTL;
80
+        $this->sessionTTL = (int) $sessionTTL;
81 81
         //If we cannot connect to Consul on start, we have a problem.
82 82
         $this->createSession();
83 83
         $this->lastSuccessfullCheck = time();
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
     public function heartbeat()
115 115
     {
116 116
         //If we have last successfull check recently new, we don't have to do anything
117
-        if ($this->lastSuccessfullCheck !== null && time() - $this->lastSuccessfullCheck < $this->sessionTTL / 2 ) {
117
+        if ($this->lastSuccessfullCheck !== null && time()-$this->lastSuccessfullCheck < $this->sessionTTL / 2) {
118 118
             return false;
119 119
         }
120 120
         //If session reneval succeedes, update last successfull check.
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
         } catch (RuntimeException $e) {
132 132
             //We could not create new session. We can work for some time in 'detached' mode,
133 133
             //but if our TTL time runs out, we have to throw an exception.
134
-            if ($this->lastSuccessfullCheck === null || time() - $this->lastSuccessfullCheck >= $this->sessionTTL) {
134
+            if ($this->lastSuccessfullCheck === null || time()-$this->lastSuccessfullCheck >= $this->sessionTTL) {
135 135
                 throw $e;
136 136
             }
137 137
             return false;
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         //Check, if we don't have existing value for the session
150 150
         $currentValue = $this->curl->performGetRequest('/kv/'.$this->kvPrefix.$this->sessionId);
151 151
         if (!empty($currentValue['Value'])) {
152
-            return (int)base64_decode($currentValue['Value']);
152
+            return (int) base64_decode($currentValue['Value']);
153 153
         }
154 154
         //Lock main key to block concurrent checks
155 155
         $this->lockKey();
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         }
165 165
         //Release the lock on the main key and return machine ID.
166 166
         $this->releaseKey();
167
-        return (int)$machineId;
167
+        return (int) $machineId;
168 168
     }
169 169
     
170 170
     /**
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
             if ($currentValue['Key'] == $this->kvPrefix) {
182 182
                 continue;
183 183
             } elseif ($currentValue['Key'] == $this->sessionId) {
184
-                return (int)base64_decode($currentValue['Value']);
184
+                return (int) base64_decode($currentValue['Value']);
185 185
             }
186 186
             else {
187
-                $usedIds[] = (int)base64_decode($currentValue['Value']);
187
+                $usedIds[] = (int) base64_decode($currentValue['Value']);
188 188
             }
189 189
         }
190 190
         for ($k = 0; $k < 1024; $k++) {
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
     private function lockKey()
202 202
     {
203 203
         //try to acquire the lock on prefix during whole operation.
204
-        $tryCount=0;
204
+        $tryCount = 0;
205 205
         do {
206 206
             $acquired = $this->curl->performPutRequest('/kv/'.$this->kvPrefix.'?acquire='.$this->sessionId."&flags=".$tryCount, $this->sessionId);
207 207
             if (!$acquired) {
@@ -226,12 +226,12 @@  discard block
 block discarded – undo
226 226
      */
227 227
     private function createSession()
228 228
     {
229
-        $url ='/session/create';
229
+        $url = '/session/create';
230 230
         //We create new session with given TTL and with lock delay equal to half of TTL.
231 231
         $payload = array(
232 232
             'TTL' => $this->sessionTTL.'s',
233 233
             "Behavior" => "delete",
234
-            'LockDelay' => floor($this->sessionTTL/2).'s',
234
+            'LockDelay' => floor($this->sessionTTL / 2).'s',
235 235
         );
236 236
         $returnData = $this->curl->performPutRequest($url, json_encode($payload));
237 237
         if (empty($returnData['ID'])) {
Please login to merge, or discard this patch.