RetryDriver.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 4.2.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace TestApp\Database\Driver;
  17. use Cake\Database\Driver\Sqlserver;
  18. use Cake\Datasource\ConnectionManager;
  19. class RetryDriver extends Sqlserver
  20. {
  21. /**
  22. * @inheritDoc
  23. */
  24. protected const RETRY_ERROR_CODES = [18456];
  25. /**
  26. * @inheritDoc
  27. */
  28. public function connect(): void
  29. {
  30. $testConfig = ConnectionManager::get('test')->config() + $this->_baseConfig;
  31. $dsn = "sqlsrv:Server={$testConfig['host']};Database={$testConfig['database']}";
  32. $this->pdo = $this->createPdo($dsn, ['username' => 'invalid', 'password' => '', 'flags' => []]);
  33. }
  34. public function getConnectRetries(): int
  35. {
  36. return $this->connectRetries;
  37. }
  38. public function enabled(): bool
  39. {
  40. return true;
  41. }
  42. }