SqlserverTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * PHP Version 5.4
  4. *
  5. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice.
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://cakephp.org CakePHP(tm) Project
  14. * @since CakePHP(tm) v 3.0.0
  15. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  16. */
  17. namespace Cake\Test\TestCase\Database\Driver;
  18. use Cake\Core\Configure;
  19. use Cake\Database\Connection;
  20. use Cake\Database\Driver\Sqlserver;
  21. use Cake\Database\Query;
  22. use \PDO;
  23. /**
  24. * Tests Sqlserver driver
  25. */
  26. class SqlserverTest extends \Cake\TestSuite\TestCase {
  27. /**
  28. * Test connecting to Sqlserver with custom configuration
  29. *
  30. * @return void
  31. */
  32. public function testConnectionConfigCustom() {
  33. $config = [
  34. 'persistent' => false,
  35. 'host' => 'foo',
  36. 'login' => 'Administrator',
  37. 'password' => 'blablabla',
  38. 'database' => 'bar',
  39. 'encoding' => 'a-language',
  40. 'flags' => [1 => true, 2 => false],
  41. 'init' => ['Execute this', 'this too'],
  42. 'settings' => ['config1' => 'value1', 'config2' => 'value2'],
  43. ];
  44. $driver = $this->getMock(
  45. 'Cake\Database\Driver\Sqlserver',
  46. ['_connect', 'connection'],
  47. [$config]
  48. );
  49. $expected = $config;
  50. $expected['dsn'] = 'sqlsrv:Server=foo;Database=bar';
  51. $expected['flags'] += [
  52. PDO::ATTR_PERSISTENT => false,
  53. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  54. PDO::SQLSRV_ATTR_ENCODING => 'a-language'
  55. ];
  56. $connection = $this->getMock('stdClass', ['exec', 'quote']);
  57. $connection->expects($this->any())
  58. ->method('quote')
  59. ->will($this->onConsecutiveCalls(
  60. $this->returnArgument(0),
  61. $this->returnArgument(0),
  62. $this->returnArgument(0)
  63. ));
  64. $connection->expects($this->at(0))->method('exec')->with('Execute this');
  65. $connection->expects($this->at(1))->method('exec')->with('this too');
  66. $connection->expects($this->at(2))->method('exec')->with('SET config1 value1');
  67. $connection->expects($this->at(3))->method('exec')->with('SET config2 value2');
  68. $driver->connection($connection);
  69. $driver->expects($this->once())->method('_connect')
  70. ->with($expected);
  71. $driver->expects($this->any())->method('connection')
  72. ->will($this->returnValue($connection));
  73. $driver->connect();
  74. }
  75. }