No Description

DataCollectorTest.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpKernel\Tests\Fixtures\DataCollector\CloneVarDataCollector;
  14. use Symfony\Component\VarDumper\Cloner\Stub;
  15. use Symfony\Component\VarDumper\Cloner\VarCloner;
  16. use Symfony\Component\VarDumper\Dumper\CliDumper;
  17. class DataCollectorTest extends \PHPUnit_Framework_TestCase
  18. {
  19. public function testCloneVarStringWithScheme()
  20. {
  21. $c = new CloneVarDataCollector('scheme://foo');
  22. $c->collect(new Request(), new Response());
  23. $cloner = new VarCloner();
  24. $this->assertEquals($cloner->cloneVar('scheme://foo'), $c->getData());
  25. }
  26. public function testCloneVarExistingFilePath()
  27. {
  28. $c = new CloneVarDataCollector($filePath = tempnam(sys_get_temp_dir(), 'clone_var_data_collector_'));
  29. $c->collect(new Request(), new Response());
  30. $data = $c->getData();
  31. $this->assertInstanceOf(Stub::class, $data->getRawData()[0][0]);
  32. $this->assertDumpEquals("\"$filePath\"", $data);
  33. }
  34. private function assertDumpEquals($dump, $data, $message = '')
  35. {
  36. $dumper = new CliDumper();
  37. $dumper->setColors(false);
  38. $this->assertSame(rtrim($dump), rtrim($dumper->dump($data, true)), $message);
  39. }
  40. }