/
PropelDataCollectorTest.php
111 lines (95 loc) · 3.58 KB
/
PropelDataCollectorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?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\Bridge\Propel1\Tests\DataCollector;
use Symfony\Bridge\Propel1\DataCollector\PropelDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bridge\Propel1\Tests\Propel1TestCase;
class PropelDataCollectorTest extends Propel1TestCase
{
protected function setUp()
{
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
$this->markTestSkipped('The "HttpFoundation" component is not available');
}
}
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 | connection: default | 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',
'connection' => 'default',
'memory' => '1.4 MB',
),
), $c->getQueries());
$this->assertEquals(1, $c->getQueryCount());
}
public function testCollectWithMultipleData()
{
$queries = array(
"time: 0.000 sec | mem: 1.4 MB | connection: default | SET NAMES 'utf8'",
"time: 0.012 sec | mem: 2.4 MB | connection: default | SELECT tags.NAME, image.FILENAME FROM tags LEFT JOIN image ON tags.IMAGEID = image.ID WHERE image.ID = 12",
"time: 0.012 sec | mem: 2.4 MB | connection: default | INSERT INTO `table` (`some_array`) VALUES ('| 1 | 2 | 3 |')",
);
$c = $this->createCollector($queries);
$c->collect(new Request(), new Response());
$this->assertEquals(array(
array(
'sql' => "SET NAMES 'utf8'",
'time' => '0.000 sec',
'connection' => 'default',
'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',
'connection' => 'default',
'memory' => '2.4 MB',
),
array(
'sql' => "INSERT INTO `table` (`some_array`) VALUES ('| 1 | 2 | 3 |')",
'time' => '0.012 sec',
'connection' => 'default',
'memory' => '2.4 MB',
),
), $c->getQueries());
$this->assertEquals(3, $c->getQueryCount());
$this->assertEquals(0.024, $c->getTime());
}
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);
}
}