connection = new Connection($config); DbManager::getInstance()->addConnection($this->connection); $connection = DbManager::getInstance()->getConnection(); $this->assertTrue($connection === $this->connection); } public function testAdd() { $testUserModel = new TestUserModel(); $testUserModel->state = 1; $testUserModel->name = 'Siam'; $testUserModel->age = 100; $testUserModel->addTime = date('Y-m-d H:i:s'); $data = $testUserModel->save(); $this->assertIsInt($data); $testUserModel = new TestUserModel(); $testUserModel->state = 1; $testUserModel->name = 'Siam222'; $testUserModel->age = 100; $testUserModel->addTime = date('Y-m-d H:i:s'); $data = $testUserModel->save(); $this->assertIsInt($data); } public function testGet() { $user = TestUserModel::create()->get(function (QueryBuilder $queryBuilder) { $queryBuilder->where('name', 'Siam222'); $queryBuilder->fields(['name', 'age']); }); $this->assertNotEmpty($user->age); $this->assertEmpty($user->state); $this->assertEmpty($user->addTime); } public function testUpdate() { $test = TestUserModel::create()->update([ 'age' => QueryBuilder::inc(3) ], [ 'name' => 'Siam222' ]); $this->assertTrue($test); $user = TestUserModel::create()->get(function (QueryBuilder $queryBuilder) { $queryBuilder->where('name', 'Siam222'); $queryBuilder->fields(['name', 'age']); }); $this->assertEquals(103, $user->age); } public function testDeleteAll() { $res = TestUserListModel::create()->destroy(null, true); $this->assertIsInt($res); $test = TestUserModel::create()->destroy(null, true); $this->assertIsInt($test); } }