DataCollectorTest.php 1.6 KB

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