1111
1212namespace Symfony \Tests \Bridge \Doctrine \DataCollector ;
1313
14+ use Doctrine \DBAL \Platforms \MySqlPlatform ;
1415use Symfony \Bridge \Doctrine \DataCollector \DoctrineDataCollector ;
1516use Symfony \Component \HttpFoundation \Request ;
1617use Symfony \Component \HttpFoundation \Response ;
@@ -70,49 +71,58 @@ public function testCollectTime()
7071 /**
7172 * @dataProvider paramProvider
7273 */
73- public function testCollectQueries ($ param , $ expected )
74+ public function testCollectQueries ($ param , $ types , $ expected, $ explainable )
7475 {
7576 $ queries = array (
76- array ('sql ' => "SELECT * FROM table1 WHERE field1 = ?1 " , 'params ' => array ($ param ), 'types ' => array () , 'executionMS ' => 1 )
77+ array ('sql ' => "SELECT * FROM table1 WHERE field1 = ?1 " , 'params ' => array ($ param ), 'types ' => $ types , 'executionMS ' => 1 )
7778 );
7879 $ c = $ this ->createCollector ($ queries );
7980 $ c ->collect (new Request (), new Response ());
8081
8182 $ collected_queries = $ c ->getQueries ();
8283 $ this ->assertEquals ($ expected , $ collected_queries ['default ' ][0 ]['params ' ][0 ]);
84+ $ this ->assertEquals ($ explainable , $ collected_queries ['default ' ][0 ]['explainable ' ]);
8385 }
8486
8587 /**
8688 * @dataProvider paramProvider
8789 */
88- public function testSerialization ($ param , $ expected )
90+ public function testSerialization ($ param , $ types , $ expected, $ explainable )
8991 {
9092 $ queries = array (
91- array ('sql ' => "SELECT * FROM table1 WHERE field1 = ?1 " , 'params ' => array ($ param ), 'types ' => array () , 'executionMS ' => 1 )
93+ array ('sql ' => "SELECT * FROM table1 WHERE field1 = ?1 " , 'params ' => array ($ param ), 'types ' => $ types , 'executionMS ' => 1 )
9294 );
9395 $ c = $ this ->createCollector ($ queries );
9496 $ c ->collect (new Request (), new Response ());
9597 $ c = unserialize (serialize ($ c ));
9698
9799 $ collected_queries = $ c ->getQueries ();
98100 $ this ->assertEquals ($ expected , $ collected_queries ['default ' ][0 ]['params ' ][0 ]);
101+ $ this ->assertEquals ($ explainable , $ collected_queries ['default ' ][0 ]['explainable ' ]);
99102 }
100103
101104 public function paramProvider ()
102105 {
103106 return array (
104- array ('some value ' , 'some value ' ),
105- array (1 , ' 1 ' ),
106- array (true , ' true ' ),
107- array (null , ' null ' ),
108- array (new \stdClass ( ), ' Object(stdClass) ' ),
109- array (fopen (__FILE__ , 'r ' ), 'Resource(stream) ' ),
110- array (new \SplFileInfo (__FILE__ ), 'Object(SplFileInfo) ' ),
107+ array ('some value ' , array (), 'some value ' , true ),
108+ array (1 , array (), 1 , true ),
109+ array (true , array (), true , true ),
110+ array (null , array (), null , true ),
111+ array (new \DateTime ( ' 2011-09-11 ' ), array ( ' date ' ), ' 2011-09-11 ' , true ),
112+ array (fopen (__FILE__ , 'r ' ), array (), 'Resource(stream) ' , false ),
113+ array (new \SplFileInfo (__FILE__ ), array (), 'Object(SplFileInfo) ' , false ),
111114 );
112115 }
113116
114117 private function createCollector ($ queries )
115118 {
119+ $ connection = $ this ->getMockBuilder ('Doctrine\DBAL\Connection ' )
120+ ->disableOriginalConstructor ()
121+ ->getMock ();
122+ $ connection ->expects ($ this ->any ())
123+ ->method ('getDatabasePlatform ' )
124+ ->will ($ this ->returnValue (new MySqlPlatform ()));
125+
116126 $ registry = $ this ->getMock ('Doctrine\Common\Persistence\ManagerRegistry ' );
117127 $ registry
118128 ->expects ($ this ->any ())
@@ -122,6 +132,9 @@ private function createCollector($queries)
122132 ->expects ($ this ->any ())
123133 ->method ('getManagerNames ' )
124134 ->will ($ this ->returnValue (array ('default ' => 'doctrine.orm.default_entity_manager ' )));
135+ $ registry ->expects ($ this ->any ())
136+ ->method ('getConnection ' )
137+ ->will ($ this ->returnValue ($ connection ));
125138
126139 $ logger = $ this ->getMock ('Doctrine\DBAL\Logging\DebugStack ' );
127140 $ logger ->queries = $ queries ;
0 commit comments