Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Propel] Added tests for the PropelDataCollector
- Loading branch information
1 parent
d9ce982
commit 97cbf90
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
tests/Symfony/Tests/Bridge/Propel1/DataCollector/PropelDataCollectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Tests\Bridge\Propel1\DataCollector; | ||
|
||
use Symfony\Bridge\Propel1\DataCollector\PropelDataCollector; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Tests\Bridge\Propel1\Propel1TestCase; | ||
|
||
class PropelDataCollectorTest extends Propel1TestCase | ||
{ | ||
public function testCollectWithoutData() | ||
{ | ||
$c = $this->createCollector(array()); | ||
$c->collect(new Request(), new Response()); | ||
|
||
$this->assertEquals(array(), $c->getQueries()); | ||
$this->assertEquals(0, $c->getQueryCount()); | ||
} | ||
|
||
public function testCollectWithData() | ||
{ | ||
$queries = array( | ||
"time: 0.000 sec | mem: 1.4 MB | SET NAMES 'utf8'", | ||
); | ||
|
||
$c = $this->createCollector($queries); | ||
$c->collect(new Request(), new Response()); | ||
|
||
$this->assertEquals(array( | ||
array( | ||
'sql' => "SET NAMES 'utf8'", | ||
'time' => '0.000 sec', | ||
'memory' => '1.4 MB' | ||
) | ||
), $c->getQueries()); | ||
$this->assertEquals(1, $c->getQueryCount()); | ||
} | ||
|
||
public function testCollectWithMultipleData() | ||
{ | ||
$queries = array( | ||
"time: 0.000 sec | mem: 1.4 MB | SET NAMES 'utf8'", | ||
"time: 0.012 sec | mem: 2.4 MB | SELECT tags.NAME, image.FILENAME FROM tags LEFT JOIN image ON tags.IMAGEID = image.ID WHERE image.ID = 12" | ||
); | ||
|
||
$c = $this->createCollector($queries); | ||
$c->collect(new Request(), new Response()); | ||
|
||
$this->assertEquals(array( | ||
array( | ||
'sql' => "SET NAMES 'utf8'", | ||
'time' => '0.000 sec', | ||
'memory' => '1.4 MB' | ||
), | ||
array( | ||
'sql' => "SELECT tags.NAME, image.FILENAME FROM tags LEFT JOIN image ON tags.IMAGEID = image.ID WHERE image.ID = 12", | ||
'time' => '0.012 sec', | ||
'memory' => '2.4 MB' | ||
) | ||
), $c->getQueries()); | ||
$this->assertEquals(2, $c->getQueryCount()); | ||
} | ||
|
||
private function createCollector($queries) | ||
{ | ||
$config = $this->getMock('\PropelConfiguration'); | ||
$config | ||
->expects($this->any()) | ||
->method('getParameter') | ||
->will($this->returnArgument(1)) | ||
; | ||
|
||
$logger = $this->getMock('\Symfony\Bridge\Propel1\Logger\PropelLogger'); | ||
$logger | ||
->expects($this->any()) | ||
->method('getQueries') | ||
->will($this->returnValue($queries)) | ||
; | ||
|
||
return new PropelDataCollector($logger, $config); | ||
} | ||
} |