Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: symfony/var-dumper
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.4.21
Choose a base ref
...
head repository: symfony/var-dumper
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.4.22
Choose a head ref
  • 3 commits
  • 6 files changed
  • 3 contributors

Commits on Mar 6, 2023

  1. Copy the full SHA
    2901ca1 View commit details

Commits on Mar 13, 2023

  1. Copy the full SHA
    15715d4 View commit details

Commits on Mar 25, 2023

  1. Copy the full SHA
    e2edac9 View commit details
6 changes: 5 additions & 1 deletion Dumper/CliDumper.php
Original file line number Diff line number Diff line change
@@ -198,6 +198,9 @@ public function dumpString(Cursor $cursor, string $str, bool $bin, int $cut)
}
if ('' === $str) {
$this->line .= '""';
if ($cut) {
$this->line .= ''.$cut;
}
$this->endValue($cursor);
} else {
$attr += [
@@ -445,7 +448,8 @@ protected function style(string $style, string $value, array $attr = [])

if (null === $this->handlesHrefGracefully) {
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR')
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100);
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100)
&& !isset($_SERVER['IDEA_INITIAL_DIRECTORY']);
}

if (isset($attr['ellipsis'], $attr['ellipsis-type'])) {
45 changes: 45 additions & 0 deletions Tests/Caster/DoctrineCasterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\VarDumper\Tests\Caster;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\PersistentCollection;
use PHPUnit\Framework\TestCase;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;

/**
* @requires function \Doctrine\Common\Collections\ArrayCollection::__construct
*/
class DoctrineCasterTest extends TestCase
{
use VarDumperTestTrait;

public function testCastPersistentCollection()
{
$classMetadata = new ClassMetadata(__CLASS__);

$collection = new PersistentCollection($this->createMock(EntityManagerInterface::class), $classMetadata, new ArrayCollection(['test']));

$expected = <<<EODUMP
Doctrine\ORM\PersistentCollection {
%A
-em: Mock_EntityManagerInterface_%s { …3}
-backRefFieldName: null
-typeClass: Doctrine\ORM\Mapping\ClassMetadata { …}
%A
EODUMP;

$this->assertDumpMatchesFormat($expected, $collection);
}
}
89 changes: 89 additions & 0 deletions Tests/Caster/ExceptionCasterTest.php
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
namespace Symfony\Component\VarDumper\Tests\Caster;

use PHPUnit\Framework\TestCase;
use Symfony\Component\ErrorHandler\Exception\SilencedErrorContext;
use Symfony\Component\VarDumper\Caster\Caster;
use Symfony\Component\VarDumper\Caster\ExceptionCaster;
use Symfony\Component\VarDumper\Caster\FrameStub;
@@ -29,6 +30,21 @@ private function getTestException($msg, &$ref = null)
return new \Exception(''.$msg);
}

private function getTestError($msg): \Error
{
return new \Error(''.$msg);
}

private function getTestErrorException($msg): \ErrorException
{
return new \ErrorException(''.$msg);
}

private function getTestSilencedErrorContext(): SilencedErrorContext
{
return new SilencedErrorContext(\E_ERROR, __FILE__, __LINE__);
}

protected function tearDown(): void
{
ExceptionCaster::$srcContext = 1;
@@ -61,6 +77,79 @@ public function testDefaultSettings()
$this->assertSame(['foo'], $ref);
}

public function testDefaultSettingsOnError()
{
$e = $this->getTestError('foo');

$expectedDump = <<<'EODUMP'
Error {
#message: "foo"
#code: 0
#file: "%sExceptionCasterTest.php"
#line: %d
trace: {
%s%eTests%eCaster%eExceptionCasterTest.php:%d {
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestError($msg): Error
› {
› return new \Error(''.$msg);
› }
}
%s%eTests%eCaster%eExceptionCasterTest.php:%d { …}
%A
EODUMP;

$this->assertDumpMatchesFormat($expectedDump, $e);
}

public function testDefaultSettingsOnErrorException()
{
$e = $this->getTestErrorException('foo');

$expectedDump = <<<'EODUMP'
ErrorException {
#message: "foo"
#code: 0
#file: "%sExceptionCasterTest.php"
#line: %d
#severity: E_ERROR
trace: {
%s%eTests%eCaster%eExceptionCasterTest.php:%d {
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestErrorException($msg): ErrorException
› {
› return new \ErrorException(''.$msg);
› }
}
%s%eTests%eCaster%eExceptionCasterTest.php:%d { …}
%A
EODUMP;

$this->assertDumpMatchesFormat($expectedDump, $e);
}

/**
* @requires function \Symfony\Component\ErrorHandler\Exception\SilencedErrorContext::__construct
*/
public function testCastSilencedErrorContext()
{
$e = $this->getTestSilencedErrorContext();

$expectedDump = <<<'EODUMP'
Symfony\Component\ErrorHandler\Exception\SilencedErrorContext {
+count: 1
-severity: E_ERROR
trace: {
%s%eTests%eCaster%eExceptionCasterTest.php:%d {
› {
› return new SilencedErrorContext(\E_ERROR, __FILE__, __LINE__);
› }
}
}
}
EODUMP;

$this->assertDumpMatchesFormat($expectedDump, $e);
}

public function testSeek()
{
$e = $this->getTestException(2);
85 changes: 85 additions & 0 deletions Tests/Caster/FiberCasterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\VarDumper\Tests\Caster;

use PHPUnit\Framework\TestCase;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;

/**
* @requires PHP 8.1
*/
class FiberCasterTest extends TestCase
{
use VarDumperTestTrait;

public function testCastFiberNotStarted()
{
$fiber = new \Fiber(static function () {
return true;
});

$expected = <<<EODUMP
Fiber {
status: "not started"
}
EODUMP;

$this->assertDumpEquals($expected, $fiber);
}

public function testCastFiberTerminated()
{
$fiber = new \Fiber(static function () {
return true;
});
$fiber->start();

$expected = <<<EODUMP
Fiber {
status: "terminated"
}
EODUMP;

$this->assertDumpEquals($expected, $fiber);
}

public function testCastFiberSuspended()
{
$fiber = new \Fiber(static function () {
\Fiber::suspend();
});
$fiber->start();

$expected = <<<EODUMP
Fiber {
status: "suspended"
}
EODUMP;

$this->assertDumpEquals($expected, $fiber);
}

public function testCastFiberRunning()
{
$fiber = new \Fiber(function () {
$expected = <<<EODUMP
Fiber {
status: "running"
}
EODUMP;

$this->assertDumpEquals($expected, \Fiber::getCurrent());
});

$fiber->start();
}
}
8 changes: 7 additions & 1 deletion Tests/Dumper/CliDumperTest.php
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
namespace Symfony\Component\VarDumper\Tests\Dumper;

use PHPUnit\Framework\TestCase;
use Symfony\Component\VarDumper\Caster\CutStub;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
use Symfony\Component\VarDumper\Dumper\CliDumper;
@@ -37,6 +38,11 @@ public function testGet()
':stream' => function ($res, $a) {
unset($a['uri'], $a['wrapper_data']);

return $a;
},
'Symfony\Component\VarDumper\Tests\Fixture\DumbFoo' => function ($foo, $a) {
$a['foo'] = new CutStub($a['foo']);

return $a;
},
]);
@@ -76,7 +82,7 @@ public function testGet()
%A options: []
}
"obj" => Symfony\Component\VarDumper\Tests\Fixture\DumbFoo {#%d
+foo: "foo"
+foo: ""…3
+"bar": "bar"
}
"closure" => Closure(\$a, PDO &\$b = null) {#%d
49 changes: 49 additions & 0 deletions Tests/Dumper/ContextProvider/RequestContextProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Dumper\ContextProvider;

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Dumper\ContextProvider\RequestContextProvider;

/**
* @requires function \Symfony\Component\HttpFoundation\RequestStack::__construct
*/
class RequestContextProviderTest extends TestCase
{
public function testGetContextOnNullRequest()
{
$requestStack = new RequestStack();
$provider = new RequestContextProvider($requestStack);

$this->assertNull($provider->getContext());
}

public function testGetContextOnRequest()
{
$request = Request::create('https://example.org/', 'POST');
$request->attributes->set('_controller', 'MyControllerClass');

$requestStack = new RequestStack();
$requestStack->push($request);

$context = (new RequestContextProvider($requestStack))->getContext();
$this->assertSame('https://example.org/', $context['uri']);
$this->assertSame('POST', $context['method']);
$this->assertInstanceOf(Data::class, $context['controller']);
$this->assertSame('MyControllerClass', $context['controller']->getValue());
$this->assertSame('https://example.org/', $context['uri']);
$this->assertArrayHasKey('identifier', $context);
}
}