/** * @param null $columns * @return Select */ public function select($columns = null) { $select = new Select(); $select->setConnection($this->getConnectionManager()->getReadConnection())->table($this->getName()); if ($this->cacheManager) { $select->setCacheManager($this->cacheManager); } if ($columns) { $select->select($columns); } return $select; }
/** * @return int */ public function foundRows() { if (null === $this->foundRows) { $this->foundRows = $this->select->foundRows(); } return $this->foundRows; }
public function testFoundRowsWithCacheAndCacheReturnsFalse() { $stmt = $this->getMock('stmt', ['fetchColumn']); $stmt->expects($this->once())->method('fetchColumn')->willReturn('10'); $connection = $this->getMock('Sloths\\Db\\Connection', ['query'], ['dsn']); $connection->expects($this->once())->method('query')->with("SELECT COUNT(*) FROM users")->willReturn($stmt); $cacheKey = Select::CACHE_KEY_PREFIX . '.' . md5("SELECT COUNT(*) FROM users"); $cacheManager = $this->getMock('Sloths\\Cache\\CacheManager', ['get', 'set']); $cacheManager->expects($this->once())->method('get')->with($cacheKey)->willReturnCallback(function ($key, &$success) { $success = false; }); $cacheManager->expects($this->once())->method('set')->with($cacheKey, 10); $select = new Select(); $select->setConnection($connection)->setCacheManager($cacheManager)->table('users')->remember(10); $this->assertSame(10, $select->foundRows()); }