123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- /**
- * 获取器(取出一次执行一次getAttr)
- * User: Siam
- * Date: 2019/10/24
- * Time: 11:31
- */
- namespace EasySwoole\ORM\Tests;
- use EasySwoole\ORM\Db\Config;
- use EasySwoole\ORM\Db\Connection;
- use EasySwoole\ORM\DbManager;
- use PHPUnit\Framework\TestCase;
- use EasySwoole\ORM\Tests\models\TestUserListGetterModel;
- class GetterTest extends TestCase
- {
- /**
- * @var $connection Connection
- */
- protected $connection;
- protected $tableName = 'user_test_list';
- protected function setUp(): void
- {
- parent::setUp(); // TODO: Change the autogenerated stub
- $config = new Config(MYSQL_CONFIG);
- $this->connection = new Connection($config);
- DbManager::getInstance()->addConnection($this->connection);
- $connection = DbManager::getInstance()->getConnection();
- $this->assertTrue($connection === $this->connection);
- }
- public function testAdd()
- {
- $testUserModel = new TestUserListGetterModel();
- $testUserModel->state = 1;
- $testUserModel->name = 'Siam';
- $testUserModel->age = 18;
- $testUserModel->addTime = date('Y-m-d H:i:s');
- $data = $testUserModel->save();
- $this->assertIsInt($data);
- }
- public function testGetter()
- {
- $test = TestUserListGetterModel::create()->all();
- $this->assertEquals($test[0]->addTime, 123);
- }
- public function testGetterJson()
- {
- $test = TestUserListGetterModel::create()->all();
- $json = json_encode($test);
- $decode = json_decode($json);
- $this->assertEquals($decode[0]->addTime, 123);
- }
- public function testDeleteAll()
- {
- $res = TestUserListGetterModel::create()->destroy(null, true);
- $this->assertIsInt($res);
- }
- }
|