connection = new Connection($config); DbManager::getInstance()->addConnection($this->connection); $connection = DbManager::getInstance()->getConnection(); $this->assertTrue($connection === $this->connection); } /** * @throws \EasySwoole\ORM\Exception\Exception * @throws \Throwable */ public function testInsertInt() { $user = TestTimeStampModel::create(); $user->name = 'siam'; $user->age = 21; $res = $user->save(); $this->assertIsInt($user->id); $this->assertIsInt($user->create_at); $this->assertIsInt($user->update_at); } /** * @throws \EasySwoole\Mysqli\Exception\Exception * @throws \EasySwoole\ORM\Exception\Exception * @throws \Throwable */ public function testUpdateInt() { $user = TestTimeStampModel::create()->get([ 'name' => 'siam' ]); $user->age = 22; $time = $user->update_at; sleep(1); $user->update(); $this->assertTrue(($user->update_at - $time) > 0); } /** * @throws \EasySwoole\ORM\Exception\Exception * @throws \Throwable */ public function testInsertDate() { $user = TestTimeStampModel::create(); $user->setAutoTime('datetime'); $user->setCreateTime('create_time'); $user->setUpdateTime('update_time'); $user->name = 'siam_date'; $user->age = 21; $res = $user->save(); $this->assertIsInt($user->id); $this->assertIsInt(strtotime($user->create_time)); $this->assertIsInt(strtotime($user->update_time)); } /** * @throws \EasySwoole\Mysqli\Exception\Exception * @throws \EasySwoole\ORM\Exception\Exception * @throws \Throwable */ public function testUpdateDate() { $user = TestTimeStampModel::create(); $user = $user->get([ 'name' => 'siam_date' ]); // get返回的是一个新模型 需要在这里设置 $user->setAutoTime('datetime'); $user->setCreateTime('create_time'); $user->setUpdateTime('update_time'); $user->age = 22; sleep(1); $time = date('Y-m-d H:i:s'); $user->update(); $this->assertEquals($time, $user->update_time); } /** * @throws \EasySwoole\ORM\Exception\Exception * @throws \Throwable */ public function testDeleteAll() { $res = TestTimeStampModel::create()->destroy(null, true); $this->assertIsInt($res); } }