Pheasant\Tests\Relationships\IncludesTest::testIncludesHitsCache PHP Method

testIncludesHitsCache() public method

    public function testIncludesHitsCache()
    {
        $queries = 0;
        $this->connection()->filterChain()->onQuery(function ($sql) use(&$queries) {
            ++$queries;
            return $sql;
        });
        // the first lookup of SecretIdentity should cache all the rest
        $heros = Hero::all()->includes(array('SecretIdentity'))->toArray();
        $this->assertNotNull($heros[0]->SecretIdentity);
        // these should be from cache
        $queries = 0;
        $this->assertNotNull($heros[1]->SecretIdentity);
        $this->assertNotNull($heros[2]->SecretIdentity);
        $this->assertEquals(0, $queries, "this should have hit the cache");
    }