CursorTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * 游标模式
  4. * User: haoxu
  5. * Date: 2020-01-15
  6. * Time: 14:42
  7. */
  8. namespace EasySwoole\ORM\Tests;
  9. use EasySwoole\ORM\Db\Config;
  10. use EasySwoole\ORM\Db\Cursor;
  11. use EasySwoole\ORM\DbManager;
  12. use PHPUnit\Framework\TestCase;
  13. use EasySwoole\ORM\Db\Connection;
  14. use Swoole\Coroutine\MySQL\Statement;
  15. use EasySwoole\ORM\Tests\models\TestUserModel;
  16. class CursorTest extends TestCase
  17. {
  18. /**
  19. * @var $connection Connection
  20. */
  21. protected $connection;
  22. protected $tableName = 'user_test_list';
  23. protected function setUp(): void
  24. {
  25. parent::setUp(); // TODO: Change the autogenerated stub
  26. $config = new Config(MYSQL_CONFIG);
  27. $config->setFetchMode(true);
  28. $this->connection = new Connection($config);
  29. DbManager::getInstance()->addConnection($this->connection);
  30. $connection = DbManager::getInstance()->getConnection();
  31. $this->assertTrue($connection === $this->connection);
  32. }
  33. public function testAdd()
  34. {
  35. $testUserModel = new TestUserModel();
  36. $testUserModel->state = 1;
  37. $testUserModel->name = 'Siam';
  38. $testUserModel->age = 18;
  39. $testUserModel->addTime = date('Y-m-d H:i:s');
  40. $data = $testUserModel->save(false, false);
  41. $this->assertIsInt($data);
  42. }
  43. public function testQuery()
  44. {
  45. $cursor = TestUserModel::create()->all();
  46. $this->assertInstanceOf(Cursor::class, $cursor);
  47. }
  48. public function testCursorNotArray()
  49. {
  50. $cursor = TestUserModel::create()->all();
  51. $item = $cursor->fetch();
  52. $this->assertInstanceOf(TestUserModel::class, $item);
  53. }
  54. }