Skip to content

Commit

Permalink
Merge branch '6.2' into 6.3
Browse files Browse the repository at this point in the history
* 6.2:
  [Translation] Decouple TranslatorPathsPass from "debug." convention
  [VarDumper] Add a bit of test coverage
  [TwigBridge] Fix flagged malicious url
  [HttpClient] Fix encoding "+" in URLs
  [DependencyInjection] Fix dumping array of enums parameters
  Bump Symfony version to 6.2.8
  Update VERSION for 6.2.7
  Update CHANGELOG for 6.2.7
  Bump Symfony version to 5.4.22
  Update VERSION for 5.4.21
  Update CONTRIBUTORS for 5.4.21
  Update CHANGELOG for 5.4.21
  [Messenger] Fix TransportNamesStamp deserialization
  Removed @internal tag on TraceableAuthenticator::getAuthenticator()
  • Loading branch information
nicolas-grekas committed Mar 6, 2023
2 parents 5519cc7 + 30ab404 commit 9f88ac7
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 0 deletions.
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
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
76 changes: 76 additions & 0 deletions Tests/Caster/FiberCasterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?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;

class FiberCasterTest extends TestCase
{
use VarDumperTestTrait;

public function testCastFiberNotStarted()
{
$fiber = new \Fiber(static fn() => true);

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

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

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

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

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

public function testCastFiberSuspended()
{
$fiber = new \Fiber(\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();
}
}
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);
}
}

0 comments on commit 9f88ac7

Please sign in to comment.