Angejia\Pea\ModelTest::testPartialCachedSimpleGet PHP Method

testPartialCachedSimpleGet() public method

    public function testPartialCachedSimpleGet()
    {
        $this->cache->shouldReceive('get')->with(['3558193cd9818af7fe4d2c2f5bd9d00f', '343a10e6c2480e111dd3e9e564eb7966'])->andReturn(['3558193cd9818af7fe4d2c2f5bd9d00f' => (object) ['id' => 1, 'name' => '海涛']]);
        // 模拟数据库返回查询未命中缓存的数据
        $this->conn->shouldReceive('select')->with('select * from "user" where "id" in (?)', [2], true)->andReturn([(object) ['id' => 2, 'name' => '涛涛']]);
        // 查询完成后需要将数据写入缓存
        $this->cache->shouldReceive('set')->with(['343a10e6c2480e111dd3e9e564eb7966' => (object) ['id' => 2, 'name' => '涛涛']]);
        $dispatcher = M::Mock(Dispatcher::class);
        $dispatcher->shouldReceive('fire')->with('angejia.pea.get', ['table' => 'user', 'db' => 'angejia']);
        $dispatcher->shouldReceive('fire')->with('angejia.pea.hit.simple.500', ['table' => 'user', 'db' => 'angejia']);
        $this->app->instance(Dispatcher::class, $dispatcher);
        list($u1, $u2) = User::find([1, 2]);
        $this->assertEquals('海涛', $u1->name);
        $this->assertEquals('涛涛', $u2->name);
    }