1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: fs |
5
|
|
|
* Date: 16.03.2015 |
6
|
|
|
* Time: 18:33 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace IntegerNet\Anonymizer; |
10
|
|
|
|
11
|
|
|
use IntegerNet\Anonymizer\Mock\AnonymizableMock; |
12
|
|
|
|
13
|
|
|
class AnonymizerTest extends \PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @param AnonymizableMock[] $inputData |
17
|
|
|
* @param string[] $expectedValues |
18
|
|
|
* @dataProvider getAnonymizableData |
19
|
|
|
*/ |
20
|
|
|
public function testAnonymizer(array $inputData, $expectedValues) |
21
|
|
|
{ |
22
|
|
|
$provider = $this->getMock(Provider::__CLASS); |
23
|
|
|
$provider->expects($this->once())->method('initialize'); |
24
|
|
|
$provider->expects($this->exactly(count($expectedValues)))->method('getFakerData') |
25
|
|
|
->willReturnCallback(function($formatter, $identifier) { |
26
|
|
|
return sprintf('%s_%s', $formatter, explode('|', $identifier, 2)[0]); |
27
|
|
|
}); |
28
|
|
|
|
29
|
|
|
$anonymizer = new Anonymizer($provider, 'de_DE'); |
30
|
|
|
$anonymizer->anonymize($inputData); |
31
|
|
|
|
32
|
|
|
reset($expectedValues); |
33
|
|
|
/** @var AnonymizableMock $anonymizedEntity */ |
34
|
|
|
foreach ($inputData as $anonymizedEntity) { |
35
|
|
|
foreach ($anonymizedEntity->getValues() as $anonymizedValue) { |
36
|
|
|
$this->assertEquals(current($expectedValues), $anonymizedValue->getValue()); |
37
|
|
|
next($expectedValues); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Provider::getFakerData() should be called with |
44
|
|
|
* - identifier as combination of entity identifier and current value |
45
|
|
|
* - unique key parameter for values marked as unique |
46
|
|
|
* |
47
|
|
|
* @test |
48
|
|
|
*/ |
49
|
|
|
public function testGetFakerDataParameters() |
50
|
|
|
{ |
51
|
|
|
$provider = $this->getMock(Provider::__CLASS); |
52
|
|
|
$provider->expects($this->once())->method('initialize'); |
53
|
|
|
$provider->expects($this->exactly(2))->method('getFakerData') |
54
|
|
|
->withConsecutive( |
55
|
|
|
array('email', '[email protected]|[email protected]', true), |
56
|
|
|
array('name', '[email protected]|Mr. Email', false)); |
57
|
|
|
|
58
|
|
|
$anonymizer = new Anonymizer($provider, 'de_DE'); |
59
|
|
|
$anonymizer->anonymize([new AnonymizableMock(['email' => '[email protected]', 'name' => 'Mr. Email'], 'email')]); |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public static function getAnonymizableData() |
64
|
|
|
{ |
65
|
|
|
return array( |
66
|
|
|
array( |
67
|
|
|
'inputData' => array( |
68
|
|
|
new AnonymizableMock(['email' => '[email protected]', 'firstName' => 'Max', 'lastName' => 'Mustermann']), |
69
|
|
|
new AnonymizableMock(['email' => '[email protected]', 'firstName' => 'Max', 'lastName' => 'Mustermann']), |
70
|
|
|
new AnonymizableMock(['email' => '[email protected]', 'firstName' => 'Maxi', 'lastName' => 'Musterfrau']), |
71
|
|
|
new AnonymizableMock(['email' => '[email protected]', 'firstName' => 'Max', 'lastName' => 'Mustermann', 'streetAddress' => 'Musterstraße 42']), |
72
|
|
|
), |
73
|
|
|
'expectedValues' => array( |
74
|
|
|
'[email protected]', '[email protected]', '[email protected]', |
75
|
|
|
'[email protected]', '[email protected]', '[email protected]', |
76
|
|
|
'[email protected]', '[email protected]', '[email protected]', |
77
|
|
|
'[email protected]', '[email protected]', '[email protected]', '[email protected]' |
78
|
|
|
) |
79
|
|
|
) |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|