ConnectErrorTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * 连接错误
  4. * User: Administrator
  5. * Date: 2019/11/16 0016
  6. * Time: 10:05
  7. */
  8. namespace EasySwoole\ORM\Tests;
  9. use EasySwoole\ORM\Db\Config;
  10. use EasySwoole\ORM\Db\Connection;
  11. use EasySwoole\ORM\Db\MysqlPool;
  12. use EasySwoole\ORM\DbManager;
  13. use EasySwoole\ORM\Exception\Exception;
  14. use EasySwoole\Pool\Exception\PoolEmpty;
  15. use PHPUnit\Framework\TestCase;
  16. class ConnectErrorTest extends TestCase
  17. {
  18. private $connection;
  19. private $config;
  20. protected function setUp(): void
  21. {
  22. parent::setUp(); // TODO: Change the autogenerated stub
  23. $config = new Config([
  24. 'host' => '127.0.0.1',
  25. 'port' => 3306,
  26. 'user' => 'error',
  27. 'password' => 'error',
  28. 'database' => 'demo',
  29. 'timeout' => 5,
  30. 'charset' => 'utf8mb4',
  31. ]);
  32. $this->config = $config;
  33. $this->connection = new Connection($config);
  34. DbManager::getInstance()->addConnection($this->connection, 'error');
  35. }
  36. public function testConnect()
  37. {
  38. /** @var Connection $connection */
  39. $connection = DbManager::getInstance()->getConnection('error');
  40. $pool = new MysqlPool($this->config);
  41. try {
  42. $obj = $pool->defer(1);
  43. } catch (\Exception $e) {
  44. $this->assertInstanceOf(Exception::class, $e);
  45. }
  46. }
  47. }