Browse Source

Codestyle fixes (automatically)

Maurits van der Schee 7 years ago
parent
commit
857a0407d7
8 changed files with 129 additions and 99 deletions
  1. 49
    23
      tests/Api.php
  2. 8
    5
      tests/MysqlTest.php
  3. 13
    11
      tests/PostgresqlTest.php
  4. 3
    3
      tests/SqlServerTest.php
  5. 4
    4
      tests/SqliteTest.php
  6. 8
    9
      tests/TestBase.php
  7. 43
    43
      tests/Tests.php
  8. 1
    1
      tests/autoload.php

+ 49
- 23
tests/Api.php View File

@@ -29,11 +29,11 @@ class Api
29 29
         $this->config['dbengine'] = $test->getEngineName();
30 30
     }
31 31
 
32
-    private function action($method,$url,$data='')
32
+    private function action($method, $url, $data='')
33 33
     {
34 34
         $url = parse_url($url);
35 35
         $query = isset($url['query'])?$url['query']:'';
36
-        parse_str($query,$get);
36
+        parse_str($query, $get);
37 37
 
38 38
         $this->api = new \PHP_CRUD_API(array(
39 39
             'dbengine'=>$this->config['dbengine'],
@@ -42,14 +42,37 @@ class Api
42 42
             'password'=>$this->config['password'],
43 43
             'database'=>$this->config['database'],
44 44
             // callbacks
45
-            'table_authorizer'=>function($action,$database,$table) { return true; },
46
-            'column_authorizer'=>function($action,$database,$table,$column) { return !($column=='password'&&$action=='list'); },
47
-            'record_filter'=>function($action,$database,$table) { return ($table=='posts')?array('id,neq,13'):false; },
48
-            'tenancy_function'=>function($action,$database,$table,$column) { return ($table=='users'&&$column=='id')?1:null; },
49
-            'input_sanitizer'=>function($action,$database,$table,$column,$type,$value) { return is_string($value)?strip_tags($value):$value; },
50
-            'input_validator'=>function($action,$database,$table,$column,$type,$value,$context) { return ($column=='category_id' && !is_numeric($value))?'must be numeric':true; },
51
-            'before'=>function(&$action,&$database,&$table,&$id,&$input) { if ($table=='products') if ($action=='create') $input->created_at = '2013-12-11 10:09:08'; else if ($action=='delete') { $action='update'; $input = (object)array('deleted_at' => '2013-12-11 11:10:09'); } },
52
-            'after'=>function($action,$database,$table,$id,$input,$output) { file_put_contents('log.txt',var_export(array($action,$database,$table,$id,$input,$output),true),FILE_APPEND); },
45
+            'table_authorizer'=>function ($action, $database, $table) {
46
+                return true;
47
+            },
48
+            'column_authorizer'=>function ($action, $database, $table, $column) {
49
+                return !($column=='password'&&$action=='list');
50
+            },
51
+            'record_filter'=>function ($action, $database, $table) {
52
+                return ($table=='posts')?array('id,neq,13'):false;
53
+            },
54
+            'tenancy_function'=>function ($action, $database, $table, $column) {
55
+                return ($table=='users'&&$column=='id')?1:null;
56
+            },
57
+            'input_sanitizer'=>function ($action, $database, $table, $column, $type, $value) {
58
+                return is_string($value)?strip_tags($value):$value;
59
+            },
60
+            'input_validator'=>function ($action, $database, $table, $column, $type, $value, $context) {
61
+                return ($column=='category_id' && !is_numeric($value))?'must be numeric':true;
62
+            },
63
+            'before'=>function (&$action, &$database, &$table, &$id, &$input) {
64
+                if ($table=='products') {
65
+                    if ($action=='create') {
66
+                        $input->created_at = '2013-12-11 10:09:08';
67
+                    } elseif ($action=='delete') {
68
+                        $action='update';
69
+                        $input = (object)array('deleted_at' => '2013-12-11 11:10:09');
70
+                    }
71
+                }
72
+            },
73
+            'after'=>function ($action, $database, $table, $id, $input, $output) {
74
+                file_put_contents('log.txt', var_export(array($action,$database,$table,$id,$input,$output), true), FILE_APPEND);
75
+            },
53 76
             // for tests
54 77
             'method'=>$method,
55 78
             'request'=>$url['path'],
@@ -61,32 +84,32 @@ class Api
61 84
 
62 85
     public function get($url)
63 86
     {
64
-        return $this->action('GET',$url);
87
+        return $this->action('GET', $url);
65 88
     }
66 89
 
67
-    public function post($url,$data)
90
+    public function post($url, $data)
68 91
     {
69
-        return $this->action('POST',$url,$data);
92
+        return $this->action('POST', $url, $data);
70 93
     }
71 94
 
72
-    public function put($url,$data)
95
+    public function put($url, $data)
73 96
     {
74
-        return $this->action('PUT',$url,$data);
97
+        return $this->action('PUT', $url, $data);
75 98
     }
76 99
 
77 100
     public function delete($url)
78 101
     {
79
-        return $this->action('DELETE',$url);
102
+        return $this->action('DELETE', $url);
80 103
     }
81 104
 
82 105
     public function options($url)
83 106
     {
84
-        return $this->action('OPTIONS',$url);
107
+        return $this->action('OPTIONS', $url);
85 108
     }
86 109
 
87
-    public function patch($url,$data)
110
+    public function patch($url, $data)
88 111
     {
89
-        return $this->action('PATCH',$url,$data);
112
+        return $this->action('PATCH', $url, $data);
90 113
     }
91 114
 
92 115
     public function expectAny()
@@ -97,7 +120,7 @@ class Api
97 120
         return $this;
98 121
     }
99 122
 
100
-    public function expect($output,$error=false)
123
+    public function expect($output, $error=false)
101 124
     {
102 125
         $exception = false;
103 126
         ob_start();
@@ -108,8 +131,11 @@ class Api
108 131
         }
109 132
         $data = ob_get_contents();
110 133
         ob_end_clean();
111
-        if ($exception) $this->test->assertEquals($error, $exception);
112
-        else $this->test->assertEquals($output, $data);
134
+        if ($exception) {
135
+            $this->test->assertEquals($error, $exception);
136
+        } else {
137
+            $this->test->assertEquals($output, $data);
138
+        }
113 139
         return $this;
114 140
     }
115
-}
141
+}

+ 8
- 5
tests/MysqlTest.php View File

@@ -31,7 +31,7 @@ class MysqlTest extends Tests
31 31
             die("Connect failed: ".mysqli_connect_error()."\n");
32 32
         }
33 33
 
34
-        mysqli_set_charset($db,'utf8');
34
+        mysqli_set_charset($db, 'utf8');
35 35
 
36 36
         return $db;
37 37
     }
@@ -92,16 +92,19 @@ class MysqlTest extends Tests
92 92
         $contents = file_get_contents($fixture);
93 93
 
94 94
         if (!($capabilities & self::GIS)) {
95
-            $contents = preg_replace('/(POINT|POLYGON) NOT NULL/i','text NOT NULL',$contents);
96
-            $contents = preg_replace('/ST_GeomFromText/i','concat',$contents);
95
+            $contents = preg_replace('/(POINT|POLYGON) NOT NULL/i', 'text NOT NULL', $contents);
96
+            $contents = preg_replace('/ST_GeomFromText/i', 'concat', $contents);
97 97
         }
98 98
         if (!($capabilities & self::JSON)) {
99
-            $contents = preg_replace('/JSON NOT NULL/i','text NOT NULL',$contents);
99
+            $contents = preg_replace('/JSON NOT NULL/i', 'text NOT NULL', $contents);
100 100
         }
101 101
 
102 102
         $i=0;
103 103
         if (mysqli_multi_query($db, $contents)) {
104
-            do { $i++; mysqli_next_result($db); } while (mysqli_more_results($db));
104
+            do {
105
+                $i++;
106
+                mysqli_next_result($db);
107
+            } while (mysqli_more_results($db));
105 108
         }
106 109
 
107 110
         if (mysqli_errno($db)) {

+ 13
- 11
tests/PostgresqlTest.php View File

@@ -20,7 +20,9 @@ class PostgresqlTest extends Tests
20 20
      */
21 21
     public function connect($config)
22 22
     {
23
-        $e = function ($v) { return str_replace(array('\'','\\'),array('\\\'','\\\\'),$v); };
23
+        $e = function ($v) {
24
+            return str_replace(array('\'','\\'), array('\\\'','\\\\'), $v);
25
+        };
24 26
         $hostname = $e($config['hostname']);
25 27
         $database = $e($config['database']);
26 28
         $username = $e($config['username']);
@@ -50,7 +52,7 @@ class PostgresqlTest extends Tests
50 52
         $major = 9;
51 53
         $minor = 1;
52 54
         $version = pg_version();
53
-        $v = explode('.',$version['server']);
55
+        $v = explode('.', $version['server']);
54 56
         if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor)) {
55 57
             die("Detected PostgreSQL $v[0].$v[1], but only $major.$minor and up are supported\n");
56 58
         }
@@ -67,15 +69,15 @@ class PostgresqlTest extends Tests
67 69
         $major = 9;
68 70
         $minor = 4;
69 71
         $version = pg_version();
70
-        $v = explode('.',$version['server']);
72
+        $v = explode('.', $version['server']);
71 73
         if ($v[0]>$major || ($v[0]==$major && $v[1]>=$minor)) {
72 74
             $capabilities |= self::JSON;
73 75
         }
74 76
         $extensions = pg_fetch_all(pg_query($db, "SELECT * FROM pg_extension;"));
75 77
         foreach ($extensions as $extension) {
76
-          if ($extension['extname'] === 'postgis') {
77
-            $capabilities |= self::GIS;
78
-          }
78
+            if ($extension['extname'] === 'postgis') {
79
+                $capabilities |= self::GIS;
80
+            }
79 81
         }
80 82
         return $capabilities;
81 83
     }
@@ -85,17 +87,17 @@ class PostgresqlTest extends Tests
85 87
      *
86 88
      * @return void
87 89
      */
88
-    public function seedDatabase($db,$capabilities)
90
+    public function seedDatabase($db, $capabilities)
89 91
     {
90 92
         $fixture = __DIR__.'/data/blog_postgresql.sql';
91 93
         $contents = file_get_contents($fixture);
92 94
 
93 95
         if (!($capabilities & self::GIS)) {
94
-            $contents = preg_replace('/(geometry) NOT NULL/i','text NOT NULL',$contents);
95
-            $contents = preg_replace('/ST_GeomFromText/i','concat',$contents);
96
+            $contents = preg_replace('/(geometry) NOT NULL/i', 'text NOT NULL', $contents);
97
+            $contents = preg_replace('/ST_GeomFromText/i', 'concat', $contents);
96 98
         }
97 99
         if (!($capabilities & self::JSON)) {
98
-            $contents = preg_replace('/JSONB? NOT NULL/i','text NOT NULL',$contents);
100
+            $contents = preg_replace('/JSONB? NOT NULL/i', 'text NOT NULL', $contents);
99 101
         }
100 102
 
101 103
         $queries = preg_split('/;\s*\n/', $contents);
@@ -104,7 +106,7 @@ class PostgresqlTest extends Tests
104 106
         foreach ($queries as $i=>$query) {
105 107
             if (!pg_query($db, $query.';')) {
106 108
                 $i++;
107
-                die("Loading '$fixture' failed on statemement #$i with error:\n".print_r( pg_last_error($db), true)."\n");
109
+                die("Loading '$fixture' failed on statemement #$i with error:\n".print_r(pg_last_error($db), true)."\n");
108 110
             }
109 111
         }
110 112
     }

+ 3
- 3
tests/SqlServerTest.php View File

@@ -30,7 +30,7 @@ class SqlServerTest extends Tests
30 30
         $db = sqlsrv_connect($config['hostname'], $connectionInfo);
31 31
 
32 32
         if (!$db) {
33
-            die("Connect failed: ".print_r( sqlsrv_errors(), true));
33
+            die("Connect failed: ".print_r(sqlsrv_errors(), true));
34 34
         }
35 35
 
36 36
         return $db;
@@ -57,7 +57,7 @@ class SqlServerTest extends Tests
57 57
         $minor = 0;
58 58
         $build = 3000;
59 59
         $version = sqlsrv_server_info($db);
60
-        $v = explode('.',$version['SQLServerVersion']);
60
+        $v = explode('.', $version['SQLServerVersion']);
61 61
         if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor) || ($v[0]==$major && $v[1]==$minor && $v[2]<$build)) {
62 62
             die("Detected SQL Server $v[0].$v[1].$v[2], but only $major.$minor.$build and up are supported\n");
63 63
         }
@@ -93,7 +93,7 @@ class SqlServerTest extends Tests
93 93
         foreach ($queries as $i=>$query) {
94 94
             if (!sqlsrv_query($db, $query)) {
95 95
                 $i++;
96
-                die("Loading '$fixture' failed on statemement #$i with error:\n".print_r( sqlsrv_errors(), true)."\n");
96
+                die("Loading '$fixture' failed on statemement #$i with error:\n".print_r(sqlsrv_errors(), true)."\n");
97 97
             }
98 98
         }
99 99
     }

+ 4
- 4
tests/SqliteTest.php View File

@@ -49,7 +49,7 @@ class SqliteTest extends Tests
49 49
         $major = 3;
50 50
         $minor = 0;
51 51
         $version = \SQLite3::version();
52
-        $v = explode('.',$version['versionString']);
52
+        $v = explode('.', $version['versionString']);
53 53
         if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor)) {
54 54
             die("Detected SQLite $v[0].$v[1], but only $major.$minor and up are supported\n");
55 55
         }
@@ -77,10 +77,10 @@ class SqliteTest extends Tests
77 77
         $contents = file_get_contents($fixture);
78 78
 
79 79
         if (!($capabilities & self::GIS)) {
80
-            $contents = preg_replace('/GEOMETRY NOT NULL/i','text NOT NULL',$contents);
80
+            $contents = preg_replace('/GEOMETRY NOT NULL/i', 'text NOT NULL', $contents);
81 81
         }
82 82
         if (!($capabilities & self::JSON)) {
83
-            $contents = preg_replace('/JSON NOT NULL/i','text NOT NULL',$contents);
83
+            $contents = preg_replace('/JSON NOT NULL/i', 'text NOT NULL', $contents);
84 84
         }
85 85
 
86 86
         $queries = preg_split('/;\s*\n/', $contents);
@@ -93,4 +93,4 @@ class SqliteTest extends Tests
93 93
             }
94 94
         }
95 95
     }
96
-}
96
+}

+ 8
- 9
tests/TestBase.php View File

@@ -13,7 +13,7 @@ abstract class TestBase extends \PHPUnit_Framework_TestCase
13 13
         $db = static::connect($config);
14 14
         static::checkVersion($db);
15 15
         $capabilities = static::getCapabilities($db);
16
-        static::seedDatabase($db,$capabilities);
16
+        static::seedDatabase($db, $capabilities);
17 17
         static::disconnect($db);
18 18
         // set params for test
19 19
         static::$config = $config;
@@ -26,16 +26,15 @@ abstract class TestBase extends \PHPUnit_Framework_TestCase
26 26
     const GIS = 1;
27 27
     const JSON = 2;
28 28
 
29
-    public abstract function getEngineName();
29
+    abstract public function getEngineName();
30 30
 
31
-    public abstract function connect($db);
31
+    abstract public function connect($db);
32 32
 
33
-    public abstract function disconnect($db);
33
+    abstract public function disconnect($db);
34 34
 
35
-    public abstract function checkVersion($db);
35
+    abstract public function checkVersion($db);
36 36
 
37
-    public abstract function getCapabilities($db);
37
+    abstract public function getCapabilities($db);
38 38
 
39
-    public abstract function seedDatabase($db,$capabilities);
40
-
41
-}
39
+    abstract public function seedDatabase($db, $capabilities);
40
+}

+ 43
- 43
tests/Tests.php View File

@@ -48,14 +48,14 @@ abstract class Tests extends TestBase
48 48
     public function testAddPost()
49 49
     {
50 50
         $test = new Api($this);
51
-        $test->post('/posts','{"user_id":1,"category_id":1,"content":"test"}');
51
+        $test->post('/posts', '{"user_id":1,"category_id":1,"content":"test"}');
52 52
         $test->expect('3');
53 53
     }
54 54
 
55 55
     public function testEditPost()
56 56
     {
57 57
         $test = new Api($this);
58
-        $test->put('/posts/3','{"user_id":1,"category_id":1,"content":"test (edited)"}');
58
+        $test->put('/posts/3', '{"user_id":1,"category_id":1,"content":"test (edited)"}');
59 59
         $test->expect('1');
60 60
         $test->get('/posts/3');
61 61
         $test->expect('{"id":3,"user_id":1,"category_id":1,"content":"test (edited)"}');
@@ -64,7 +64,7 @@ abstract class Tests extends TestBase
64 64
     public function testEditPostColumnsMissingField()
65 65
     {
66 66
         $test = new Api($this);
67
-        $test->put('/posts/3?columns=id,content','{"content":"test (edited 2)"}');
67
+        $test->put('/posts/3?columns=id,content', '{"content":"test (edited 2)"}');
68 68
         $test->expect('1');
69 69
         $test->get('/posts/3');
70 70
         $test->expect('{"id":3,"user_id":1,"category_id":1,"content":"test (edited 2)"}');
@@ -73,7 +73,7 @@ abstract class Tests extends TestBase
73 73
     public function testEditPostColumnsExtraField()
74 74
     {
75 75
         $test = new Api($this);
76
-        $test->put('/posts/3?columns=id,content','{"user_id":2,"content":"test (edited 3)"}');
76
+        $test->put('/posts/3?columns=id,content', '{"user_id":2,"content":"test (edited 3)"}');
77 77
         $test->expect('1');
78 78
         $test->get('/posts/3');
79 79
         $test->expect('{"id":3,"user_id":1,"category_id":1,"content":"test (edited 3)"}');
@@ -83,7 +83,7 @@ abstract class Tests extends TestBase
83 83
     {
84 84
         $utf8 = json_encode('Hello world, Καλημέρα κόσμε, コンニチハ');
85 85
         $test = new Api($this);
86
-        $test->put('/posts/2','{"content":'.$utf8.'}');
86
+        $test->put('/posts/2', '{"content":'.$utf8.'}');
87 87
         $test->expect('1');
88 88
         $test->get('/posts/2');
89 89
         $test->expect('{"id":2,"user_id":1,"category_id":2,"content":'.$utf8.'}');
@@ -95,7 +95,7 @@ abstract class Tests extends TestBase
95 95
         $url_encoded = urlencode($utf8);
96 96
         $json_encoded = json_encode($utf8);
97 97
         $test = new Api($this);
98
-        $test->put('/posts/2','content='.$url_encoded);
98
+        $test->put('/posts/2', 'content='.$url_encoded);
99 99
         $test->expect('1');
100 100
         $test->get('/posts/2');
101 101
         $test->expect('{"id":2,"user_id":1,"category_id":2,"content":'.$json_encoded.'}');
@@ -107,20 +107,20 @@ abstract class Tests extends TestBase
107 107
         $test->delete('/posts/3');
108 108
         $test->expect('1');
109 109
         $test->get('/posts/3');
110
-        $test->expect(false,'Not found (object)');
110
+        $test->expect(false, 'Not found (object)');
111 111
     }
112 112
 
113 113
     public function testAddPostWithPost()
114 114
     {
115 115
         $test = new Api($this);
116
-        $test->post('/posts','user_id=1&category_id=1&content=test');
116
+        $test->post('/posts', 'user_id=1&category_id=1&content=test');
117 117
         $test->expect('4');
118 118
     }
119 119
 
120 120
     public function testEditPostWithPost()
121 121
     {
122 122
         $test = new Api($this);
123
-        $test->put('/posts/4','user_id=1&category_id=1&content=test+(edited)');
123
+        $test->put('/posts/4', 'user_id=1&category_id=1&content=test+(edited)');
124 124
         $test->expect('1');
125 125
         $test->get('/posts/4');
126 126
         $test->expect('{"id":4,"user_id":1,"category_id":1,"content":"test (edited)"}');
@@ -132,14 +132,14 @@ abstract class Tests extends TestBase
132 132
         $test->delete('/posts/4');
133 133
         $test->expect('1');
134 134
         $test->get('/posts/4');
135
-        $test->expect(false,'Not found (object)');
135
+        $test->expect(false, 'Not found (object)');
136 136
     }
137 137
 
138 138
     public function testListWithPaginate()
139 139
     {
140 140
         $test = new Api($this);
141 141
         for ($i=1;$i<=10;$i++) {
142
-            $test->post('/posts','{"user_id":1,"category_id":1,"content":"#'.$i.'"}');
142
+            $test->post('/posts', '{"user_id":1,"category_id":1,"content":"#'.$i.'"}');
143 143
             $test->expect(4+$i);
144 144
         }
145 145
         $test->get('/posts?page=2,2&order=id');
@@ -207,7 +207,7 @@ abstract class Tests extends TestBase
207 207
         $binary = base64_encode("\0abc\0\n\r\b\0");
208 208
         $base64url = rtrim(strtr($binary, '+/', '-_'), '=');
209 209
         $test = new Api($this);
210
-        $test->put('/categories/2','{"icon":"'.$base64url.'"}');
210
+        $test->put('/categories/2', '{"icon":"'.$base64url.'"}');
211 211
         $test->expect('1');
212 212
         $test->get('/categories/2');
213 213
         $test->expect('{"id":2,"name":"article","icon":"'.$binary.'"}');
@@ -216,7 +216,7 @@ abstract class Tests extends TestBase
216 216
     public function testEditCategoryWithNull()
217 217
     {
218 218
         $test = new Api($this);
219
-        $test->put('/categories/2','{"icon":null}');
219
+        $test->put('/categories/2', '{"icon":null}');
220 220
         $test->expect('1');
221 221
         $test->get('/categories/2');
222 222
         $test->expect('{"id":2,"name":"article","icon":null}');
@@ -227,7 +227,7 @@ abstract class Tests extends TestBase
227 227
         $binary = base64_encode("€ \0abc\0\n\r\b\0");
228 228
         $base64url = rtrim(strtr($binary, '+/', '-_'), '=');
229 229
         $test = new Api($this);
230
-        $test->put('/categories/2','icon='.$base64url);
230
+        $test->put('/categories/2', 'icon='.$base64url);
231 231
         $test->expect('1');
232 232
         $test->get('/categories/2');
233 233
         $test->expect('{"id":2,"name":"article","icon":"'.$binary.'"}');
@@ -243,7 +243,7 @@ abstract class Tests extends TestBase
243 243
     public function testEditCategoryWithNullWithPost()
244 244
     {
245 245
         $test = new Api($this);
246
-        $test->put('/categories/2','icon__is_null');
246
+        $test->put('/categories/2', 'icon__is_null');
247 247
         $test->expect('1');
248 248
         $test->get('/categories/2');
249 249
         $test->expect('{"id":2,"name":"article","icon":null}');
@@ -252,7 +252,7 @@ abstract class Tests extends TestBase
252 252
     public function testAddPostFailure()
253 253
     {
254 254
         $test = new Api($this);
255
-        $test->post('/posts','{"user_id":"a","category_id":1,"content":"tests"}');
255
+        $test->post('/posts', '{"user_id":"a","category_id":1,"content":"tests"}');
256 256
         $test->expect('null');
257 257
     }
258 258
 
@@ -260,7 +260,7 @@ abstract class Tests extends TestBase
260 260
     {
261 261
         $test = new Api($this);
262 262
         $test->options('/posts/2');
263
-        $test->expect('["Access-Control-Allow-Headers: Content-Type, X-XSRF-TOKEN","Access-Control-Allow-Methods: OPTIONS, GET, PUT, POST, DELETE, PATCH","Access-Control-Allow-Credentials: true","Access-Control-Max-Age: 1728000"]',false);
263
+        $test->expect('["Access-Control-Allow-Headers: Content-Type, X-XSRF-TOKEN","Access-Control-Allow-Methods: OPTIONS, GET, PUT, POST, DELETE, PATCH","Access-Control-Allow-Credentials: true","Access-Control-Max-Age: 1728000"]', false);
264 264
     }
265 265
 
266 266
     public function testHidingPasswordColumn()
@@ -273,14 +273,14 @@ abstract class Tests extends TestBase
273 273
     public function testValidatorErrorMessage()
274 274
     {
275 275
         $test = new Api($this);
276
-        $test->put('/posts/1','{"category_id":"a"}');
277
-        $test->expect(false,'{"category_id":"must be numeric"}');
276
+        $test->put('/posts/1', '{"category_id":"a"}');
277
+        $test->expect(false, '{"category_id":"must be numeric"}');
278 278
     }
279 279
 
280 280
     public function testSanitizerToStripTags()
281 281
     {
282 282
         $test = new Api($this);
283
-        $test->put('/categories/2','{"name":"<script>alert();</script>"}');
283
+        $test->put('/categories/2', '{"name":"<script>alert();</script>"}');
284 284
         $test->expect('1');
285 285
         $test->get('/categories/2');
286 286
         $test->expect('{"id":2,"name":"alert();","icon":null}');
@@ -289,21 +289,21 @@ abstract class Tests extends TestBase
289 289
     public function testErrorOnInvalidJson()
290 290
     {
291 291
         $test = new Api($this);
292
-        $test->post('/posts','{"}');
293
-        $test->expect(false,'Not found (input)');
292
+        $test->post('/posts', '{"}');
293
+        $test->expect(false, 'Not found (input)');
294 294
     }
295 295
 
296 296
     public function testErrorOnDuplicatePrimaryKey()
297 297
     {
298 298
         $test = new Api($this);
299
-        $test->post('/posts','{"id":1,"user_id":1,"category_id":1,"content":"blog started (duplicate)"}');
299
+        $test->post('/posts', '{"id":1,"user_id":1,"category_id":1,"content":"blog started (duplicate)"}');
300 300
         $test->expect('null');
301 301
     }
302 302
 
303 303
     public function testErrorOnFailingForeignKeyConstraint()
304 304
     {
305 305
         $test = new Api($this);
306
-        $test->post('/posts','{"user_id":3,"category_id":1,"content":"fk constraint"}');
306
+        $test->post('/posts', '{"user_id":3,"category_id":1,"content":"fk constraint"}');
307 307
         $test->expect('null');
308 308
     }
309 309
 
@@ -317,14 +317,14 @@ abstract class Tests extends TestBase
317 317
     public function testEditUserPassword()
318 318
     {
319 319
         $test = new Api($this);
320
-        $test->put('/users/1','{"password":"testtest"}');
320
+        $test->put('/users/1', '{"password":"testtest"}');
321 321
         $test->expect('1');
322 322
     }
323 323
 
324 324
     public function testEditUserLocation()
325 325
     {
326 326
         $test = new Api($this);
327
-        $test->put('/users/1','{"location":"POINT(30 20)"}');
327
+        $test->put('/users/1', '{"location":"POINT(30 20)"}');
328 328
         $test->expect('1');
329 329
         $test->get('/users/1?columns=id,location');
330 330
         if ($this->getEngineName()=='SQLServer') {
@@ -349,7 +349,7 @@ abstract class Tests extends TestBase
349 349
     {
350 350
         if ($this->getEngineName()!='SQLServer') {
351 351
             $test = new Api($this);
352
-            $test->put('/users/1','{"id":2,"password":"testtest2"}');
352
+            $test->put('/users/1', '{"id":2,"password":"testtest2"}');
353 353
             $test->expect('1');
354 354
             $test->get('/users/1?columns=id,username,password');
355 355
             $test->expect('{"id":1,"username":"user1","password":"testtest2"}');
@@ -360,13 +360,13 @@ abstract class Tests extends TestBase
360 360
     {
361 361
         $test = new Api($this);
362 362
         $test->get('/users/2');
363
-        $test->expect(false,'Not found (object)');
363
+        $test->expect(false, 'Not found (object)');
364 364
     }
365 365
 
366 366
     public function testEditOtherUser()
367 367
     {
368 368
         $test = new Api($this);
369
-        $test->put('/users/2','{"password":"testtest"}');
369
+        $test->put('/users/2', '{"password":"testtest"}');
370 370
         $test->expect('0');
371 371
     }
372 372
 
@@ -466,7 +466,7 @@ abstract class Tests extends TestBase
466 466
     public function testAddPostsWithNonExistingCategory()
467 467
     {
468 468
         $test = new Api($this);
469
-        $test->post('/posts','[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":15,"content":"tests"}]');
469
+        $test->post('/posts', '[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":15,"content":"tests"}]');
470 470
         $test->expect('null');
471 471
         $test->get('/posts?columns=content&filter=content,eq,tests');
472 472
         $test->expect('{"posts":{"columns":["content"],"records":[]}}');
@@ -475,7 +475,7 @@ abstract class Tests extends TestBase
475 475
     public function testAddPosts()
476 476
     {
477 477
         $test = new Api($this);
478
-        $test->post('/posts','[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":1,"content":"tests"}]');
478
+        $test->post('/posts', '[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":1,"content":"tests"}]');
479 479
         $test->expectAny();
480 480
         $test->get('/posts?columns=content&filter=content,eq,tests');
481 481
         $test->expect('{"posts":{"columns":["content"],"records":[["tests"],["tests"]]}}');
@@ -491,7 +491,7 @@ abstract class Tests extends TestBase
491 491
     public function testIncrementEventVisitors()
492 492
     {
493 493
         $test = new Api($this);
494
-        $test->patch('/events/1','{"visitors":11}');
494
+        $test->patch('/events/1', '{"visitors":11}');
495 495
         $test->expect('1');
496 496
         $test->get('/events/1');
497 497
         $test->expect('{"id":1,"name":"Launch","datetime":"2016-01-01 13:01:01","visitors":11}');
@@ -500,7 +500,7 @@ abstract class Tests extends TestBase
500 500
     public function testIncrementEventVisitorsWithZero()
501 501
     {
502 502
         $test = new Api($this);
503
-        $test->patch('/events/1','{"visitors":0}');
503
+        $test->patch('/events/1', '{"visitors":0}');
504 504
         $test->expect('1');
505 505
         $test->get('/events/1');
506 506
         $test->expect('{"id":1,"name":"Launch","datetime":"2016-01-01 13:01:01","visitors":11}');
@@ -509,7 +509,7 @@ abstract class Tests extends TestBase
509 509
     public function testDecrementEventVisitors()
510 510
     {
511 511
         $test = new Api($this);
512
-        $test->patch('/events/1','{"visitors":-5}');
512
+        $test->patch('/events/1', '{"visitors":-5}');
513 513
         $test->expect('1');
514 514
         $test->get('/events/1');
515 515
         $test->expect('{"id":1,"name":"Launch","datetime":"2016-01-01 13:01:01","visitors":6}');
@@ -527,15 +527,15 @@ abstract class Tests extends TestBase
527 527
         $test = new Api($this);
528 528
         $test->get('/tags?transform=1');
529 529
         $test->expect('{"tags":[{"id":1,"name":"funny"},{"id":2,"name":"important"}]}');
530
-        $test->put('/tags/1,2','[{"name":"funny"},{"name":"important"}]');
530
+        $test->put('/tags/1,2', '[{"name":"funny"},{"name":"important"}]');
531 531
         $test->expect('[1,1]');
532 532
     }
533 533
 
534 534
     public function testUpdateMultipleTagsTooManyIds()
535 535
     {
536 536
         $test = new Api($this);
537
-        $test->put('/tags/1,2,3','[{"name":"funny!!!"},{"name":"important"}]');
538
-        $test->expect(false,'Not found (subject)');
537
+        $test->put('/tags/1,2,3', '[{"name":"funny!!!"},{"name":"important"}]');
538
+        $test->expect(false, 'Not found (subject)');
539 539
         $test->get('/tags?transform=1');
540 540
         $test->expect('{"tags":[{"id":1,"name":"funny"},{"id":2,"name":"important"}]}');
541 541
     }
@@ -543,7 +543,7 @@ abstract class Tests extends TestBase
543 543
     public function testUpdateMultipleTagsWithoutFields()
544 544
     {
545 545
         $test = new Api($this);
546
-        $test->put('/tags/1,2','[{"name":"funny!!!"},{}]');
546
+        $test->put('/tags/1,2', '[{"name":"funny!!!"},{}]');
547 547
         $test->expect('null');
548 548
         $test->get('/tags?transform=1');
549 549
         $test->expect('{"tags":[{"id":1,"name":"funny"},{"id":2,"name":"important"}]}');
@@ -552,7 +552,7 @@ abstract class Tests extends TestBase
552 552
     public function testDeleteMultipleTags()
553 553
     {
554 554
         $test = new Api($this);
555
-        $test->post('/tags','[{"name":"extra"},{"name":"more"}]');
555
+        $test->post('/tags', '[{"name":"extra"},{"name":"more"}]');
556 556
         $test->expect('[3,4]');
557 557
         $test->delete('/tags/3,4');
558 558
         $test->expect('[1,1]');
@@ -593,9 +593,9 @@ abstract class Tests extends TestBase
593 593
     {
594 594
         $test = new Api($this);
595 595
         if (static::$capabilities & self::JSON) {
596
-            $test->put('/products/1','{"properties":{"depth":false,"model":"TRX-120","width":100,"height":123}}');
596
+            $test->put('/products/1', '{"properties":{"depth":false,"model":"TRX-120","width":100,"height":123}}');
597 597
         } else {
598
-            $test->put('/products/1','{"properties":"{\"depth\":false,\"model\":\"TRX-120\",\"width\":100,\"height\":123}"}');
598
+            $test->put('/products/1', '{"properties":"{\"depth\":false,\"model\":\"TRX-120\",\"width\":100,\"height\":123}"}');
599 599
         }
600 600
         $test->expect('1');
601 601
         $test->get('/products/1?columns=id,properties');
@@ -610,9 +610,9 @@ abstract class Tests extends TestBase
610 610
     {
611 611
         $test = new Api($this);
612 612
         if (static::$capabilities & self::JSON) {
613
-            $test->post('/products','{"name":"Laptop","price":"1299.99","properties":{}}');
613
+            $test->post('/products', '{"name":"Laptop","price":"1299.99","properties":{}}');
614 614
         } else {
615
-            $test->post('/products','{"name":"Laptop","price":"1299.99","properties":"{}"}');
615
+            $test->post('/products', '{"name":"Laptop","price":"1299.99","properties":"{}"}');
616 616
         }
617 617
         $test->expect('2');
618 618
         $test->get('/products/2?columns=id,created_at,deleted_at');

+ 1
- 1
tests/autoload.php View File

@@ -38,4 +38,4 @@ spl_autoload_register(function ($class) {
38 38
     if (file_exists($file)) {
39 39
         require $file;
40 40
     }
41
-});
41
+});

Loading…
Cancel
Save