1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* integer_net Magento Module |
4
|
|
|
* |
5
|
|
|
* @category IntegerNet |
6
|
|
|
* @package IntegerNet_Anonymizer |
7
|
|
|
* @copyright Copyright (c) 2015 integer_net GmbH (http://www.integer-net.de/) |
8
|
|
|
* @author Fabian Schmengler <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace IntegerNet\Anonymizer\Mock; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use IntegerNet\Anonymizer\Implementor\AnonymizableEntity; |
15
|
|
|
use IntegerNet\Anonymizer\AnonymizableValue; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Dumb implementation of AnonymizableEntity that generates AnonymizableValue instances from test data |
19
|
|
|
* |
20
|
|
|
* @package IntegerNet\Anonymizer\Mock |
21
|
|
|
*/ |
22
|
|
|
class AnonymizableMock implements AnonymizableEntity |
23
|
|
|
{ |
24
|
|
|
const __CLASS = __CLASS__; |
25
|
|
|
|
26
|
|
|
private $data = array(); |
27
|
|
|
private $identifier = ''; |
28
|
|
|
private $uniqueKey = null; |
29
|
|
|
/** |
30
|
|
|
* @var bool |
31
|
|
|
*/ |
32
|
|
|
private $isAnonymizable; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param mixed[] $data data in the form [formatter => value], the first entry will be used as identifier |
36
|
|
|
* @param string|null $uniqueKey |
37
|
|
|
*/ |
38
|
|
|
function __construct($data = array(), $uniqueKey = null, $isAnonymizable = true) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$this->uniqueKey = $uniqueKey; |
41
|
|
|
$this->setRawData($data); |
42
|
|
|
$this->isAnonymizable = $isAnonymizable; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function isAnonymizable() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
return $this->isAnonymizable; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
function getIdentifier() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
return $this->identifier; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return AnonymizableValue[] |
60
|
|
|
*/ |
61
|
|
|
function getValues() |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
return $this->data; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Sets raw data from database |
68
|
|
|
* |
69
|
|
|
* @param string[] $data |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
function setRawData($data) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
foreach ($data as $key => $value) { |
75
|
|
|
$this->data[] = new AnonymizableValue($key, $value, $this->uniqueKey === $key); |
76
|
|
|
} |
77
|
|
|
if (!empty($this->data)) { |
78
|
|
|
$this->identifier = reset($this->data)->getValue(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Update values in database |
84
|
|
|
* |
85
|
|
|
* @return mixed |
86
|
|
|
*/ |
87
|
|
|
function updateValues() |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
// method stub. Should be mocked with PHPUnit to set expectations |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Reset to empty instance |
94
|
|
|
* |
95
|
|
|
* @return mixed |
96
|
|
|
*/ |
97
|
|
|
function clearInstance() |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
$this->data = array(); |
100
|
|
|
$this->identifier = ''; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Returns name of entity as translatable string |
105
|
|
|
* |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
function getEntityName() |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
return 'Mock'; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.