Skip to content

Commit 9f88ac7

Browse files
Merge branch '6.2' into 6.3
* 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()
2 parents 5519cc7 + 30ab404 commit 9f88ac7

File tree

4 files changed

+259
-0
lines changed

4 files changed

+259
-0
lines changed

Tests/Caster/DoctrineCasterTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarDumper\Tests\Caster;
13+
14+
use Doctrine\Common\Collections\ArrayCollection;
15+
use Doctrine\ORM\EntityManagerInterface;
16+
use Doctrine\ORM\Mapping\ClassMetadata;
17+
use Doctrine\ORM\PersistentCollection;
18+
use PHPUnit\Framework\TestCase;
19+
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
20+
21+
/**
22+
* @requires function \Doctrine\Common\Collections\ArrayCollection::__construct
23+
*/
24+
class DoctrineCasterTest extends TestCase
25+
{
26+
use VarDumperTestTrait;
27+
28+
public function testCastPersistentCollection()
29+
{
30+
$classMetadata = new ClassMetadata(__CLASS__);
31+
32+
$collection = new PersistentCollection($this->createMock(EntityManagerInterface::class), $classMetadata, new ArrayCollection(['test']));
33+
34+
$expected = <<<EODUMP
35+
Doctrine\ORM\PersistentCollection {
36+
%A
37+
-em: Mock_EntityManagerInterface_%s { …3}
38+
-backRefFieldName: null
39+
-typeClass: Doctrine\ORM\Mapping\ClassMetadata { …}
40+
%A
41+
EODUMP;
42+
43+
$this->assertDumpMatchesFormat($expected, $collection);
44+
}
45+
}

Tests/Caster/ExceptionCasterTest.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\VarDumper\Tests\Caster;
1313

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

33+
private function getTestError($msg): \Error
34+
{
35+
return new \Error(''.$msg);
36+
}
37+
38+
private function getTestErrorException($msg): \ErrorException
39+
{
40+
return new \ErrorException(''.$msg);
41+
}
42+
43+
private function getTestSilencedErrorContext(): SilencedErrorContext
44+
{
45+
return new SilencedErrorContext(\E_ERROR, __FILE__, __LINE__);
46+
}
47+
3248
protected function tearDown(): void
3349
{
3450
ExceptionCaster::$srcContext = 1;
@@ -61,6 +77,79 @@ public function testDefaultSettings()
6177
$this->assertSame(['foo'], $ref);
6278
}
6379

80+
public function testDefaultSettingsOnError()
81+
{
82+
$e = $this->getTestError('foo');
83+
84+
$expectedDump = <<<'EODUMP'
85+
Error {
86+
#message: "foo"
87+
#code: 0
88+
#file: "%sExceptionCasterTest.php"
89+
#line: %d
90+
trace: {
91+
%s%eTests%eCaster%eExceptionCasterTest.php:%d {
92+
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestError($msg): Error
93+
› {
94+
› return new \Error(''.$msg);
95+
› }
96+
}
97+
%s%eTests%eCaster%eExceptionCasterTest.php:%d { …}
98+
%A
99+
EODUMP;
100+
101+
$this->assertDumpMatchesFormat($expectedDump, $e);
102+
}
103+
104+
public function testDefaultSettingsOnErrorException()
105+
{
106+
$e = $this->getTestErrorException('foo');
107+
108+
$expectedDump = <<<'EODUMP'
109+
ErrorException {
110+
#message: "foo"
111+
#code: 0
112+
#file: "%sExceptionCasterTest.php"
113+
#line: %d
114+
#severity: E_ERROR
115+
trace: {
116+
%s%eTests%eCaster%eExceptionCasterTest.php:%d {
117+
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestErrorException($msg): ErrorException
118+
› {
119+
› return new \ErrorException(''.$msg);
120+
› }
121+
}
122+
%s%eTests%eCaster%eExceptionCasterTest.php:%d { …}
123+
%A
124+
EODUMP;
125+
126+
$this->assertDumpMatchesFormat($expectedDump, $e);
127+
}
128+
129+
/**
130+
* @requires function \Symfony\Component\ErrorHandler\Exception\SilencedErrorContext::__construct
131+
*/
132+
public function testCastSilencedErrorContext()
133+
{
134+
$e = $this->getTestSilencedErrorContext();
135+
136+
$expectedDump = <<<'EODUMP'
137+
Symfony\Component\ErrorHandler\Exception\SilencedErrorContext {
138+
+count: 1
139+
-severity: E_ERROR
140+
trace: {
141+
%s%eTests%eCaster%eExceptionCasterTest.php:%d {
142+
› {
143+
› return new SilencedErrorContext(\E_ERROR, __FILE__, __LINE__);
144+
› }
145+
}
146+
}
147+
}
148+
EODUMP;
149+
150+
$this->assertDumpMatchesFormat($expectedDump, $e);
151+
}
152+
64153
public function testSeek()
65154
{
66155
$e = $this->getTestException(2);

Tests/Caster/FiberCasterTest.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarDumper\Tests\Caster;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
16+
17+
class FiberCasterTest extends TestCase
18+
{
19+
use VarDumperTestTrait;
20+
21+
public function testCastFiberNotStarted()
22+
{
23+
$fiber = new \Fiber(static fn() => true);
24+
25+
$expected = <<<EODUMP
26+
Fiber {
27+
status: "not started"
28+
}
29+
EODUMP;
30+
31+
$this->assertDumpEquals($expected, $fiber);
32+
}
33+
34+
public function testCastFiberTerminated()
35+
{
36+
$fiber = new \Fiber(static fn () => true);
37+
$fiber->start();
38+
39+
$expected = <<<EODUMP
40+
Fiber {
41+
status: "terminated"
42+
}
43+
EODUMP;
44+
45+
$this->assertDumpEquals($expected, $fiber);
46+
}
47+
48+
public function testCastFiberSuspended()
49+
{
50+
$fiber = new \Fiber(\Fiber::suspend(...));
51+
$fiber->start();
52+
53+
$expected = <<<EODUMP
54+
Fiber {
55+
status: "suspended"
56+
}
57+
EODUMP;
58+
59+
$this->assertDumpEquals($expected, $fiber);
60+
}
61+
62+
public function testCastFiberRunning()
63+
{
64+
$fiber = new \Fiber(function () {
65+
$expected = <<<EODUMP
66+
Fiber {
67+
status: "running"
68+
}
69+
EODUMP;
70+
71+
$this->assertDumpEquals($expected, \Fiber::getCurrent());
72+
});
73+
74+
$fiber->start();
75+
}
76+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Dumper\ContextProvider;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpFoundation\RequestStack;
17+
use Symfony\Component\VarDumper\Cloner\Data;
18+
use Symfony\Component\VarDumper\Dumper\ContextProvider\RequestContextProvider;
19+
20+
/**
21+
* @requires function \Symfony\Component\HttpFoundation\RequestStack::__construct
22+
*/
23+
class RequestContextProviderTest extends TestCase
24+
{
25+
public function testGetContextOnNullRequest()
26+
{
27+
$requestStack = new RequestStack();
28+
$provider = new RequestContextProvider($requestStack);
29+
30+
$this->assertNull($provider->getContext());
31+
}
32+
33+
public function testGetContextOnRequest()
34+
{
35+
$request = Request::create('https://example.org/', 'POST');
36+
$request->attributes->set('_controller', 'MyControllerClass');
37+
38+
$requestStack = new RequestStack();
39+
$requestStack->push($request);
40+
41+
$context = (new RequestContextProvider($requestStack))->getContext();
42+
$this->assertSame('https://example.org/', $context['uri']);
43+
$this->assertSame('POST', $context['method']);
44+
$this->assertInstanceOf(Data::class, $context['controller']);
45+
$this->assertSame('MyControllerClass', $context['controller']->getValue());
46+
$this->assertSame('https://example.org/', $context['uri']);
47+
$this->assertArrayHasKey('identifier', $context);
48+
}
49+
}

0 commit comments

Comments
 (0)