8000 bug #45496 [VarDumper] Fix dumping mysqli_driver instances (nicolas-g… · symfony/symfony@46408f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 46408f0

Browse files
bug #45496 [VarDumper] Fix dumping mysqli_driver instances (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [VarDumper] Fix dumping mysqli_driver instances | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #45487 | License | MIT | Doc PR | - See linked issue and https://www.php.net/manual/en/class.mysqli-driver.php Commits ------- 88cc3af [VarDumper] Fix dumping mysqli_driver instances
2 parents 7bc53c6 + 88cc3af commit 46408f0

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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\Caster;
13+
14+
use Symfony\Component\VarDumper\Cloner\Stub;
15+
16+
/**
17+
* @author Nicolas Grekas <p@tchwork.com>
18+
*
19+
* @internal
20+
*/
21+
final class MysqliCaster
22+
{
23+
public static function castMysqliDriver(\mysqli_driver $c, array $a, Stub $stub, bool $isNested): array
24+
{
25+
foreach ($a as $k => $v) {
26+
if (isset($c->$k)) {
27+
$a[$k] = $c->$k;
28+
}
29+
}
30+
31+
return $a;
32+
}
33+
}

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ abstract class AbstractCloner implements ClonerInterface
144144
'Ds\Pair' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castPair'],
145145
'Symfony\Component\VarDumper\Caster\DsPairStub' => ['Symfony\Component\VarDumper\Caster\DsCaster', 'castPairStub'],
146146

147+
'mysqli_driver' => ['Symfony\Component\VarDumper\Caster\MysqliCaster', 'castMysqliDriver'],
148+
147149
'CurlHandle' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'],
148150
':curl' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'],
149151

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
/**
18+
* @requires extension mysqli
19+
* @group integration
20+
*/
21+
class MysqliCasterTest extends TestCase
22+
{
23+
use VarDumperTestTrait;
24+
25+
public function testNotConnected()
26+
{
27+
$driver = new \mysqli_driver();
28+
$driver->report_mode = 3;
29+
30+
$xCast = <<<EODUMP
31+
mysqli_driver {%A
32+
+reconnect: false
33+
+report_mode: 3
34+
}
35+
EODUMP;
36+
37+
$this->assertDumpMatchesFormat($xCast, $driver);
38+
}
39+
}

0 commit comments

Comments
 (0)
0