4
4
5
5
class MysqlTest extends PHP_CRUD_API_Test
6
6
{
7
+ const MYSQL_56 = 50600 ;
8
+ const MYSQL_57 = 50700 ;
9
+ public static $ mysql_version ;
10
+
7
11
public static function setUpBeforeClass ()
8
12
{
9
13
self ::setConfig ('MySQL ' );
@@ -21,8 +25,6 @@ public function seedDatabase()
21
25
die ("Configure database in 'config.php' before running tests. \n" );
22
26
}
23
27
24
- $ fixture = __DIR__ .'/data/blog_ ' .strtolower (static ::$ config ['dbengine ' ]).'.sql ' ;
25
-
26
28
$ link = mysqli_connect (
27
29
static ::$ config ['hostname ' ],
28
30
static ::$ config ['username ' ],
@@ -34,16 +36,138 @@ public function seedDatabase()
34
36
die ("Connect failed: " .mysqli_connect_error ()."\n" );
35
37
}
36
38
39
+ // Note: For some reason this version is formatted:
40
+ // $mysql_version = main_version * 10000 + minor_version * 100 + sub_version
41
+ static ::$ mysql_version = mysqli_get_server_version ($ link );
42
+ $ seed_file = self ::getSeedFile ();
43
+
37
44
mysqli_set_charset ($ link ,'utf8 ' );
38
45
39
46
$ i =0 ;
40
- if (mysqli_multi_query ($ link , file_get_contents ($ fixture ))) {
47
+ if (mysqli_multi_query ($ link , file_get_contents ($ seed_file ))) {
41
48
do { $ i ++; mysqli_next_result ($ link ); } while (mysqli_more_results ($ link ));
42
49
}
43
50
if (mysqli_errno ($ link )) {
44
- die ("Loading ' $ fixture ' failed on statemement # $ i with error: \n" .mysqli_error ($ link )."\n" );
51
+ die ("Loading ' $ seed_file ' failed on statemement # $ i with error: \n" .mysqli_error ($ link )."\n" );
45
52
}
46
53
47
54
mysqli_close ($ link );
48
55
}
56
+
57
+ /**
58
+ * Gets the path to the seed file based on the version of MySQL
59
+ *
60
+ * @return string
61
+ */
62
+ protected static function getSeedFile ()
63
+ {
64
+ if (static ::$ mysql_version >= self ::MYSQL_57 ) {
65
+ return __DIR__ .'/data/blog_ ' .strtolower (static ::$ config ['dbengine ' ]).'_57.sql ' ;
66
+ } elseif (static ::$ mysql_version >= self ::MYSQL_56 ) {
67
+ return __DIR__ .'/data/blog_ ' .strtolower (static ::$ config ['dbengine ' ]).'_56.sql ' ;
68
+ }
69
+ return __DIR__ .'/data/blog_ ' .strtolower (static ::$ config ['dbengine ' ]).'_55.sql ' ;
70
+ }
71
+
72
+ public function testHidingPasswordColumn ()
73
+ {
74
+ parent ::testHidingPasswordColumn ();
75
+ }
76
+
77
+ public function testMissingIntermediateTable ()
78
+ {
79
+ $ test = new API ($ this , static ::$ config );
80
+ $ test ->get ('/users?include=posts,tags ' );
81
+ $ test ->expect ('{"users":{"columns":["id","username","location"],"records":[[1,"user1",null]]},"posts":{"relations":{"user_id":"users.id"},"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"],[2,1,2,"It works!"]]},"post_tags":{"relations":{"post_id":"posts.id"},"columns":["id","post_id","tag_id"],"records":[[1,1,1],[2,1,2],[3,2,1],[4,2,2]]},"tags":{"relations":{"id":"post_tags.tag_id"},"columns":["id","name"],"records":[[1,"funny"],[2,"important"]]}} ' );
82
+ }
83
+
84
+ public function testEditUserPassword ()
85
+ {
86
+ parent ::testEditUserPassword ();
87
+ }
88
+
89
+ public function testEditUserLocation ()
90
+ {
91
+ parent ::testEditUserLocation ();
92
+ }
93
+
94
+ public function testListUserLocations ()
95
+ {
96
+ parent ::testListUserLocations ();
97
+ }
98
+
99
+ public function testEditUserWithId ()
100
+ {
101
+ parent ::testEditUserWithId ();
102
+ }
103
+
104
+ public function testReadOtherUser ()
105
+ {
106
+ parent ::testReadOtherUser ();
107
+ }
108
+
109
+ public function testEditOtherUser ()
110
+ {
111
+ parent ::testEditOtherUser ();
112
+ }
113
+
114
+ public function testSpatialFilterWithin ()
115
+ {
116
+ if (static ::$ mysql_version < self ::MYSQL_56 ) {
117
+ $ this ->markTestSkipped ("MySQL < 5.6 does not support JSON fields. " );
118
+ }
119
+ parent ::testSpatialFilterWithin ();
120
+ }
121
+
122
+
123
+ public function testListProductsProperties ()
124
+ {
125
+ if (static ::$ mysql_version < self ::MYSQL_57 ) {
126
+ $ this ->markTestSkipped ("MySQL < 5.7 does not support JSON fields. " );
127
+ }
128
+ parent ::testListProductsProperties ();
129
+ }
130
+
131
+ public function testReadProductProperties ()
132
+ {
133
+ if (static ::$ mysql_version < self ::MYSQL_57 ) {
134
+ $ this ->markTestSkipped ("MySQL < 5.7 does not support JSON fields. " );
135
+ }
136
+ parent ::testReadProductProperties ();
137
+ }
138
+
139
+ public function testWriteProductProperties ()
140
+ {
141
+ if (static ::$ mysql_version < self ::MYSQL_57 ) {
142
+ $ this ->markTestSkipped ("MySQL < 5.7 does not support JSON fields. " );
143
+ }
144
+ parent ::testWriteProductProperties ();
145
+ }
146
+
147
+ public function testListProducts ()
148
+ {
149
+ parent ::testListProducts ();
150
+ }
151
+
152
+ public function testAddProducts ()
153
+ {
154
+ if (static ::$ mysql_version < self ::MYSQL_57 ) {
155
+ $ this ->markTestSkipped ("MySQL < 5.7 does not support JSON fields. " );
156
+ }
157
+ parent ::testAddProducts ();
158
+ }
159
+
160
+ public function testSoftDeleteProducts ()
161
+ {
162
+ if (static ::$ mysql_version < self ::MYSQL_57 ) {
163
+ $ test = new API ($ this , static ::$ config );
164
+ $ test ->delete ('/products/1 ' );
165
+ $ test ->expect ('1 ' );
166
+ $ test ->get ('/products?columns=id,deleted_at ' );
167
+ $ test ->expect ('{"products":{"columns":["id","deleted_at"],"records":[[1,"2013-12-11 11:10:09"]]}} ' );
168
+ } else {
169
+ parent ::testSoftDeleteProducts ();
170
+ }
171
+ }
172
+
49
173
}
0 commit comments