|
1 | 1 | <?php |
2 | 2 |
|
3 | | -use DirectoryTree\Anonymize\AnonymizeManager; |
| 3 | +use DirectoryTree\Anonymize\Facades\Anonymize; |
4 | 4 | use DirectoryTree\Anonymize\Tests\AnonymizedModel; |
5 | | -use Faker\Factory; |
6 | 5 |
|
7 | 6 | it('does not leak data via serialize', function () { |
8 | | - setManager()->enable(); |
| 7 | + Anonymize::enable(); |
9 | 8 |
|
10 | 9 | $model = new AnonymizedModel([ |
11 | 10 | 'name' => 'Foo Bar', |
|
15 | 14 | }); |
16 | 15 |
|
17 | 16 | it('invalidates attribute cache when seed changes', function () { |
18 | | - setManager()->enable(); |
| 17 | + Anonymize::enable(); |
19 | 18 |
|
20 | 19 | $model = new AnonymizedModel([ |
21 | 20 | 'id' => 1, |
|
32 | 31 | }); |
33 | 32 |
|
34 | 33 | it('generates different attributes for models with distinct ids', function () { |
35 | | - setManager()->enable(); |
| 34 | + Anonymize::enable(); |
36 | 35 |
|
37 | 36 | $model1Attributes = (new AnonymizedModel([ |
38 | 37 | 'id' => 1, |
|
48 | 47 | }); |
49 | 48 |
|
50 | 49 | it('generates the same attributes for models with the same id', function () { |
51 | | - setManager()->enable(); |
| 50 | + Anonymize::enable(); |
52 | 51 |
|
53 | 52 | $model1Attributes = (new AnonymizedModel([ |
54 | 53 | 'id' => 1, |
|
64 | 63 | }); |
65 | 64 |
|
66 | 65 | it('overwrites only anonymized attributes', function () { |
67 | | - setManager()->enable(); |
| 66 | + Anonymize::enable(); |
68 | 67 |
|
69 | 68 | $attributes = (new AnonymizedModel([ |
70 | 69 | 'favourite_color' => 'blue', |
|
74 | 73 | }); |
75 | 74 |
|
76 | 75 | it('anonymizes only attributes that exist on the model', function () { |
77 | | - setManager()->enable(); |
| 76 | + Anonymize::enable(); |
78 | 77 |
|
79 | 78 | $attributes = (new AnonymizedModel([ |
80 | 79 | 'name' => 'Foo Bar', |
|
84 | 83 | }); |
85 | 84 |
|
86 | 85 | it('anonymizes attributes array when anonymization is enabled', function () { |
87 | | - setManager()->enable(); |
| 86 | + Anonymize::enable(); |
88 | 87 |
|
89 | 88 | $attributes = (new AnonymizedModel([ |
90 | 89 | 'name' => 'original-title', |
|
96 | 95 | }); |
97 | 96 |
|
98 | 97 | it('anonymizes attributes when anonymization is enabled', function () { |
99 | | - setManager()->enable(); |
| 98 | + Anonymize::enable(); |
100 | 99 |
|
101 | 100 | $model = new AnonymizedModel([ |
102 | 101 | 'name' => 'original-name', |
|
108 | 107 | }); |
109 | 108 |
|
110 | 109 | it('does not anonymize attributes array when anonymization is disabled', function () { |
111 | | - setManager()->disable(); |
| 110 | + Anonymize::disable(); |
112 | 111 |
|
113 | 112 | $original = [ |
114 | 113 | 'name' => 'Foo Bar', |
|
121 | 120 | }); |
122 | 121 |
|
123 | 122 | it('does not anonymize attributes when anonymization is disabled', function () { |
124 | | - setManager()->disable(); |
| 123 | + Anonymize::disable(); |
125 | 124 |
|
126 | 125 | $model = new AnonymizedModel([ |
127 | 126 | 'name' => 'Foo Bar', |
|
133 | 132 | }); |
134 | 133 |
|
135 | 134 | it('disables anonymization within withoutAnonymization block', function () { |
136 | | - setManager()->enable(); |
| 135 | + Anonymize::enable(); |
137 | 136 |
|
138 | 137 | $original = [ |
139 | 138 | 'name' => 'Foo Bar', |
|
154 | 153 | expect($seed)->toContain($id); |
155 | 154 | }); |
156 | 155 |
|
157 | | -function setManager(): AnonymizeManager |
158 | | -{ |
159 | | - AnonymizedModel::setManager($manager = new AnonymizeManager(Factory::create())); |
| 156 | +it('flushes anonymization manager enablement', function (string $attribute, string $value) { |
| 157 | + $model = new AnonymizedModel([$attribute => $value]); |
160 | 158 |
|
161 | | - return $manager; |
162 | | -} |
| 159 | + expect($model->getAttributeValue($attribute))->toBe($value); |
| 160 | + |
| 161 | + Anonymize::enable(); |
| 162 | + |
| 163 | + expect($model->getAttributeValue($attribute))->not->toBe($value); |
| 164 | +})->with([ |
| 165 | + ['name', 'Foo Bar'], |
| 166 | + |
| 167 | + ['address', '1600 Pennsylvania Avenue'], |
| 168 | +]); |
0 commit comments