SqlserverSchemaTest.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Database\Schema;
  16. use Cake\Core\Configure;
  17. use Cake\Database\Schema\Collection as SchemaCollection;
  18. use Cake\Database\Schema\SqlserverSchema;
  19. use Cake\Database\Schema\Table;
  20. use Cake\Datasource\ConnectionManager;
  21. use Cake\TestSuite\TestCase;
  22. /**
  23. * SQL Server schema test case.
  24. */
  25. class SqlserverSchemaTest extends TestCase {
  26. /**
  27. * Set up
  28. *
  29. * @return void
  30. */
  31. public function setUp() {
  32. parent::setUp();
  33. $this->skipUnless(defined('PDO::SQLSRV_ENCODING_UTF8'), 'SQL Server extension not present');
  34. }
  35. /**
  36. * Helper method for skipping tests that need a real connection.
  37. *
  38. * @return void
  39. */
  40. protected function _needsConnection() {
  41. $config = ConnectionManager::config('test');
  42. $this->skipIf(strpos($config['driver'], 'Sqlserver') === false, 'Not using Sqlserver for test config');
  43. }
  44. /**
  45. * Helper method for testing methods.
  46. *
  47. * @return void
  48. */
  49. protected function _createTables($connection) {
  50. $this->_needsConnection();
  51. $connection->execute("IF OBJECT_ID('schema_articles', 'U') IS NOT NULL DROP TABLE schema_articles");
  52. $connection->execute("IF OBJECT_ID('schema_authors', 'U') IS NOT NULL DROP TABLE schema_authors");
  53. $table = <<<SQL
  54. CREATE TABLE schema_authors (
  55. id int IDENTITY(1,1) PRIMARY KEY,
  56. name VARCHAR(50),
  57. bio DATE,
  58. created DATETIME
  59. )
  60. SQL;
  61. $connection->execute($table);
  62. $table = <<<SQL
  63. CREATE TABLE schema_articles (
  64. id BIGINT PRIMARY KEY,
  65. title VARCHAR(20),
  66. body VARCHAR(1000),
  67. author_id INTEGER NOT NULL,
  68. published BIT DEFAULT 0,
  69. views SMALLINT DEFAULT 0,
  70. created DATETIME,
  71. CONSTRAINT [content_idx] UNIQUE ([title], [body]),
  72. CONSTRAINT [author_idx] FOREIGN KEY ([author_id]) REFERENCES [schema_authors] ([id]) ON DELETE CASCADE ON UPDATE CASCADE
  73. )
  74. SQL;
  75. $connection->execute($table);
  76. $connection->execute('CREATE INDEX [author_idx] ON [schema_articles] ([author_id])');
  77. }
  78. /**
  79. * Data provider for convert column testing
  80. *
  81. * @return array
  82. */
  83. public static function convertColumnProvider() {
  84. return [
  85. [
  86. 'DATETIME',
  87. null,
  88. null,
  89. null,
  90. ['type' => 'timestamp', 'length' => null]
  91. ],
  92. [
  93. 'DATE',
  94. null,
  95. null,
  96. null,
  97. ['type' => 'date', 'length' => null]
  98. ],
  99. [
  100. 'TIME',
  101. null,
  102. null,
  103. null,
  104. ['type' => 'time', 'length' => null]
  105. ],
  106. [
  107. 'SMALLINT',
  108. null,
  109. 4,
  110. null,
  111. ['type' => 'integer', 'length' => 4]
  112. ],
  113. [
  114. 'INTEGER',
  115. null,
  116. null,
  117. null,
  118. ['type' => 'integer', 'length' => 10]
  119. ],
  120. [
  121. 'INTEGER',
  122. null,
  123. 8,
  124. null,
  125. ['type' => 'integer', 'length' => 8]
  126. ],
  127. [
  128. 'BIGINT',
  129. null,
  130. null,
  131. null,
  132. ['type' => 'biginteger', 'length' => 20]
  133. ],
  134. [
  135. 'NUMERIC',
  136. null,
  137. 15,
  138. 5,
  139. ['type' => 'decimal', 'length' => 15, 'precision' => 5]
  140. ],
  141. [
  142. 'DECIMAL',
  143. null,
  144. 11,
  145. 3,
  146. ['type' => 'decimal', 'length' => 11, 'precision' => 3]
  147. ],
  148. [
  149. 'MONEY',
  150. null,
  151. null,
  152. null,
  153. ['type' => 'decimal', 'length' => null, 'precision' => null]
  154. ],
  155. [
  156. 'VARCHAR',
  157. null,
  158. null,
  159. null,
  160. ['type' => 'string', 'length' => 255]
  161. ],
  162. [
  163. 'VARCHAR',
  164. 10,
  165. null,
  166. null,
  167. ['type' => 'string', 'length' => 10]
  168. ],
  169. [
  170. 'NVARCHAR',
  171. 50,
  172. null,
  173. null,
  174. ['type' => 'string', 'length' => 50]
  175. ],
  176. [
  177. 'CHAR',
  178. 10,
  179. null,
  180. null,
  181. ['type' => 'string', 'fixed' => true, 'length' => 10]
  182. ],
  183. [
  184. 'NCHAR',
  185. 10,
  186. null,
  187. null,
  188. ['type' => 'string', 'fixed' => true, 'length' => 10]
  189. ],
  190. [
  191. 'UNIQUEIDENTIFIER',
  192. null,
  193. null,
  194. null,
  195. ['type' => 'uuid']
  196. ],
  197. [
  198. 'TEXT',
  199. null,
  200. null,
  201. null,
  202. ['type' => 'text', 'length' => null]
  203. ],
  204. [
  205. 'REAL',
  206. null,
  207. null,
  208. null,
  209. ['type' => 'float', 'length' => null]
  210. ],
  211. [
  212. 'VARCHAR',
  213. -1,
  214. null,
  215. null,
  216. ['type' => 'text', 'length' => null]
  217. ],
  218. ];
  219. }
  220. /**
  221. * Test parsing Sqlserver column types from field description.
  222. *
  223. * @dataProvider convertColumnProvider
  224. * @return void
  225. */
  226. public function testConvertColumn($type, $length, $precision, $scale, $expected) {
  227. $field = [
  228. 'name' => 'field',
  229. 'type' => $type,
  230. 'null' => 'YES',
  231. 'default' => 'Default value',
  232. 'char_length' => $length,
  233. 'precision' => $precision,
  234. 'scale' => $scale
  235. ];
  236. $expected += [
  237. 'null' => true,
  238. 'default' => 'Default value',
  239. ];
  240. $driver = $this->getMock('Cake\Database\Driver\Sqlserver');
  241. $dialect = new SqlserverSchema($driver);
  242. $table = $this->getMock('Cake\Database\Schema\Table', [], ['table']);
  243. $table->expects($this->at(0))->method('addColumn')->with('field', $expected);
  244. $dialect->convertColumnDescription($table, $field);
  245. }
  246. /**
  247. * Test listing tables with Sqlserver
  248. *
  249. * @return void
  250. */
  251. public function testListTables() {
  252. $connection = ConnectionManager::get('test');
  253. $this->_createTables($connection);
  254. $schema = new SchemaCollection($connection);
  255. $result = $schema->listTables();
  256. $this->assertInternalType('array', $result);
  257. $this->assertContains('schema_articles', $result);
  258. $this->assertContains('schema_authors', $result);
  259. }
  260. /**
  261. * Test describing a table with Sqlserver
  262. *
  263. * @return void
  264. */
  265. public function testDescribeTable() {
  266. $connection = ConnectionManager::get('test');
  267. $this->_createTables($connection);
  268. $schema = new SchemaCollection($connection);
  269. $result = $schema->describe('schema_articles');
  270. $expected = [
  271. 'id' => [
  272. 'type' => 'biginteger',
  273. 'null' => false,
  274. 'default' => null,
  275. 'length' => 19,
  276. 'precision' => null,
  277. 'unsigned' => null,
  278. 'autoIncrement' => null,
  279. 'comment' => null,
  280. ],
  281. 'title' => [
  282. 'type' => 'string',
  283. 'null' => true,
  284. 'default' => null,
  285. 'length' => 20,
  286. 'precision' => null,
  287. 'comment' => null,
  288. 'fixed' => null,
  289. ],
  290. 'body' => [
  291. 'type' => 'string',
  292. 'null' => true,
  293. 'default' => null,
  294. 'length' => 1000,
  295. 'precision' => null,
  296. 'fixed' => null,
  297. 'comment' => null,
  298. ],
  299. 'author_id' => [
  300. 'type' => 'integer',
  301. 'null' => false,
  302. 'default' => null,
  303. 'length' => 10,
  304. 'precision' => null,
  305. 'unsigned' => null,
  306. 'autoIncrement' => null,
  307. 'comment' => null,
  308. ],
  309. 'published' => [
  310. 'type' => 'boolean',
  311. 'null' => true,
  312. 'default' => 0,
  313. 'length' => null,
  314. 'precision' => null,
  315. 'comment' => null,
  316. ],
  317. 'views' => [
  318. 'type' => 'integer',
  319. 'null' => true,
  320. 'default' => 0,
  321. 'length' => 5,
  322. 'precision' => null,
  323. 'unsigned' => null,
  324. 'autoIncrement' => null,
  325. 'comment' => null,
  326. ],
  327. 'created' => [
  328. 'type' => 'timestamp',
  329. 'null' => true,
  330. 'default' => null,
  331. 'length' => null,
  332. 'precision' => null,
  333. 'comment' => null,
  334. ],
  335. ];
  336. $this->assertEquals(['id'], $result->primaryKey());
  337. foreach ($expected as $field => $definition) {
  338. $this->assertEquals($definition, $result->column($field), 'Failed to match field ' . $field);
  339. }
  340. }
  341. /**
  342. * Test that describe accepts tablenames containing `schema.table`.
  343. *
  344. * @return void
  345. */
  346. public function testDescribeWithSchemaName() {
  347. $connection = ConnectionManager::get('test');
  348. $this->_createTables($connection);
  349. $schema = new SchemaCollection($connection);
  350. $result = $schema->describe('dbo.schema_articles');
  351. $this->assertEquals(['id'], $result->primaryKey());
  352. $this->assertEquals('schema_articles', $result->name());
  353. }
  354. /**
  355. * Test describing a table with indexes
  356. *
  357. * @return void
  358. */
  359. public function testDescribeTableIndexes() {
  360. $connection = ConnectionManager::get('test');
  361. $this->_createTables($connection);
  362. $schema = new SchemaCollection($connection);
  363. $result = $schema->describe('schema_articles');
  364. $this->assertInstanceOf('Cake\Database\Schema\Table', $result);
  365. $this->assertCount(3, $result->constraints());
  366. $expected = [
  367. 'primary' => [
  368. 'type' => 'primary',
  369. 'columns' => ['id'],
  370. 'length' => []
  371. ],
  372. 'content_idx' => [
  373. 'type' => 'unique',
  374. 'columns' => ['title', 'body'],
  375. 'length' => []
  376. ],
  377. 'author_idx' => [
  378. 'type' => 'foreign',
  379. 'columns' => ['author_id'],
  380. 'references' => ['schema_authors', 'id'],
  381. 'length' => [],
  382. 'update' => 'cascade',
  383. 'delete' => 'cascade',
  384. ]
  385. ];
  386. $this->assertEquals($expected['primary'], $result->constraint('primary'));
  387. $this->assertEquals($expected['content_idx'], $result->constraint('content_idx'));
  388. $this->assertEquals($expected['author_idx'], $result->constraint('author_idx'));
  389. $this->assertCount(1, $result->indexes());
  390. $expected = [
  391. 'type' => 'index',
  392. 'columns' => ['author_id'],
  393. 'length' => []
  394. ];
  395. $this->assertEquals($expected, $result->index('author_idx'));
  396. }
  397. /**
  398. * Column provider for creating column sql
  399. *
  400. * @return array
  401. */
  402. public static function columnSqlProvider() {
  403. return [
  404. // strings
  405. [
  406. 'title',
  407. ['type' => 'string', 'length' => 25, 'null' => false],
  408. '[title] NVARCHAR(25) NOT NULL'
  409. ],
  410. [
  411. 'title',
  412. ['type' => 'string', 'length' => 25, 'null' => true, 'default' => 'ignored'],
  413. '[title] NVARCHAR(25) DEFAULT NULL'
  414. ],
  415. [
  416. 'id',
  417. ['type' => 'string', 'length' => 32, 'fixed' => true, 'null' => false],
  418. '[id] NCHAR(32) NOT NULL'
  419. ],
  420. [
  421. 'id',
  422. ['type' => 'uuid', 'null' => false],
  423. '[id] UNIQUEIDENTIFIER NOT NULL'
  424. ],
  425. [
  426. 'role',
  427. ['type' => 'string', 'length' => 10, 'null' => false, 'default' => 'admin'],
  428. "[role] NVARCHAR(10) NOT NULL DEFAULT [admin]"
  429. ],
  430. [
  431. 'title',
  432. ['type' => 'string'],
  433. '[title] NVARCHAR(255)'
  434. ],
  435. // Text
  436. [
  437. 'body',
  438. ['type' => 'text', 'null' => false],
  439. '[body] NVARCHAR(MAX) NOT NULL'
  440. ],
  441. // Integers
  442. [
  443. 'post_id',
  444. ['type' => 'integer', 'length' => 11],
  445. '[post_id] INTEGER'
  446. ],
  447. [
  448. 'post_id',
  449. ['type' => 'biginteger', 'length' => 20],
  450. '[post_id] BIGINT'
  451. ],
  452. // Decimal
  453. [
  454. 'value',
  455. ['type' => 'decimal'],
  456. '[value] DECIMAL'
  457. ],
  458. [
  459. 'value',
  460. ['type' => 'decimal', 'length' => 11],
  461. '[value] DECIMAL(11,0)'
  462. ],
  463. [
  464. 'value',
  465. ['type' => 'decimal', 'length' => 12, 'precision' => 5],
  466. '[value] DECIMAL(12,5)'
  467. ],
  468. // Float
  469. [
  470. 'value',
  471. ['type' => 'float'],
  472. '[value] FLOAT'
  473. ],
  474. [
  475. 'value',
  476. ['type' => 'float', 'length' => 11, 'precision' => 3],
  477. '[value] FLOAT(3)'
  478. ],
  479. // Binary
  480. [
  481. 'img',
  482. ['type' => 'binary'],
  483. '[img] VARBINARY(MAX)'
  484. ],
  485. // Boolean
  486. [
  487. 'checked',
  488. ['type' => 'boolean', 'default' => false],
  489. '[checked] BIT DEFAULT 0'
  490. ],
  491. [
  492. 'checked',
  493. ['type' => 'boolean', 'default' => true, 'null' => false],
  494. '[checked] BIT NOT NULL DEFAULT 1'
  495. ],
  496. // datetimes
  497. [
  498. 'created',
  499. ['type' => 'datetime'],
  500. '[created] DATETIME'
  501. ],
  502. // Date & Time
  503. [
  504. 'start_date',
  505. ['type' => 'date'],
  506. '[start_date] DATE'
  507. ],
  508. [
  509. 'start_time',
  510. ['type' => 'time'],
  511. '[start_time] TIME'
  512. ],
  513. // timestamps
  514. [
  515. 'created',
  516. ['type' => 'timestamp', 'null' => true],
  517. '[created] DATETIME DEFAULT NULL'
  518. ],
  519. ];
  520. }
  521. /**
  522. * Test generating column definitions
  523. *
  524. * @dataProvider columnSqlProvider
  525. * @return void
  526. */
  527. public function testColumnSql($name, $data, $expected) {
  528. $driver = $this->_getMockedDriver();
  529. $schema = new SqlserverSchema($driver);
  530. $table = (new Table('schema_articles'))->addColumn($name, $data);
  531. $this->assertEquals($expected, $schema->columnSql($table, $name));
  532. }
  533. /**
  534. * Provide data for testing constraintSql
  535. *
  536. * @return array
  537. */
  538. public static function constraintSqlProvider() {
  539. return [
  540. [
  541. 'primary',
  542. ['type' => 'primary', 'columns' => ['title']],
  543. 'PRIMARY KEY ([title])'
  544. ],
  545. [
  546. 'unique_idx',
  547. ['type' => 'unique', 'columns' => ['title', 'author_id']],
  548. 'CONSTRAINT [unique_idx] UNIQUE ([title], [author_id])'
  549. ],
  550. [
  551. 'author_id_idx',
  552. ['type' => 'foreign', 'columns' => ['author_id'], 'references' => ['authors', 'id']],
  553. 'CONSTRAINT [author_id_idx] FOREIGN KEY ([author_id]) ' .
  554. 'REFERENCES [authors] ([id]) ON UPDATE SET NULL ON DELETE SET NULL'
  555. ],
  556. [
  557. 'author_id_idx',
  558. ['type' => 'foreign', 'columns' => ['author_id'], 'references' => ['authors', 'id'], 'update' => 'cascade'],
  559. 'CONSTRAINT [author_id_idx] FOREIGN KEY ([author_id]) ' .
  560. 'REFERENCES [authors] ([id]) ON UPDATE CASCADE ON DELETE SET NULL'
  561. ],
  562. [
  563. 'author_id_idx',
  564. ['type' => 'foreign', 'columns' => ['author_id'], 'references' => ['authors', 'id'], 'update' => 'setDefault'],
  565. 'CONSTRAINT [author_id_idx] FOREIGN KEY ([author_id]) ' .
  566. 'REFERENCES [authors] ([id]) ON UPDATE SET DEFAULT ON DELETE SET NULL'
  567. ],
  568. [
  569. 'author_id_idx',
  570. ['type' => 'foreign', 'columns' => ['author_id'], 'references' => ['authors', 'id'], 'update' => 'setNull'],
  571. 'CONSTRAINT [author_id_idx] FOREIGN KEY ([author_id]) ' .
  572. 'REFERENCES [authors] ([id]) ON UPDATE SET NULL ON DELETE SET NULL'
  573. ],
  574. [
  575. 'author_id_idx',
  576. ['type' => 'foreign', 'columns' => ['author_id'], 'references' => ['authors', 'id'], 'update' => 'noAction'],
  577. 'CONSTRAINT [author_id_idx] FOREIGN KEY ([author_id]) ' .
  578. 'REFERENCES [authors] ([id]) ON UPDATE NO ACTION ON DELETE SET NULL'
  579. ],
  580. ];
  581. }
  582. /**
  583. * Test the constraintSql method.
  584. *
  585. * @dataProvider constraintSqlProvider
  586. */
  587. public function testConstraintSql($name, $data, $expected) {
  588. $driver = $this->_getMockedDriver();
  589. $schema = new SqlserverSchema($driver);
  590. $table = (new Table('schema_articles'))->addColumn('title', [
  591. 'type' => 'string',
  592. 'length' => 255
  593. ])->addColumn('author_id', [
  594. 'type' => 'integer',
  595. ])->addConstraint($name, $data);
  596. $this->assertEquals($expected, $schema->constraintSql($table, $name));
  597. }
  598. /**
  599. * Integration test for converting a Schema\Table into MySQL table creates.
  600. *
  601. * @return void
  602. */
  603. public function testCreateSql() {
  604. $driver = $this->_getMockedDriver();
  605. $connection = $this->getMock('Cake\Database\Connection', [], [], '', false);
  606. $connection->expects($this->any())->method('driver')
  607. ->will($this->returnValue($driver));
  608. $table = (new Table('schema_articles'))->addColumn('id', [
  609. 'type' => 'integer',
  610. 'null' => false
  611. ])
  612. ->addColumn('title', [
  613. 'type' => 'string',
  614. 'null' => false,
  615. ])
  616. ->addColumn('body', ['type' => 'text'])
  617. ->addColumn('created', 'datetime')
  618. ->addConstraint('primary', [
  619. 'type' => 'primary',
  620. 'columns' => ['id'],
  621. ])
  622. ->addIndex('title_idx', [
  623. 'type' => 'index',
  624. 'columns' => ['title'],
  625. ]);
  626. $expected = <<<SQL
  627. CREATE TABLE [schema_articles] (
  628. [id] INTEGER IDENTITY(1, 1),
  629. [title] NVARCHAR(255) NOT NULL,
  630. [body] NVARCHAR(MAX),
  631. [created] DATETIME,
  632. PRIMARY KEY ([id])
  633. )
  634. SQL;
  635. $result = $table->createSql($connection);
  636. $this->assertCount(2, $result);
  637. $this->assertEquals(str_replace("\r\n", "\n", $expected), str_replace("\r\n", "\n", $result[0]));
  638. $this->assertEquals(
  639. 'CREATE INDEX [title_idx] ON [schema_articles] ([title])',
  640. $result[1]
  641. );
  642. }
  643. /**
  644. * test dropSql
  645. *
  646. * @return void
  647. */
  648. public function testDropSql() {
  649. $driver = $this->_getMockedDriver();
  650. $connection = $this->getMock('Cake\Database\Connection', [], [], '', false);
  651. $connection->expects($this->any())->method('driver')
  652. ->will($this->returnValue($driver));
  653. $table = new Table('schema_articles');
  654. $result = $table->dropSql($connection);
  655. $this->assertCount(1, $result);
  656. $this->assertEquals('DROP TABLE [schema_articles]', $result[0]);
  657. }
  658. /**
  659. * Test truncateSql()
  660. *
  661. * @return void
  662. */
  663. public function testTruncateSql() {
  664. $driver = $this->_getMockedDriver();
  665. $connection = $this->getMock('Cake\Database\Connection', [], [], '', false);
  666. $connection->expects($this->any())->method('driver')
  667. ->will($this->returnValue($driver));
  668. $table = new Table('schema_articles');
  669. $table->addColumn('id', 'integer')
  670. ->addConstraint('primary', [
  671. 'type' => 'primary',
  672. 'columns' => ['id']
  673. ]);
  674. $result = $table->truncateSql($connection);
  675. $this->assertCount(2, $result);
  676. $this->assertEquals('DELETE FROM [schema_articles]', $result[0]);
  677. $this->assertEquals('DBCC CHECKIDENT([schema_articles], RESEED, 0)', $result[1]);
  678. }
  679. /**
  680. * Get a schema instance with a mocked driver/pdo instances
  681. *
  682. * @return Driver
  683. */
  684. protected function _getMockedDriver() {
  685. $driver = new \Cake\Database\Driver\Sqlserver();
  686. $mock = $this->getMock('FakePdo', ['quote', 'quoteIdentifier']);
  687. $mock->expects($this->any())
  688. ->method('quote')
  689. ->will($this->returnCallback(function ($value) {
  690. return '[' . $value . ']';
  691. }));
  692. $mock->expects($this->any())
  693. ->method('quoteIdentifier')
  694. ->will($this->returnCallback(function ($value) {
  695. return '[' . $value . ']';
  696. }));
  697. $driver->connection($mock);
  698. return $driver;
  699. }
  700. }