Skip to content

Commit

Permalink
Dumper: added ext-ds support (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
enumag authored and dg committed May 10, 2021
1 parent 86c6f9e commit 0a90e93
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ds
coverage: none

- run: composer install --no-progress --prefer-dist
Expand All @@ -41,6 +42,7 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
extensions: ds
coverage: none

- run: composer install --no-progress --prefer-dist
Expand Down
2 changes: 2 additions & 0 deletions src/Tracy/Dumper/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class Dumper
\DOMNode::class => [Exposer::class, 'exposeDOMNode'],
\DOMNodeList::class => [Exposer::class, 'exposeDOMNodeList'],
\DOMNamedNodeMap::class => [Exposer::class, 'exposeDOMNodeList'],
\Ds\Collection::class => [Exposer::class, 'exposeDsCollection'],
\Ds\Map::class => [Exposer::class, 'exposeDsMap'],
];

/** @var Describer */
Expand Down
23 changes: 23 additions & 0 deletions src/Tracy/Dumper/Exposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,27 @@ public static function exposePhpIncompleteClass(
}
$value->value = $class . ' (Incomplete Class)';
}


public static function exposeDsCollection(
\Ds\Collection $obj,
Value $value,
Describer $describer
): void {
foreach ($obj as $k => $v) {
$describer->addPropertyTo($value, (string) $k, $v, Value::PROP_VIRTUAL);
}
}


public static function exposeDsMap(
\Ds\Map $obj,
Value $value,
Describer $describer
): void {
$i = 0;
foreach ($obj as $k => $v) {
$describer->addPropertyTo($value, (string) $i++, new \Ds\Pair($k, $v), Value::PROP_VIRTUAL);
}
}
}
32 changes: 32 additions & 0 deletions tests/Tracy/Dumper.toText().specials.ds.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* Test: Tracy\Dumper::toText() specials
* @phpExtension ds
*/

declare(strict_types=1);

use Tester\Assert;
use Tracy\Dumper;

require __DIR__ . '/../bootstrap.php';


$collection = new Ds\Vector(['value']);
Assert::match(<<<'XX'
Ds\Vector #%d%
0: 'value'
XX
, Dumper::toText($collection));


$map = new Ds\Map;
$map->put('key', 'value');
Assert::match(<<<'XX'
Ds\Map #%d%
0: Ds\Pair #%d%
| key: 'key'
| value: 'value'
XX
, Dumper::toText($map));

0 comments on commit 0a90e93

Please sign in to comment.