Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #164 from hxss/develop
Browse files Browse the repository at this point in the history
recursively set indentations for child arrays
  • Loading branch information
Ocramius committed Oct 24, 2018
2 parents 3f2f541 + 646a77c commit 8003f74
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Generator/ValueGenerator.php
Expand Up @@ -361,6 +361,7 @@ public function generate()
}

$curValue = new self($curValue, $newType, self::OUTPUT_MULTIPLE_LINE, $this->getConstants());
$curValue->setIndentation($this->indentation);
}
}

Expand Down
95 changes: 95 additions & 0 deletions test/Generator/ValueGeneratorTest.php
Expand Up @@ -225,6 +225,85 @@ public function complexArray()
return $this->generateArrayData($longOutput, $value);
}

/**
* Data provider for testPropertyDefaultValueCanHandleComplexArrayWCustomIndentOfTypes test
*/
public function complexArrayWCustomIndent(): array
{
$value = [
'5bcf08a0a5d20' => [
'5bcf08a0a5d65' => [
'5bcf08a0a5d9f' => [
'5bcf08a0a5dd8' => [
'5bcf08a0a5e11' => [
'5bcf08a0a5e4f' => '5bcf08a0a5e8c',
'5bcf08a0a5eca' => '5bcf08a0a5f05',
'5bcf08a0a5f43' => '5bcf08a0a5f7f',
'5bcf08a0a5fbd' => '5bcf08a0a5ff8',
],
],
'5bcf08a0a603a' => [],
'5bcf08a0a6062' => '5bcf08a0a609f',
'5bcf08a0a60dc' => [
'5bcf08a0a611b' => '5bcf08a0a6158',
'5bcf08a0a6197' => [
'5bcf08a0a61d7' => '5bcf08a0a6212',
'5bcf08a0a6250' => '5bcf08a0a628c',
'5bcf08a0a62cb' => '5bcf08a0a6306',
],
'5bcf08a0a6345' => [
'5bcf08a0a637e' => '5bcf08a0a63b4',
'5bcf08a0a63ee' => '5bcf08a0a642a',
],
'5bcf08a0a6449' => '5bcf08a0a6485',
],
],
], '5bcf08a0a64c8' => '5bcf08a0a6540',
'5bcf08a0a657f' => '5bcf08a0a65bf',
],
];

$longOutput = <<<EOS
array(
'5bcf08a0a5d20' => array(
'5bcf08a0a5d65' => array(
'5bcf08a0a5d9f' => array(
'5bcf08a0a5dd8' => array(
'5bcf08a0a5e11' => array(
'5bcf08a0a5e4f' => '5bcf08a0a5e8c',
'5bcf08a0a5eca' => '5bcf08a0a5f05',
'5bcf08a0a5f43' => '5bcf08a0a5f7f',
'5bcf08a0a5fbd' => '5bcf08a0a5ff8',
),
),
'5bcf08a0a603a' => array(
),
'5bcf08a0a6062' => '5bcf08a0a609f',
'5bcf08a0a60dc' => array(
'5bcf08a0a611b' => '5bcf08a0a6158',
'5bcf08a0a6197' => array(
'5bcf08a0a61d7' => '5bcf08a0a6212',
'5bcf08a0a6250' => '5bcf08a0a628c',
'5bcf08a0a62cb' => '5bcf08a0a6306',
),
'5bcf08a0a6345' => array(
'5bcf08a0a637e' => '5bcf08a0a63b4',
'5bcf08a0a63ee' => '5bcf08a0a642a',
),
'5bcf08a0a6449' => '5bcf08a0a6485',
),
),
),
'5bcf08a0a64c8' => '5bcf08a0a6540',
'5bcf08a0a657f' => '5bcf08a0a65bf',
),
)
EOS;

return $this->generateArrayData($longOutput, $value);
}

/**
* Data provider for testPropertyDefaultValueCanHandleArrayWithUnsortedKeys test
*
Expand Down Expand Up @@ -338,6 +417,22 @@ public function testPropertyDefaultValueCanHandleComplexArrayOfTypes($type, arra
self::assertEquals($expected, $valueGenerator->generate());
}

/**
* @dataProvider complexArrayWCustomIndent
*/
public function testPropertyDefaultValueCanHandleComplexArrayWCustomIndentOfTypes(
string $type,
array $value,
string $expected
): void {
$valueGenerator = new ValueGenerator();
$valueGenerator->setType($type);
$valueGenerator->setValue($value);
$valueGenerator->setIndentation("\t");

self::assertEquals($expected, $valueGenerator->generate());
}

/**
* @group 6023
*
Expand Down

0 comments on commit 8003f74

Please sign in to comment.