connection = new Connection($config); DbManager::getInstance()->addConnection($this->connection); $connection = DbManager::getInstance()->getConnection(); $this->assertTrue($connection === $this->connection); } public function testGet() { try { $model = TestUserModel::create(); $testUserModel = $model->where("xxx", 1)->get(""); $this->assertFalse($testUserModel); if ($model->lastQueryResult()->getLastErrorNo() !== 0) { $this->assertIsString($model->lastQueryResult()->getLastError()); } } catch (Exception $e) { $this->assertNotFalse(strpos($e->getMessage(), "SQLSTATE[42S22] [1054] Unknown column 'xxx' in 'where clause'")); } catch (\Throwable $e) { } } // 全部字段为null id自增 public function testSaveNull() {// 没有准备表结构 本地临时测试通过 // $model = TestUserListModel::create(); // $res = $model->save(); // $this->assertIsInt($res); } public function testThrow() { // 不存在的字段 where 抛出异常 try { $test = TestUserModel::create()->get([ 'fuck_life' => 1 ]); } catch (Exception $e) { $this->assertEquals("SQLSTATE[42S22] [1054] Unknown column 'fuck_life' in 'where clause' [SELECT * FROM `test_user_model` WHERE `fuck_life` = 1 LIMIT 1]", $e->getMessage()); } catch (\Throwable $e) { } } }