Skip to content

Commit 857a040

Browse files
committed
Codestyle fixes (automatically)
1 parent 2a2e49e commit 857a040

File tree

8 files changed

+129
-99
lines changed

8 files changed

+129
-99
lines changed

tests/Api.php

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public function __construct($test)
2929
$this->config['dbengine'] = $test->getEngineName();
3030
}
3131

32-
private function action($method,$url,$data='')
32+
private function action($method, $url, $data='')
3333
{
3434
$url = parse_url($url);
3535
$query = isset($url['query'])?$url['query']:'';
36-
parse_str($query,$get);
36+
parse_str($query, $get);
3737

3838
$this->api = new \PHP_CRUD_API(array(
3939
'dbengine'=>$this->config['dbengine'],
@@ -42,14 +42,37 @@ private function action($method,$url,$data='')
4242
'password'=>$this->config['password'],
4343
'database'=>$this->config['database'],
4444
// 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+
},
5376
// for tests
5477
'method'=>$method,
5578
'request'=>$url['path'],
@@ -61,32 +84,32 @@ private function action($method,$url,$data='')
6184

6285
public function get($url)
6386
{
64-
return $this->action('GET',$url);
87+
return $this->action('GET', $url);
6588
}
6689

67-
public function post($url,$data)
90+
public function post($url, $data)
6891
{
69-
return $this->action('POST',$url,$data);
92+
return $this->action('POST', $url, $data);
7093
}
7194

72-
public function put($url,$data)
95+
public function put($url, $data)
7396
{
74-
return $this->action('PUT',$url,$data);
97+
return $this->action('PUT', $url, $data);
7598
}
7699

77100
public function delete($url)
78101
{
79-
return $this->action('DELETE',$url);
102+
return $this->action('DELETE', $url);
80103
}
81104

82105
public function options($url)
83106
{
84-
return $this->action('OPTIONS',$url);
107+
return $this->action('OPTIONS', $url);
85108
}
86109

87-
public function patch($url,$data)
110+
public function patch($url, $data)
88111
{
89-
return $this->action('PATCH',$url,$data);
112+
return $this->action('PATCH', $url, $data);
90113
}
91114

92115
public function expectAny()
@@ -97,7 +120,7 @@ public function expectAny()
97120
return $this;
98121
}
99122

100-
public function expect($output,$error=false)
123+
public function expect($output, $error=false)
101124
{
102125
$exception = false;
103126
ob_start();
@@ -108,8 +131,11 @@ public function expect($output,$error=false)
108131
}
109132
$data = ob_get_contents();
110133
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+
}
113139
return $this;
114140
}
115-
}
141+
}

tests/MysqlTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function connect($config)
3131
die("Connect failed: ".mysqli_connect_error()."\n");
3232
}
3333

34-
mysqli_set_charset($db,'utf8');
34+
mysqli_set_charset($db, 'utf8');
3535

3636
return $db;
3737
}
@@ -92,16 +92,19 @@ public function seedDatabase($db, $capabilities)
9292
$contents = file_get_contents($fixture);
9393

9494
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);
9797
}
9898
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);
100100
}
101101

102102
$i=0;
103103
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));
105108
}
106109

107110
if (mysqli_errno($db)) {

tests/PostgresqlTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public function getEngineName()
2020
*/
2121
public function connect($config)
2222
{
23-
$e = function ($v) { return str_replace(array('\'','\\'),array('\\\'','\\\\'),$v); };
23+
$e = function ($v) {
24+
return str_replace(array('\'','\\'), array('\\\'','\\\\'), $v);
25+
};
2426
$hostname = $e($config['hostname']);
2527
$database = $e($config['database']);
2628
$username = $e($config['username']);
@@ -50,7 +52,7 @@ public function checkVersion($db)
5052
$major = 9;
5153
$minor = 1;
5254
$version = pg_version();
53-
$v = explode('.',$version['server']);
55+
$v = explode('.', $version['server']);
5456
if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor)) {
5557
die("Detected PostgreSQL $v[0].$v[1], but only $major.$minor and up are supported\n");
5658
}
@@ -67,15 +69,15 @@ public function getCapabilities($db)
6769
$major = 9;
6870
$minor = 4;
6971
$version = pg_version();
70-
$v = explode('.',$version['server']);
72+
$v = explode('.', $version['server']);
7173
if ($v[0]>$major || ($v[0]==$major && $v[1]>=$minor)) {
7274
$capabilities |= self::JSON;
7375
}
7476
$extensions = pg_fetch_all(pg_query($db, "SELECT * FROM pg_extension;"));
7577
foreach ($extensions as $extension) {
76-
if ($extension['extname'] === 'postgis') {
77-
$capabilities |= self::GIS;
78-
}
78+
if ($extension['extname'] === 'postgis') {
79+
$capabilities |= self::GIS;
80+
}
7981
}
8082
return $capabilities;
8183
}
@@ -85,17 +87,17 @@ public function getCapabilities($db)
8587
*
8688
* @return void
8789
*/
88-
public function seedDatabase($db,$capabilities)
90+
public function seedDatabase($db, $capabilities)
8991
{
9092
$fixture = __DIR__.'/data/blog_postgresql.sql';
9193
$contents = file_get_contents($fixture);
9294

9395
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);
9698
}
9799
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);
99101
}
100102

101103
$queries = preg_split('/;\s*\n/', $contents);
@@ -104,7 +106,7 @@ public function seedDatabase($db,$capabilities)
104106
foreach ($queries as $i=>$query) {
105107
if (!pg_query($db, $query.';')) {
106108
$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");
108110
}
109111
}
110112
}

tests/SqlServerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function connect($config)
3030
$db = sqlsrv_connect($config['hostname'], $connectionInfo);
3131

3232
if (!$db) {
33-
die("Connect failed: ".print_r( sqlsrv_errors(), true));
33+
die("Connect failed: ".print_r(sqlsrv_errors(), true));
3434
}
3535

3636
return $db;
@@ -57,7 +57,7 @@ public function checkVersion($db)
5757
$minor = 0;
5858
$build = 3000;
5959
$version = sqlsrv_server_info($db);
60-
$v = explode('.',$version['SQLServerVersion']);
60+
$v = explode('.', $version['SQLServerVersion']);
6161
if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor) || ($v[0]==$major && $v[1]==$minor && $v[2]<$build)) {
6262
die("Detected SQL Server $v[0].$v[1].$v[2], but only $major.$minor.$build and up are supported\n");
6363
}
@@ -93,7 +93,7 @@ public function seedDatabase($db, $capabilities)
9393
foreach ($queries as $i=>$query) {
9494
if (!sqlsrv_query($db, $query)) {
9595
$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");
9797
}
9898
}
9999
}

tests/SqliteTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function checkVersion($db)
4949
$major = 3;
5050
$minor = 0;
5151
$version = \SQLite3::version();
52-
$v = explode('.',$version['versionString']);
52+
$v = explode('.', $version['versionString']);
5353
if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor)) {
5454
die("Detected SQLite $v[0].$v[1], but only $major.$minor and up are supported\n");
5555
}
@@ -77,10 +77,10 @@ public function seedDatabase($db, $capabilities)
7777
$contents = file_get_contents($fixture);
7878

7979
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);
8181
}
8282
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);
8484
}
8585

8686
$queries = preg_split('/;\s*\n/', $contents);
@@ -93,4 +93,4 @@ public function seedDatabase($db, $capabilities)
9393
}
9494
}
9595
}
96-
}
96+
}

tests/TestBase.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static function setUpBeforeClass()
1313
$db = static::connect($config);
1414
static::checkVersion($db);
1515
$capabilities = static::getCapabilities($db);
16-
static::seedDatabase($db,$capabilities);
16+
static::seedDatabase($db, $capabilities);
1717
static::disconnect($db);
1818
// set params for test
1919
static::$config = $config;
@@ -26,16 +26,15 @@ public static function setUpBeforeClass()
2626
const GIS = 1;
2727
const JSON = 2;
2828

29-
public abstract function getEngineName();
29+
abstract public function getEngineName();
3030

31-
public abstract function connect($db);
31+
abstract public function connect($db);
3232

33-
public abstract function disconnect($db);
33+
abstract public function disconnect($db);
3434

35-
public abstract function checkVersion($db);
35+
abstract public function checkVersion($db);
3636

37-
public abstract function getCapabilities($db);
37+
abstract public function getCapabilities($db);
3838

39-
public abstract function seedDatabase($db,$capabilities);
40-
41-
}
39+
abstract public function seedDatabase($db, $capabilities);
40+
}

0 commit comments

Comments
 (0)