Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 036e3a0

Browse filesBrowse files
[VarDumper] Add DbaCaster
1 parent 561edb6 commit 036e3a0
Copy full SHA for 036e3a0

File tree

4 files changed

+87
-10
lines changed
Filter options

4 files changed

+87
-10
lines changed
+33Lines 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 Alexandre Daubois <alex.daubois@gmail.com>
18+
*/
19+
class DbaCaster
20+
{
21+
public static function castDbaConnection(\Dba\Connection $dba, array $a, Stub $stub, bool $isNested): array
22+
{
23+
return $a;
24+
}
25+
26+
public static function castDbaResource($dba, array $a, Stub $stub, bool $isNested): array
27+
{
28+
$list = dba_list();
29+
$a['file'] = $list[(int) $dba];
30+
31+
return $a;
32+
}
33+
}

‎src/Symfony/Component/VarDumper/Caster/ResourceCaster.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/ResourceCaster.php
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222
*/
2323
class ResourceCaster
2424
{
25-
public static function castDba($dba, array $a, Stub $stub, bool $isNested): array
26-
{
27-
$list = dba_list();
28-
$a['file'] = $list[(int) $dba];
29-
30-
return $a;
31-
}
32-
3325
public static function castProcess($process, array $a, Stub $stub, bool $isNested): array
3426
{
3527
return proc_get_status($process);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ abstract class AbstractCloner implements ClonerInterface
179179
'CurlHandle' => ['Symfony\Component\VarDumper\Caster\CurlCaster', 'castCurl'],
180180
'CurlMultiHandle' => ['Symfony\Component\VarDumper\Caster\CurlCaster', 'castCurlMulti'],
181181

182-
':dba' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
183-
':dba persistent' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'],
182+
'Dba\Connection' => ['Symfony\Component\VarDumper\Caster\DbaCaster', 'castDbaConnection'],
183+
':dba' => ['Symfony\Component\VarDumper\Caster\DbaCaster', 'castDbaResource'],
184+
':dba persistent' => ['Symfony\Component\VarDumper\Caster\DbaCaster', 'castDbaResource'],
184185

185186
'GdImage' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'],
186187
':gd' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'],
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 Caster;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
16+
17+
/**
18+
* @requires extension dba
19+
*/
20+
class DbaCasterTest extends TestCase
21+
{
22+
use VarDumperTestTrait;
23+
24+
/**
25+
* @requires PHP 8.4
26+
*/
27+
public function testCastDba()
28+
{
29+
$dba = dba_open(sys_get_temp_dir().'/test.db', 'c');
30+
31+
$this->assertDumpMatchesFormat(
32+
<<<'EODUMP'
33+
Dba\Connection {}
34+
EODUMP, $dba);
35+
}
36+
37+
/**
38+
* @requires PHP < 8.4
39+
*/
40+
public function testCastDbaPriorToPhp84()
41+
{
42+
$dba = dba_open(sys_get_temp_dir().'/test.db', 'c');
43+
44+
$this->assertDumpMatchesFormat(
45+
<<<'EODUMP'
46+
dba resource {
47+
file: %s
48+
}
49+
EODUMP, $dba);
50+
}
51+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.