Get a count of how many queries have been run
public static queryCount ( ) : integer | ||
return | integer | Total number of queries that have been run |
public function testQueryCountIsNotCachedForDifferentQueryResult() { $mapper = test_spot_mapper(); $posts = $mapper->all('\\Spot\\Entity\\Post'); $this->assertEquals(10, $posts->count()); // Count # of queries $count1 = \Spot\Log::queryCount(); // Change query so count will NOT be cached $this->assertEquals(3, $posts->where(array('status' => array(3, 4, 5)))->count()); // Count again to ensure it is NOT cached since there are query changes $count2 = \Spot\Log::queryCount(); $this->assertNotEquals($count1, $count2); }
/** * Debug Spot queries by dumping query log */ public function debugQueryLog() { if ($this->kernel->config('app.debug')) { // Executed queries echo "<hr />"; echo "<h1>Executed Queries (" . \Spot\Log::queryCount() . ")</h1>"; echo "<pre>"; print_r(\Spot\Log::queries()); echo "</pre>"; } }
public function testQueryHasOneWith() { $mapper = test_spot_mapper(); $count1 = \Spot\Log::queryCount(); $posts = $mapper->all('Entity_Post')->with(array('author'))->execute(); $count2 = \Spot\Log::queryCount(); // @todo: Theoretically, 'HasOne' calls could be added as JOIN $this->assertEquals($count1 + 2, $count2); foreach ($posts as $post) { $this->assertEquals($post->author_id, $post->author->id); $this->assertInstanceOf('\\Spot\\Relation\\HasOne', $post->author); } $count3 = \Spot\Log::queryCount(); $this->assertEquals($count1 + 2, $count3); }