Skip to content

Commit

Permalink
add-faker-integration: Adding and testing new FakerReplacer integration
Browse files Browse the repository at this point in the history
  • Loading branch information
franziskahahn committed Jan 20, 2017
1 parent 0cd2369 commit 078263c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Webfactory/Slimdump/Config/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ public function processRowValue($value) {
}

if ($this->dump == Config::REPLACE) {
/** @var \SimpleXMLElement $replacement */
$replacementName = (string)$this->config->attributes()->replacement;

if (FakerReplacer::isFakerColumn($replacementName)) {
$fakerReplacer = new FakerReplacer();
return $fakerReplacer->generateReplacement($replacementName);
}

return $this->config->attributes()->replacement;
}

Expand Down
25 changes: 25 additions & 0 deletions test/Webfactory/Slimdump/Config/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@ public function testProcessRowValueWithMaskedConfiguration()
$this->assertEquals('xxxx@xxxx.xxx', $columnConfig->processRowValue('test@fest.com'));
}

public function testProcessRowValueFakerReplacement()
{
$xml = '<?xml version="1.0" ?>
<column name="test" dump="replace" replacement="FAKER_NAME" />';
$xmlElement = new \SimpleXMLElement($xml);

$columnConfig = new Column($xmlElement);

$fakedName = $columnConfig->processRowValue('original user name');
$this->assertNotSame('original user name', $fakedName);
}

public function testProcessRowValueStandardReplacement()
{
$xml = '<?xml version="1.0" ?>
<column name="test" dump="replace" replacement="ANON" />';
$xmlElement = new \SimpleXMLElement($xml);

$columnConfig = new Column($xmlElement);

$replacedName = $columnConfig->processRowValue('original user name');
// note: default replacement returns \SimpleXMLElement - just checking content here using assertEquals
$this->assertEquals('ANON', $replacedName);
}

/**
* @expectedException \Webfactory\Slimdump\Exception\InvalidDumpTypeException
*/
Expand Down

0 comments on commit 078263c

Please sign in to comment.