EmptyTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * 空属性字段
  4. * User: Administrator
  5. * Date: 2019/10/28 0028
  6. * Time: 18:52
  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\TestUserListModel;
  14. class EmptyTest 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 TestUserListModel();
  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 testEmpty()
  41. {
  42. $test = TestUserListModel::create()->where(['name' => 'Siam'])->get();
  43. $res = !empty($test->name);
  44. $resNot = !empty($test->testaaa);
  45. $this->assertTrue($res);
  46. $this->assertNotTrue($resNot);
  47. }
  48. public function testIsset()
  49. {
  50. $test = TestUserListModel::create()->where(['name' => 'Siam'])->get();
  51. $res = isset($test->name);
  52. $resNot = isset($test->testaaa);
  53. $this->assertTrue($res);
  54. $this->assertNotTrue($resNot);
  55. }
  56. public function testDeleteAll()
  57. {
  58. $res = TestUserListModel::create()->destroy(null, true);
  59. $this->assertIsInt($res);
  60. }
  61. }