@@ -23,6 +23,10 @@ public function testParse()
2323 $ this ->assertNull ($ component ->name );
2424 $ this ->assertNull ($ component ->expr );
2525 $ this ->assertSame (array (), $ component ->columns );
26+ $ this ->assertSame (
27+ '() ' ,
28+ Key::build ($ component )
29+ );
2630 }
2731
2832 public function testParseKeyWithoutOptions ()
@@ -40,6 +44,10 @@ public function testParseKeyWithoutOptions()
4044 'name ' => 'alias_type ' ,
4145 )
4246 ), $ component ->columns );
47+ $ this ->assertSame (
48+ 'KEY `alias_type_idx` (`alias_type`) ' ,
49+ Key::build ($ component )
50+ );
4351 }
4452
4553 public function testParseKeyWithLengthWithoutOptions ()
@@ -58,6 +66,10 @@ public function testParseKeyWithLengthWithoutOptions()
5866 'length ' => 10 ,
5967 )
6068 ), $ component ->columns );
69+ $ this ->assertSame (
70+ 'KEY `alias_type_idx` (`alias_type`(10)) ' ,
71+ Key::build ($ component )
72+ );
6173 }
6274
6375 public function testParseKeyWithLengthWithoutOptionsWithOrder ()
@@ -77,6 +89,10 @@ public function testParseKeyWithLengthWithoutOptionsWithOrder()
7789 'order ' => 'ASC ' ,
7890 )
7991 ), $ component ->columns );
92+ $ this ->assertSame (
93+ 'KEY `alias_type_idx` (`alias_type`(10) ASC) ' ,
94+ Key::build ($ component )
95+ );
8096 }
8197
8298 public function testParseKeyWithoutOptionsWithOrderLowercase ()
@@ -95,6 +111,10 @@ public function testParseKeyWithoutOptionsWithOrderLowercase()
95111 'order ' => 'DESC ' ,
96112 )
97113 ), $ component ->columns );
114+ $ this ->assertSame (
115+ 'KEY `alias_type_idx` (`alias_type` DESC) ' ,
116+ Key::build ($ component )
117+ );
98118 }
99119
100120 public function testParseKeyWithoutOptionsWithOrder ()
@@ -113,6 +133,10 @@ public function testParseKeyWithoutOptionsWithOrder()
113133 'order ' => 'DESC ' ,
114134 )
115135 ), $ component ->columns );
136+ $ this ->assertSame (
137+ 'KEY `alias_type_idx` (`alias_type` DESC) ' ,
138+ Key::build ($ component )
139+ );
116140 }
117141
118142 public function testParseKeyWithLengthWithOptions ()
@@ -140,6 +164,10 @@ public function testParseKeyWithLengthWithOptions()
140164 'length ' => 10 ,
141165 )
142166 ), $ component ->columns );
167+ $ this ->assertSame (
168+ 'KEY `alias_type_idx` (`alias_type`(10)) COMMENT \'my comment \'' ,
169+ Key::build ($ component )
170+ );
143171 }
144172
145173 public function testParseKeyExpressionWithoutOptions ()
@@ -162,14 +190,20 @@ public function testParseKeyExpressionWithoutOptions()
162190 $ component ->expr
163191 );
164192 $ this ->assertSame (array (), $ component ->columns );
193+ $ this ->assertSame (
194+ 'KEY `updated_tz_ind2` ((convert_tz(`cache_updated`,_utf8mb4 \'GMT \',_utf8mb4 \'GB \'))) ' ,
195+ Key::build ($ component )
196+ );
165197 }
166198
167199 public function testParseKeyExpressionWithOptions ()
168200 {
169201 $ component = Key::parse (
170202 new Parser (),
171203 $ this ->getTokensList (
172- 'KEY `updated_tz_ind2` ((convert_tz(`cache_updated`,_utf8mb4 \'GMT \',_utf8mb4 \'GB \'))) COMMENT \'my comment \', '
204+ 'KEY `updated_tz_ind2` '
205+ . ' ((convert_tz(`cache_updated`,_utf8mb4 \'GMT \',_utf8mb4 \'GB \'))) '
206+ . ' COMMENT \'my comment \', '
173207 )
174208 );
175209 $ this ->assertEquals ('KEY ' , $ component ->type );
@@ -193,6 +227,12 @@ public function testParseKeyExpressionWithOptions()
193227 $ component ->expr
194228 );
195229 $ this ->assertSame (array (), $ component ->columns );
230+ $ this ->assertSame (
231+ 'KEY `updated_tz_ind2` '
232+ . ' ((convert_tz(`cache_updated`,_utf8mb4 \'GMT \',_utf8mb4 \'GB \'))) '
233+ . ' COMMENT \'my comment \'' ,
234+ Key::build ($ component )
235+ );
196236 }
197237
198238 public function testParseKeyExpressionWithOptionsError ()
@@ -232,6 +272,10 @@ public function testParseKeyExpressionWithOptionsError()
232272 $ component ->expr
233273 );
234274 $ this ->assertSame (array (), $ component ->columns );
275+ $ this ->assertSame (
276+ 'KEY `updated_tz_ind2` (()(`cache_updated`,_utf8mb4 \'GMT \',_utf8mb4 \'GB \')) ' ,
277+ Key::build ($ component )
278+ );
235279 }
236280
237281 public function testParseKeyOneExpressionWithOptions ()
@@ -271,6 +315,12 @@ public function testParseKeyOneExpressionWithOptions()
271315 $ component ->expr
272316 );
273317 $ this ->assertSame (array (), $ component ->columns );
318+ $ this ->assertSame (
319+ 'KEY `updated_tz_ind2` ((convert_tz(`cache_updated`,_utf8mb4 \'GMT \',_utf8mb4 \'GB \')), '
320+ . ' (convert_tz(`cache_updated`,_utf8mb4 \'GMT \',_utf8mb4 \'FR \')) '
321+ . ') COMMENT \'my comment \'' ,
322+ Key::build ($ component )
323+ );
274324 }
275325
276326 public function testParseKeyMultipleExpressionsWithOptions ()
@@ -312,5 +362,12 @@ public function testParseKeyMultipleExpressionsWithOptions()
312362 );
313363 $ this ->assertSame (array (), $ component ->columns );
314364 $ this ->assertSame (array (), $ parser ->errors );
365+ $ this ->assertSame (
366+ 'KEY `updated_tz_ind2` ((convert_tz(`cache_updated`,_utf8mb4 \'GMT \',_utf8mb4 \'GB \')), '
367+ . ' (convert_tz(`cache_updated`,_utf8mb4 \'GMT \',_utf8mb4 \'FR \')), '
368+ . ' (convert_tz(`cache_updated`,_utf8mb4 \'GMT \',_utf8mb4 \'RU \')) '
369+ . ') COMMENT \'my comment \'' ,
370+ Key::build ($ component )
371+ );
315372 }
316373}
0 commit comments