GetterTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * 获取器(取出一次执行一次getAttr)
  4. * User: Siam
  5. * Date: 2019/10/24
  6. * Time: 11:31
  7. */
  8. namespace EasySwoole\ORM\Tests;
  9. use EasySwoole\ORM\Db\Config;
  10. use EasySwoole\ORM\Db\Connection;
  11. use EasySwoole\ORM\DbManager;
  12. use PHPUnit\Framework\TestCase;
  13. use EasySwoole\ORM\Tests\models\TestUserListGetterModel;
  14. class GetterTest extends TestCase
  15. {
  16. /**
  17. * @var $connection Connection
  18. */
  19. protected $connection;
  20. protected $tableName = 'user_test_list';
  21. protected function setUp(): void
  22. {
  23. parent::setUp(); // TODO: Change the autogenerated stub
  24. $config = new Config(MYSQL_CONFIG);
  25. $this->connection = new Connection($config);
  26. DbManager::getInstance()->addConnection($this->connection);
  27. $connection = DbManager::getInstance()->getConnection();
  28. $this->assertTrue($connection === $this->connection);
  29. }
  30. public function testAdd()
  31. {
  32. $testUserModel = new TestUserListGetterModel();
  33. $testUserModel->state = 1;
  34. $testUserModel->name = 'Siam';
  35. $testUserModel->age = 18;
  36. $testUserModel->addTime = date('Y-m-d H:i:s');
  37. $data = $testUserModel->save();
  38. $this->assertIsInt($data);
  39. }
  40. public function testGetter()
  41. {
  42. $test = TestUserListGetterModel::create()->all();
  43. $this->assertEquals($test[0]->addTime, 123);
  44. }
  45. public function testGetterJson()
  46. {
  47. $test = TestUserListGetterModel::create()->all();
  48. $json = json_encode($test);
  49. $decode = json_decode($json);
  50. $this->assertEquals($decode[0]->addTime, 123);
  51. }
  52. public function testDeleteAll()
  53. {
  54. $res = TestUserListGetterModel::create()->destroy(null, true);
  55. $this->assertIsInt($res);
  56. }
  57. }