PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/symfony/http-kernel/Tests/DataCollector/DumpDataCollectorTest.php

https://bitbucket.org/ondemosite/sompo.motor
PHP | 138 lines | 102 code | 25 blank | 11 comment | 2 complexity | 7c7fa7ccc070497a3481acaeec955404 MD5 | raw file
Possible License(s): LGPL-2.0, MIT, LGPL-3.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0, GPL-3.0, BSD-3-Clause
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests\DataCollector;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
  15. use Symfony\Component\VarDumper\Cloner\Data;
  16. use Symfony\Component\VarDumper\Dumper\CliDumper;
  17. /**
  18. * @author Nicolas Grekas <p@tchwork.com>
  19. */
  20. class DumpDataCollectorTest extends TestCase
  21. {
  22. public function testDump()
  23. {
  24. $data = new Data(array(array(123)));
  25. $collector = new DumpDataCollector();
  26. $this->assertSame('dump', $collector->getName());
  27. $collector->dump($data);
  28. $line = __LINE__ - 1;
  29. $this->assertSame(1, $collector->getDumpsCount());
  30. $dump = $collector->getDumps('html');
  31. $this->assertArrayHasKey('data', $dump[0]);
  32. $dump[0]['data'] = preg_replace('/^.*?<pre/', '<pre', $dump[0]['data']);
  33. $dump[0]['data'] = preg_replace('/sf-dump-\d+/', 'sf-dump', $dump[0]['data']);
  34. $xDump = array(
  35. array(
  36. 'data' => "<pre class=sf-dump id=sf-dump data-indent-pad=\" \"><span class=sf-dump-num>123</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n",
  37. 'name' => 'DumpDataCollectorTest.php',
  38. 'file' => __FILE__,
  39. 'line' => $line,
  40. 'fileExcerpt' => false,
  41. ),
  42. );
  43. $this->assertEquals($xDump, $dump);
  44. $this->assertStringMatchesFormat('a:3:{i:0;a:5:{s:4:"data";%c:39:"Symfony\Component\VarDumper\Cloner\Data":%a', $collector->serialize());
  45. $this->assertSame(0, $collector->getDumpsCount());
  46. $this->assertSame('a:2:{i:0;b:0;i:1;s:5:"UTF-8";}', $collector->serialize());
  47. }
  48. public function testCollectDefault()
  49. {
  50. $data = new Data(array(array(123)));
  51. $collector = new DumpDataCollector();
  52. $collector->dump($data);
  53. $line = __LINE__ - 1;
  54. ob_start();
  55. $collector->collect(new Request(), new Response());
  56. $output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
  57. $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output);
  58. $this->assertSame(1, $collector->getDumpsCount());
  59. $collector->serialize();
  60. }
  61. public function testCollectHtml()
  62. {
  63. $data = new Data(array(array(123)));
  64. $collector = new DumpDataCollector(null, 'test://%f:%l');
  65. $collector->dump($data);
  66. $line = __LINE__ - 1;
  67. $file = __FILE__;
  68. $xOutput = <<<EOTXT
  69. <pre class=sf-dump id=sf-dump data-indent-pad=" "><a href="test://{$file}:{$line}" title="{$file}"><span class=sf-dump-meta>DumpDataCollectorTest.php</span></a> on line <span class=sf-dump-meta>{$line}</span>:
  70. <span class=sf-dump-num>123</span>
  71. </pre>
  72. EOTXT;
  73. ob_start();
  74. $response = new Response();
  75. $response->headers->set('Content-Type', 'text/html');
  76. $collector->collect(new Request(), $response);
  77. $output = ob_get_clean();
  78. $output = preg_replace('#<(script|style).*?</\1>#s', '', $output);
  79. $output = preg_replace('/sf-dump-\d+/', 'sf-dump', $output);
  80. $this->assertSame($xOutput, trim($output));
  81. $this->assertSame(1, $collector->getDumpsCount());
  82. $collector->serialize();
  83. }
  84. public function testFlush()
  85. {
  86. $data = new Data(array(array(456)));
  87. $collector = new DumpDataCollector();
  88. $collector->dump($data);
  89. $line = __LINE__ - 1;
  90. ob_start();
  91. $collector->__destruct();
  92. $output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
  93. $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
  94. }
  95. public function testFlushNothingWhenDataDumperIsProvided()
  96. {
  97. $data = new Data(array(array(456)));
  98. $dumper = new CliDumper('php://output');
  99. $collector = new DumpDataCollector(null, null, null, null, $dumper);
  100. ob_start();
  101. $collector->dump($data);
  102. $line = __LINE__ - 1;
  103. $output = preg_replace("/\033\[[^m]*m/", '', ob_get_clean());
  104. if (\PHP_VERSION_ID >= 50400) {
  105. $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", $output);
  106. } else {
  107. $this->assertSame("\"DumpDataCollectorTest.php on line {$line}:\"\n456\n", $output);
  108. }
  109. ob_start();
  110. $collector->__destruct();
  111. $this->assertEmpty(ob_get_clean());
  112. }
  113. }