public function testCURD() { $this->operator->reset(); $mock = ['name' => 'hello', 'email' => '*****@*****.**', 'password' => md5('123456'), 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]; $user = $this->operator->insert($mock); $this->assertArrayHasKey('id', $user); $obj = $this->operator->reset()->findById($user['id']); $this->assertNotEmpty($obj); $this->assertEquals($user['name'], $obj['name']); $this->operator->reset()->upsertById(['id' => $user['id'], 'name' => 'world', 'email' => '*****@*****.**']); $obj = $this->operator->reset()->findByOne(['name' => 'hello']); $this->assertEmpty($obj); $obj = $this->operator->reset()->findBy(['name' => 'world']); $this->assertNotEmpty($obj); $this->assertEquals('world', $obj[0]['name']); $this->operator->reset()->insert($mock); $set = $this->operator->reset()->findBy([]); $this->assertEquals(2, count($set)); $mock['email'] = '*****@*****.**'; $this->operator->reset()->add($mock, ['name']); $set = $this->operator->reset()->findBy([]); $this->assertEquals(2, count($set)); $this->operator->reset()->add($mock, ['email']); $set = $this->operator->reset()->findBy([]); $this->assertEquals(3, count($set)); $this->operator->reset()->delete(); }
/** * 插入记录 * @param array $obj * @return bool|array 成功返回带id的对象,否则返回false */ function insert($obj) { $orig = $obj; if (isset($obj['value'])) { $obj['value'] = json_encode($obj['value']); } $obj = parent::insert($obj); return array_replace($obj, $orig); }