Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Types/Attribute/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public function add(array $attributes, string $source, int $precedence = 1): voi
}

$this->cache = null;

$this->attributes[$precedence] = array_replace_recursive($this->attributes[$precedence], $attributes);

$this->attributeMetadata = array_merge_recursive(
$this->attributeMetadata,
array_fill_keys(
Expand All @@ -41,6 +43,13 @@ public function add(array $attributes, string $source, int $precedence = 1): voi
array_walk(
$this->attributeMetadata,
function (&$value) {
array_walk(
$value['source'],
function (&$source) {
// de-dupe when attribute defined twice in same file with attribute('...') and yaml
$source = is_array($source) ? $source[0] : $source;
}
);
ksort($value['source']);
}
);
Expand Down
14 changes: 14 additions & 0 deletions tests/Test/Types/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,18 @@ public function attributeMetadataSourcesAreCorrectAndOrdered()
$this->assertEquals('attrData2 array', array_pop($sources));
$this->assertEquals('attrData1 array', array_pop($sources));
}

/** @test */
public function duplicateAttributeDefinitionDoesNotCauseErrorInConfigDump()
{
$this->createWorkspaceYml(<<<'EOD'
attribute('message'): Hello World

attributes:
message: Olleh Dlrow
EOD
);

$this->assertFalse(strpos($this->workspaceCommand('config dump --key=message')->getOutput(), 'World'));
}
}