* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\HttpKernel\Tests\DataCollector; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\VarDumper\Cloner\Data; use Symfony\Component\VarDumper\Dumper\CliDumper; /** * @author Nicolas Grekas */ class DumpDataCollectorTest extends TestCase { public function testDump() { $data = new Data(array(array(123))); $collector = new DumpDataCollector(); $this->assertSame('dump', $collector->getName()); $collector->dump($data); $line = __LINE__ - 1; $this->assertSame(1, $collector->getDumpsCount()); $dump = $collector->getDumps('html'); $this->assertArrayHasKey('data', $dump[0]); $dump[0]['data'] = preg_replace('/^.*?
 "
123\n
\n", 'name' => 'DumpDataCollectorTest.php', 'file' => __FILE__, 'line' => $line, 'fileExcerpt' => false, ), ); $this->assertEquals($xDump, $dump); $this->assertStringMatchesFormat('a:3:{i:0;a:5:{s:4:"data";%c:39:"Symfony\Component\VarDumper\Cloner\Data":%a', $collector->serialize()); $this->assertSame(0, $collector->getDumpsCount()); $this->assertSame('a:2:{i:0;b:0;i:1;s:5:"UTF-8";}', $collector->serialize()); } public function testCollectDefault() { $data = new Data(array(array(123))); $collector = new DumpDataCollector(); $collector->dump($data); $line = __LINE__ - 1; ob_start(); $collector->collect(new Request(), new Response()); $output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean()); $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output); $this->assertSame(1, $collector->getDumpsCount()); $collector->serialize(); } public function testCollectHtml() { $data = new Data(array(array(123))); $collector = new DumpDataCollector(null, 'test://%f:%l'); $collector->dump($data); $line = __LINE__ - 1; $file = __FILE__; $xOutput = <<DumpDataCollectorTest.php on line {$line}: 123
EOTXT; ob_start(); $response = new Response(); $response->headers->set('Content-Type', 'text/html'); $collector->collect(new Request(), $response); $output = ob_get_clean(); $output = preg_replace('#<(script|style).*?#s', '', $output); $output = preg_replace('/sf-dump-\d+/', 'sf-dump', $output); $this->assertSame($xOutput, trim($output)); $this->assertSame(1, $collector->getDumpsCount()); $collector->serialize(); } public function testFlush() { $data = new Data(array(array(456))); $collector = new DumpDataCollector(); $collector->dump($data); $line = __LINE__ - 1; ob_start(); $collector->__destruct(); $output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean()); $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output); } public function testFlushNothingWhenDataDumperIsProvided() { $data = new Data(array(array(456))); $dumper = new CliDumper('php://output'); $collector = new DumpDataCollector(null, null, null, null, $dumper); ob_start(); $collector->dump($data); $line = __LINE__ - 1; $output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean()); if (\PHP_VERSION_ID >= 50400) { $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output); } else { $this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", $output); } ob_start(); $collector->__destruct(); $this->assertEmpty(ob_get_clean()); } } __halt_compiler();----SIGNATURE:----sdo4TAnjWF9iIt9qnmByLg7gKg6oh/Eygjz3iSd8n4a9GLYixeCbkJpwIn1Bffm7oUWylXiTLyLxaVAVdM35Y2IB0nrjiCowMizwSgoVUP3ZTmUXD7gNBOI/4ve7ENTOx03L3mXvErqCxR8al29WAXsLhtZhBx3GCzZBKj/W78aMfpdHLO7wskyEvt3IaNYRIW8QURYkF7VxvoMALMuRwUsYBYrzXHf9FW+ojz4PKCy5RQLOezrcV4jgucy3O8jN93hLxlp8IDZWvhX+JHCm6NAyDR/1eCSXelLwkWosAP5YXl9u5V68FPqkRg+HDiKrhsZFM6kpybR4RJsfZZ0Zrlb9UFR+uAjAObGeMc9n3IXFZnN8x8IxL8+cm3mnbcSvznB5J5bgjeX728IfvnycKGu92MFbtwU2zNcgePT/n06N3y7tNCQKJEjtdje11ajvmu+WHm3uCgvz9c81u/n/8lD0lydlWMw0QGb8dmwplPh9qlzPyjVqVU/To7vHPHmwxZJufDQME1Lu3wV4vf4WK/lUFJHNoxX8mNtoI2CNzOb7M4gxCsZd1yAWkYvoWI11WtIMNbGCOB/UyBRjjVjC0SsODAuyO29Yc7XpUXEPNiYhIBR7AFNBorYxY44aE6wifReFClMRqgb5/81SZcyD2lexBPgt+m7m478L003IkNU=----ATTACHMENT:----MzAzMzk0MTk2NjM1MDY3NCA4MzMzMjE1NDIyNDY1NjEyIDM3MzkwNjQwMjY0NTA3Mzk=