-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathAddressAnonymizerTest.php
More file actions
97 lines (89 loc) · 3.77 KB
/
AddressAnonymizerTest.php
File metadata and controls
97 lines (89 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
declare(strict_types=1);
namespace DbToolsBundle\PackFrFR\Tests\Functional\Anonymizer\Core;
use MakinaCorpus\DbToolsBundle\Anonymization\Anonymizer\Options;
use MakinaCorpus\DbToolsBundle\Test\FunctionalTestCase;
class AddressAnonymizerTest extends FunctionalTestCase
{
/** @before */
protected function createTestData(): void
{
$this->createOrReplaceTable(
'table_test',
[
'id' => 'integer',
'my_street_address' => 'string',
'my_secondary_address' => 'string',
'my_postal_code' => 'string',
'my_locality' => 'string',
'my_region' => 'string',
'my_country' => 'string',
],
[
[
'id' => '1',
'my_street_address' => 'Rue Aristide Briand',
'my_secondary_address' => 'La maison aux volets bleus',
'my_postal_code' => '44400',
'my_locality' => 'REZE',
'my_region' => 'Pays de loire',
'my_country' => 'FRANCE',
],
[
'id' => '2',
'my_street_address' => 'Rue Jean Jaures',
'my_secondary_address' => 'Au dernier étage',
'my_postal_code' => '44000',
'my_locality' => 'Toto-les-bains',
'my_region' => 'Pays de loire',
'my_country' => 'FRANCE',
],
[
'id' => '3',
],
],
);
}
public function testAnonymize(): void
{
$anonymizator = $this->createAnonymizatorArbitrary(
'table_test',
'data',
'address',
new Options([
'street_address' => 'my_street_address',
'secondary_address' => 'my_secondary_address',
'postal_code' => 'my_postal_code',
'locality' => 'my_locality',
'region' => 'my_region',
'country' => 'my_country',
])
);
$this->assertSame(
"Rue Aristide Briand",
$this->getDatabaseSession()->executeQuery('select my_street_address from table_test where id = 1')->fetchOne(),
);
$anonymizator->anonymize();
$datas = $this->getDatabaseSession()->executeQuery('select * from table_test order by id asc')->fetchAllAssociative();
$this->assertNotNull($datas[0]);
$this->assertNotSame('Rue Aristide Briand', $datas[0]['my_street_address']);
$this->assertNotSame('La maison aux volets bleus', $datas[0]['my_secondary_address']);
$this->assertNotSame('44400', $datas[0]['my_postal_code']);
$this->assertNotSame('REZE', $datas[0]['my_locality']);
$this->assertNotSame('Pays de loire', $datas[0]['my_region']);
$this->assertNotNull($datas[1]);
$this->assertNotSame('Rue Jean Jaures', $datas[1]['my_street_address']);
$this->assertNotSame('Au dernier étage', $datas[1]['my_secondary_address']);
$this->assertNotSame('44000', $datas[1]['my_postal_code']);
$this->assertNotSame('Toto-les-bains', $datas[1]['my_locality']);
$this->assertNotSame('Pays de loire', $datas[1]['my_region']);
/*
$this->assertNull($datas[2]['my_street_address']);
$this->assertNull($datas[2]['my_secondary_address']);
$this->assertNull($datas[2]['my_postal_code']);
$this->assertNull($datas[2]['my_locality']);
$this->assertNull($datas[2]['my_region']);
*/
$this->assertCount(3, \array_unique(\array_map(fn ($value) => \serialize($value), $datas)), 'All generated values are different.');
}
}