| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- <?php
- namespace Test\Michel\Debug;
- use Michel\Debug\Util\DataDescriptor;
- use Michel\UniTester\TestCase;
- class StructuredDataDescriptorTest extends TestCase
- {
- protected function setUp(): void
- {
- // TODO: Implement setUp() method.
- }
- protected function tearDown(): void
- {
- // TODO: Implement tearDown() method.
- }
- protected function execute(): void
- {
- $result = DataDescriptor::describe([
- 'name' => 'John Doe',
- 'email' => 'john.doe@example.com',
- 'active' => true,
- 'roles' => ['admin', 'user'],
- 'age' => 30
- ]);
- $this->assertEquals($result, array(
- 'type' => 'array',
- 'depth' => 0,
- 'truncated' => false,
- 'count' => 5,
- 'value' => 'array(5)',
- 'items' =>
- array(
- 'name' =>
- array(
- 'type' => 'string',
- 'depth' => 1,
- 'truncated' => false,
- 'length' => 8,
- 'value' => '"John Doe"',
- ),
- 'email' =>
- array(
- 'type' => 'string',
- 'depth' => 1,
- 'truncated' => false,
- 'length' => 20,
- 'value' => '"john.doe@example.com"',
- ),
- 'active' =>
- array(
- 'type' => 'boolean',
- 'depth' => 1,
- 'truncated' => false,
- 'value' => 'true',
- ),
- 'roles' =>
- array(
- 'type' => 'array',
- 'depth' => 1,
- 'truncated' => false,
- 'count' => 2,
- 'value' => 'array(2)',
- 'items' =>
- array(
- 0 =>
- array(
- 'type' => 'string',
- 'depth' => 2,
- 'truncated' => false,
- 'length' => 5,
- 'value' => '"admin"',
- ),
- 1 =>
- array(
- 'type' => 'string',
- 'depth' => 2,
- 'truncated' => false,
- 'length' => 4,
- 'value' => '"user"',
- ),
- ),
- ),
- 'age' =>
- array(
- 'type' => 'int',
- 'depth' => 1,
- 'truncated' => false,
- 'value' => 30,
- ),
- ),
- ));
- $result = DataDescriptor::describe([
- 'string' => 'Hello world',
- 'int' => 42,
- 'float' => 3.14,
- 'boolTrue' => true,
- 'boolFalse' => false,
- 'nullValue' => null,
- 'arraySimple' => [1, 2, 3],
- 'arrayNested' => [
- 'level1' => [
- 'level2' => [
- 'level3a' => 'deep',
- 'level3b' => [4, 5, 6]
- ],
- 'level2b' => 'mid'
- ],
- 'anotherKey' => 'value'
- ],
- 'objectSimple' => (object)['foo' => 'bar', 'baz' => 123],
- ]);
- $this->assertEquals($result, array(
- 'type' => 'array',
- 'depth' => 0,
- 'truncated' => false,
- 'count' => 9,
- 'value' => 'array(9)',
- 'items' =>
- array(
- 'string' =>
- array(
- 'type' => 'string',
- 'depth' => 1,
- 'truncated' => false,
- 'length' => 11,
- 'value' => '"Hello world"',
- ),
- 'int' =>
- array(
- 'type' => 'int',
- 'depth' => 1,
- 'truncated' => false,
- 'value' => 42,
- ),
- 'float' =>
- array(
- 'type' => 'float',
- 'depth' => 1,
- 'truncated' => false,
- 'value' => 3.14,
- ),
- 'boolTrue' =>
- array(
- 'type' => 'boolean',
- 'depth' => 1,
- 'truncated' => false,
- 'value' => 'true',
- ),
- 'boolFalse' =>
- array(
- 'type' => 'boolean',
- 'depth' => 1,
- 'truncated' => false,
- 'value' => 'false',
- ),
- 'nullValue' =>
- array(
- 'type' => 'NULL',
- 'depth' => 1,
- 'truncated' => false,
- 'value' => 'null',
- ),
- 'arraySimple' =>
- array(
- 'type' => 'array',
- 'depth' => 1,
- 'truncated' => false,
- 'count' => 3,
- 'value' => 'array(3)',
- 'items' =>
- array(
- 0 =>
- array(
- 'type' => 'int',
- 'depth' => 2,
- 'truncated' => false,
- 'value' => 1,
- ),
- 1 =>
- array(
- 'type' => 'int',
- 'depth' => 2,
- 'truncated' => false,
- 'value' => 2,
- ),
- 2 =>
- array(
- 'type' => 'int',
- 'depth' => 2,
- 'truncated' => false,
- 'value' => 3,
- ),
- ),
- ),
- 'arrayNested' =>
- array(
- 'type' => 'array',
- 'depth' => 1,
- 'truncated' => false,
- 'count' => 2,
- 'value' => 'array(2)',
- 'items' =>
- array(
- 'level1' =>
- array(
- 'type' => 'array',
- 'depth' => 2,
- 'truncated' => false,
- 'count' => 2,
- 'value' => 'array(2)',
- 'items' =>
- array(
- 'level2' =>
- array(
- 'type' => 'array',
- 'depth' => 3,
- 'truncated' => false,
- 'count' => 2,
- 'value' => 'array(2)',
- 'items' =>
- array(
- 'level3a' =>
- array(
- 'type' => 'string',
- 'depth' => 4,
- 'truncated' => false,
- 'length' => 4,
- 'value' => '"deep"',
- ),
- 'level3b' =>
- array(
- 'type' => 'array',
- 'depth' => 4,
- 'truncated' => false,
- 'count' => 3,
- 'value' => 'array(3)',
- 'items' =>
- array(
- 0 =>
- array(
- 'type' => 'integer',
- 'depth' => 5,
- 'truncated' => true,
- 'value' => '…',
- ),
- 1 =>
- array(
- 'type' => 'integer',
- 'depth' => 5,
- 'truncated' => true,
- 'value' => '…',
- ),
- 2 =>
- array(
- 'type' => 'integer',
- 'depth' => 5,
- 'truncated' => true,
- 'value' => '…',
- ),
- ),
- ),
- ),
- ),
- 'level2b' =>
- array(
- 'type' => 'string',
- 'depth' => 3,
- 'truncated' => false,
- 'length' => 3,
- 'value' => '"mid"',
- ),
- ),
- ),
- 'anotherKey' =>
- array(
- 'type' => 'string',
- 'depth' => 2,
- 'truncated' => false,
- 'length' => 5,
- 'value' => '"value"',
- ),
- ),
- ),
- 'objectSimple' =>
- array(
- 'type' => 'object',
- 'depth' => 1,
- 'truncated' => false,
- 'class' => 'stdClass',
- 'object_id' => 13,
- 'value' => 'stdClass#13',
- 'properties' =>
- array(
- 'foo' =>
- array(
- 'type' => 'string',
- 'depth' => 2,
- 'truncated' => false,
- 'length' => 3,
- 'value' => '"bar"',
- ),
- 'baz' =>
- array(
- 'type' => 'int',
- 'depth' => 2,
- 'truncated' => false,
- 'value' => 123,
- ),
- ),
- ),
- ),
- ));
- }
- }
|