ClientTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/11/22 0022
  6. * Time: 20:08
  7. */
  8. namespace EasySwoole\Mysqli\Tests;
  9. use EasySwoole\Mysqli\Client;
  10. use PHPUnit\Framework\TestCase;
  11. class ClientTest extends TestCase
  12. {
  13. /**
  14. * @var Client
  15. */
  16. protected $client;
  17. protected function setUp(): void
  18. {
  19. parent::setUp(); // TODO: Change the autogenerated stub
  20. $config = new \EasySwoole\Mysqli\Config(MYSQL_CONFIG);
  21. $this->client = new \EasySwoole\Mysqli\Client($config);
  22. }
  23. public function testAdd()
  24. {
  25. $this->client->queryBuilder()->insert("user_test_list", [
  26. 'name' => 'siam,你好',
  27. 'age' => 21,
  28. 'addTime' => "2019-11-22 20:19:16",
  29. 'state' => 1
  30. ]);
  31. $res = $this->client->execBuilder();
  32. $this->assertTrue($res !== null);
  33. }
  34. public function testGet()
  35. {
  36. $this->client->queryBuilder()->where('find_in_set(?, name)', ['siam'])->get('user_test_list');
  37. $res = $this->client->execBuilder();
  38. $this->assertEquals("siam,你好", $res[0]['name']);
  39. $this->client->queryBuilder()->where('find_in_set(?, name)', ['不存在的你'])->get('user_test_list');
  40. $res = $this->client->execBuilder();
  41. $this->assertEquals([], $res);
  42. }
  43. public function testInsertAll()
  44. {
  45. $this->client->queryBuilder()->insertAll("user_test_list", [
  46. [
  47. 'name' => 'siam,你好',
  48. 'age' => 21,
  49. 'addTime' => "2019-11-22 20:19:16",
  50. 'state' => 1
  51. ],
  52. [
  53. 'name' => 'siam,你好',
  54. 'age' => 21,
  55. 'addTime' => "2019-11-22 20:19:16",
  56. 'state' => 2
  57. ]
  58. ]);
  59. $res = $this->client->execBuilder();
  60. // var_dump($this->client->mysqlClient()->insert_id);
  61. // insert_id 是第一行的
  62. $this->assertTrue($res);
  63. $this->assertEquals($this->client->mysqlClient()->affected_rows, 2);
  64. }
  65. public function testDelete()
  66. {
  67. $this->client->queryBuilder()->delete("user_test_list");
  68. $res = $this->client->execBuilder();
  69. $this->assertTrue($res);
  70. $this->assertEquals($this->client->mysqlClient()->affected_rows, 3);
  71. }
  72. }