Test Setup Failed
Push — master ( 97674e...cd6248 )
by Kevin
01:39
created
src/Helpers/PrimaryKeyRegistry.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
         $this->values = [];
52 52
         $colNames = implode(",", $this->columns);
53 53
         $rows = $this->connection->query("SELECT $colNames FROM " . $this->table->getName())->fetchAll();
54
-        foreach ($rows as $row){
54
+        foreach ($rows as $row) {
55 55
             $pk = [];
56
-            foreach ($this->columns as $column){
56
+            foreach ($this->columns as $column) {
57 57
                 $pk[$column] = $row[$column];
58 58
             }
59 59
             $this->values[] = $pk;
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
     {
72 72
         $keys = array_keys($value);
73 73
         sort($keys);
74
-        if ($this->columns == $keys){
74
+        if ($this->columns == $keys) {
75 75
             throw new PrimaryKeyColumnMismatchException("PrimaryKeys do not match between PKStore and addValue");
76 76
         }
77 77
         $this->values[] = $value;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function getRandomValue() : array
84 84
     {
85
-        return $this->values[random_int(0, count($this->values) -1)];
85
+        return $this->values[random_int(0, count($this->values) - 1)];
86 86
     }
87 87
 
88 88
     /**
Please login to merge, or discard this patch.
src/Generators/ComplexObjectGenerator.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -41,11 +41,11 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function __invoke(Column $column)
43 43
     {
44
-        if ($this->depth === null){
44
+        if ($this->depth === null) {
45 45
             $this->depth = random_int(2, 5);
46 46
         }
47 47
         $object = $this->generateRandomObject($this->depth);
48
-        if ($this->toArray){
48
+        if ($this->toArray) {
49 49
             $object = json_decode(json_encode($object, JSON_OBJECT_AS_ARRAY), true);
50 50
         }
51 51
         return $object;
@@ -60,13 +60,13 @@  discard block
 block discarded – undo
60 60
         $obj = new \stdClass();
61 61
         $nbProps = random_int(2, 5);
62 62
         $hasGoneDeeper = false;
63
-        for ($i = 0; $i < $nbProps; $i++){
63
+        for ($i = 0; $i < $nbProps; $i++) {
64 64
             $propName = $this->randomPropName();
65
-            $goDeeper = $depth != 0 && (random_int(0,10) > 7 || !$hasGoneDeeper);
66
-            if ($goDeeper){
65
+            $goDeeper = $depth != 0 && (random_int(0, 10) > 7 || !$hasGoneDeeper);
66
+            if ($goDeeper) {
67 67
                 $hasGoneDeeper = true;
68 68
                 $value = $this->generateRandomObject($depth - 1);
69
-            }else{
69
+            }else {
70 70
                 $value = $this->randomValue();
71 71
             }
72 72
             $obj->$propName = $value;
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@
 block discarded – undo
66 66
             if ($goDeeper){
67 67
                 $hasGoneDeeper = true;
68 68
                 $value = $this->generateRandomObject($depth - 1);
69
-            }else{
69
+            } else{
70 70
                 $value = $this->randomValue();
71 71
             }
72 72
             $obj->$propName = $value;
Please login to merge, or discard this patch.
test.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@  discard block
 block discarded – undo
19 19
 /* Don't hesitate to use the Faker package to generate random data,
20 20
    there is plenty of data types available (IBAN, address, country code, ...).
21 21
 */
22
-$dataFaker = \Faker\Factory::create();//you could pass the locale to generate localized data !
22
+$dataFaker = \Faker\Factory::create(); //you could pass the locale to generate localized data !
23 23
 
24 24
 // address.postal_code column is a varchar, so default generated data will be text. Here we want a postal code :
25 25
 $generatorFinderBuilder->addGenerator(
26
-    new \DBFaker\Generators\Conditions\CallBackCondition(function(\Doctrine\DBAL\Schema\Table $table,  \Doctrine\DBAL\Schema\Column $column){
26
+    new \DBFaker\Generators\Conditions\CallBackCondition(function(\Doctrine\DBAL\Schema\Table $table, \Doctrine\DBAL\Schema\Column $column) {
27 27
         return $table->getName() == "address" && $column->getName() == "postal_code";
28 28
     }),
29 29
     function() use ($dataFaker){
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
 // all columns that end with "_email" or are named exactly "email" should be emails
35 35
 $generatorFinderBuilder->addGenerator(
36
-    new \DBFaker\Generators\Conditions\CallBackCondition(function(\Doctrine\DBAL\Schema\Table $table,  \Doctrine\DBAL\Schema\Column $column){
36
+    new \DBFaker\Generators\Conditions\CallBackCondition(function(\Doctrine\DBAL\Schema\Table $table, \Doctrine\DBAL\Schema\Column $column) {
37 37
         return preg_match("/([(.*_)|_|]|^)email$/", $column->getName()) === 1;
38 38
     }),
39 39
     function() use ($dataFaker){
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
     "community_spending" => 100,
50 50
     "cron_flag" => 10,
51 51
     "project" => 50,
52
-    "project_note" => 200 ,
52
+    "project_note" => 200,
53 53
     "project_steps" => 10,
54 54
     "project_tasks" => 35,
55 55
     "request_hollidays" => 20,
Please login to merge, or discard this patch.
tests/DBFakerTest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             ->column("population")->bigInt()
61 61
             ->column("birthrate")->float()
62 62
             ->column("president_id")->references("persons")
63
-            ->column("population_density")->decimal(10,2)
63
+            ->column("population_density")->decimal(10, 2)
64 64
             ->column("summary")->text();
65 65
 
66 66
         $users->column("country_id")->references("countries");
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
         /* Don't hesitate to use the Faker package to generate random data,
104 104
            there is plenty of data types available (IBAN, address, country code, ...).
105 105
         */
106
-        $dataFaker = \Faker\Factory::create();//you could pass the locale to generate localized data !
106
+        $dataFaker = \Faker\Factory::create(); //you could pass the locale to generate localized data !
107 107
 
108 108
         // address.postal_code column is a varchar, so default generated data will be text. Here we want a postal code :
109 109
         $generatorFinderBuilder->addGenerator(
110
-            new \DBFaker\Generators\Conditions\CallBackCondition(function(\Doctrine\DBAL\Schema\Table $table,  \Doctrine\DBAL\Schema\Column $column){
110
+            new \DBFaker\Generators\Conditions\CallBackCondition(function(\Doctrine\DBAL\Schema\Table $table, \Doctrine\DBAL\Schema\Column $column) {
111 111
                 return $table->getName() == "address" && $column->getName() == "postal_code";
112 112
             }),
113 113
             new SimpleGenerator(
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 
120 120
         // all columns that end with "_email" or are named exactly "email" should be emails
121 121
         $generatorFinderBuilder->addGenerator(
122
-            new CallBackCondition(function(\Doctrine\DBAL\Schema\Table $table,  \Doctrine\DBAL\Schema\Column $column){
122
+            new CallBackCondition(function(\Doctrine\DBAL\Schema\Table $table, \Doctrine\DBAL\Schema\Column $column) {
123 123
                 return preg_match("/([(.*_)|_|]|^)email$/", $column->getName()) === 1;
124 124
             }),
125 125
             new SimpleGenerator(
Please login to merge, or discard this patch.
tests/Generators/Conditions/CheckTypeConditionTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
 
9 9
 class CheckTypeConditionTest extends TestCase
10 10
 {
11
-    public function testCanApply(){
11
+    public function testCanApply() {
12 12
         $table = new Table("foo");
13 13
         $column = new Column("bar", Type::getType(Type::DECIMAL));
14 14
 
Please login to merge, or discard this patch.
src/Helpers/NumericColumnLimitHelper.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -34,10 +34,10 @@  discard block
 block discarded – undo
34 34
      */
35 35
     public function __construct(Column $column)
36 36
     {
37
-        if (array_search($column->getType()->getName(), self::$handledNumberTypes) === false){
37
+        if (array_search($column->getType()->getName(), self::$handledNumberTypes) === false) {
38 38
             throw new UnsupportedDataTypeException("Unsupported column type : " .
39 39
                 $column->getType()->getName() . "only " .
40
-                implode("', '", self::$handledNumberTypes) ." types are supported."
40
+                implode("', '", self::$handledNumberTypes) . " types are supported."
41 41
             );
42 42
         }
43 43
         $this->column = $column;
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     public function getMinNumericValue()
51 51
     {
52 52
         $precisionValue = $this->getAbsValueByLengthPrecision($this->column);
53
-        switch ($this->column->getType()->getName()){
53
+        switch ($this->column->getType()->getName()) {
54 54
             case Type::BIGINT:
55 55
                 return $this->column->getUnsigned() ? 0 : bcpow(2, 63);
56 56
                 break;
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     public function getMaxNumericValue()
77 77
     {
78 78
         $precisionValue = $this->getAbsValueByLengthPrecision($this->column);
79
-        switch ($this->column->getType()->getName()){
79
+        switch ($this->column->getType()->getName()) {
80 80
             case Type::BIGINT:
81 81
                 return $this->column->getUnsigned() ? bcpow(2, 64) : bcpow(2, 63) - 1;
82 82
             case Type::INTEGER:
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
      */
97 97
     private function getAbsValueByLengthPrecision(Column $column)
98 98
     {
99
-        switch ($column->getType()->getName()){
99
+        switch ($column->getType()->getName()) {
100 100
             case Type::DECIMAL:
101 101
                 $str = str_repeat(9, $column->getScale());
102 102
                 return (double) substr_replace($str, ".", $column->getScale() - $column->getPrecision(), 0);
Please login to merge, or discard this patch.
src/DBFaker.php 2 patches
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
      */
93 93
     public function fakeDB() : void
94 94
     {
95
-        set_time_limit(0);//Import may take a looooong time
95
+        set_time_limit(0); //Import may take a looooong time
96 96
         $this->generateFakeData();
97 97
         $this->dropForeignKeys();
98 98
         $this->insertFakeData();
@@ -125,17 +125,17 @@  discard block
 block discarded – undo
125 125
             foreach ($table->getColumns() as $column) {
126 126
                 //Check column isn't a PK : PK will be set automatically (NO UUID support)
127 127
                 if (array_search($column->getName(), $table->getPrimaryKeyColumns()) !== false) {
128
-                    if ($column->getAutoincrement()){
128
+                    if ($column->getAutoincrement()) {
129 129
                         $value = null;
130
-                    }else{
130
+                    }else {
131 131
                         return $this->getUniqueValue($table, $column);
132 132
                     }
133 133
                 }
134 134
                 //Other data will be Faked depending of column's type and attributes
135 135
                 else {
136
-                    if (!$column->getNotnull() && $this->nullProbabilityOccured()){
136
+                    if (!$column->getNotnull() && $this->nullProbabilityOccured()) {
137 137
                         $value = null;
138
-                    }else{
138
+                    }else {
139 139
                         $value = $this->generatorFinder->findGenerator($table, $column)($column);
140 140
                     }
141 141
                 }
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
     {
155 155
         $this->foreignKeyStore = [];
156 156
         $tables = $this->schemaManager->listTables();
157
-        foreach ($tables as $table){
158
-            foreach ($table->getForeignKeys() as $fk){
157
+        foreach ($tables as $table) {
158
+            foreach ($table->getForeignKeys() as $fk) {
159 159
                 $this->foreignKeyStore[$table->getName()][] = $fk;
160 160
                 $this->schemaManager->dropForeignKey($fk, $table);
161 161
             }
@@ -167,8 +167,8 @@  discard block
 block discarded – undo
167 167
      */
168 168
     private function restoreForeignKeys() : void
169 169
     {
170
-        foreach ($this->foreignKeyStore as $tableName => $fks){
171
-            foreach ($fks as $fk){
170
+        foreach ($this->foreignKeyStore as $tableName => $fks) {
171
+            foreach ($fks as $fk) {
172 172
                 $this->schemaManager->createForeignKey($fk, $tableName);
173 173
             }
174 174
         }
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
     {
184 184
         $plateform = $this->connection->getDatabasePlatform();
185 185
         //1 - First insert data with no FKs, and null PKs. This will generate primary keys
186
-        foreach ($this->data as $tableName => $rows){
186
+        foreach ($this->data as $tableName => $rows) {
187 187
             $table = $this->schemaManager->listTableDetails($tableName);
188 188
 
189 189
             //initiate column types for insert
190 190
             $types = [];
191 191
             $first = reset($rows);
192
-            if ($first){
193
-                foreach ($first as $columnName => $value){
192
+            if ($first) {
193
+                foreach ($first as $columnName => $value) {
194 194
                     /** @var $column Column */
195 195
                     $column = $table->getColumn($columnName);
196 196
                     $types[] = $column->getType()->getBindingType();
@@ -198,9 +198,9 @@  discard block
 block discarded – undo
198 198
             }
199 199
 
200 200
             //insert faked data
201
-            foreach ($rows as $row){
201
+            foreach ($rows as $row) {
202 202
                 $dbRow = [];
203
-                foreach ($row as $columnName => $value){
203
+                foreach ($row as $columnName => $value) {
204 204
                     $column = $table->getColumn($columnName);
205 205
                     $newVal = $column->getType()->convertToDatabaseValue($value, $plateform);
206 206
                     $dbRow[$columnName] = $newVal;
@@ -213,8 +213,8 @@  discard block
 block discarded – undo
213 213
         }
214 214
 
215 215
         //2 - loop again on table to set FKs now that all PK have been loaded
216
-        foreach ($this->foreignKeyStore as $tableName => $fks){
217
-            if (array_search($tableName, array_keys($this->fakeTableRowNumbers)) === false){
216
+        foreach ($this->foreignKeyStore as $tableName => $fks) {
217
+            if (array_search($tableName, array_keys($this->fakeTableRowNumbers)) === false) {
218 218
                 //only update tables where data has been inserted
219 219
                 continue;
220 220
             }
@@ -230,11 +230,11 @@  discard block
 block discarded – undo
230 230
              * foreign tables' PKRegistries will provide final values for local FKs columns
231 231
              */
232 232
             $fkInfo = [];
233
-            foreach ($fks as $fk){
233
+            foreach ($fks as $fk) {
234 234
                 $localColums = $fk->getLocalColumns();
235 235
                 $foreignColumns = $fk->getForeignColumns();
236 236
                 $foreignTable = $this->schemaManager->listTableDetails($fk->getForeignTableName());
237
-                foreach ($localColums as $index => $localColumn){
237
+                foreach ($localColums as $index => $localColumn) {
238 238
                     $foreignColumn = $foreignColumns[$index];
239 239
                     $fkInfo[$localColumn] = [
240 240
                         "table" => $foreignTable,
@@ -245,9 +245,9 @@  discard block
 block discarded – undo
245 245
 
246 246
             //Get all the PKs in the table (ie all the lines to update), and update the FKs with random PK values
247 247
             $pkValues = $this->getPkRegistry($table)->loadValuesFromTable()->getAllValues();
248
-            foreach ($pkValues as $pkValue){
248
+            foreach ($pkValues as $pkValue) {
249 249
                 $newValues = [];
250
-                foreach ($fkInfo as $localColumn => $foreignData){
250
+                foreach ($fkInfo as $localColumn => $foreignData) {
251 251
                     $foreignTable = $foreignData["table"];
252 252
                     $foreignColumn = $foreignData["column"];
253 253
                     $fkPkRegistry = $this->getPkRegistry($foreignTable);
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
                 if (array_search($column->getName(), $table->getPrimaryKeyColumns()) !== false) {
128 128
                     if ($column->getAutoincrement()){
129 129
                         $value = null;
130
-                    }else{
130
+                    } else{
131 131
                         return $this->getUniqueValue($table, $column);
132 132
                     }
133 133
                 }
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
                 else {
136 136
                     if (!$column->getNotnull() && $this->nullProbabilityOccured()){
137 137
                         $value = null;
138
-                    }else{
138
+                    } else{
139 139
                         $value = $this->generatorFinder->findGenerator($table, $column)($column);
140 140
                     }
141 141
                 }
Please login to merge, or discard this patch.
src/Generators/NumericGenerator.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
         $inspector = new NumericColumnLimitHelper($column);
26 26
         $min = $inspector->getMinNumericValue();
27 27
         $max = $inspector->getMaxNumericValue();
28
-        switch ($column->getType()->getName()){
28
+        switch ($column->getType()->getName()) {
29 29
             case Type::BIGINT:
30 30
                 return $this->bigRandomNumber($min, $max);
31 31
             case Type::INTEGER:
@@ -35,12 +35,12 @@  discard block
 block discarded – undo
35 35
             case Type::FLOAT:
36 36
                 return $this->faker->randomFloat(10, $min, $max);
37 37
             default:
38
-                throw new UnsupportedDataTypeException("Cannot generate numeric value for Type : '".$column->getType()->getName()."'");
38
+                throw new UnsupportedDataTypeException("Cannot generate numeric value for Type : '" . $column->getType()->getName() . "'");
39 39
         }
40 40
     }
41 41
 
42 42
     private function bigRandomNumber($min, $max) {
43
-        $difference   = bcadd(bcsub($max,$min),1);
43
+        $difference   = bcadd(bcsub($max, $min), 1);
44 44
         $rand_percent = bcdiv(mt_rand(), mt_getrandmax(), 8); // 0 - 1.0
45 45
         return bcadd($min, bcmul($difference, $rand_percent, 8), 0);
46 46
     }
Please login to merge, or discard this patch.
src/Generators/BlobGenerator.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,11 +20,11 @@
 block discarded – undo
20 20
     public function __invoke(Column $column)
21 21
     {
22 22
         $files = glob($this->globExpression, GLOB_MARK);
23
-        $files = array_filter($files, function ($fileName){
23
+        $files = array_filter($files, function($fileName) {
24 24
             return strrpos($fileName, DIRECTORY_SEPARATOR) !== strlen($fileName) - 1;
25 25
         });
26
-        if (count($files) == 0){
27
-            throw new NoTestFilesFoundException("No files found for glob expression '".$this->globExpression."'");
26
+        if (count($files) == 0) {
27
+            throw new NoTestFilesFoundException("No files found for glob expression '" . $this->globExpression . "'");
28 28
         }
29 29
         $files = array_values($files);
30 30
         $chosenFile = $files[random_int(0, count($files) - 1)];
Please login to merge, or discard this patch.