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 May 10, 2021
1 parent d44afd6 commit 9585ab3
Show file tree
Hide file tree
Showing 4 changed files with 60 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 $objectKey => $objectValue) {
$describer->addPropertyTo($value, (string) $objectKey, $objectValue, Value::PROP_PRIVATE);
}
}


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

/**
* Test: Tracy\Dumper::toText() specials
*/

declare(strict_types=1);

use Tester\Assert;
use Tracy\Dumper;

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


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


// ext-ds map
$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 9585ab3

Please sign in to comment.