Skip to content

Commit 3ca9a24

Browse files
committed
Adds tests to the spec of #10, to prevent the issue from re-occurring and to validate it has been solved. Refs #10
1 parent 3fa8823 commit 3ca9a24

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

tests/HashSensitiveArrayTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,22 @@
8282

8383
$record = $this->getRecord(context: $this->insideNested->getInput());
8484
expect($processor($record)->context)->toBe(['test' => ['nested' => 'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2']]);
85+
});
86+
87+
# Prevent bugs from re-appearing
88+
# Issue: https://github.com/Globy-App/hash-sensitive/issues/10
89+
it('does not hash values of integer keys', function (): void {
90+
$integerKeys = new TestDataEntity([0 => 'foo', 1 => 'bar'], ['other', 'first', 'second']);
91+
$processor = new HashSensitiveProcessor($integerKeys->getSensitiveKeys());
92+
93+
$record = $this->getRecord(context: $integerKeys->getInput());
94+
expect($processor($record)->context)->toBe(['test' => [0 => 'foo', 1 => 'bar']]);
95+
});
96+
97+
it('does not throw an exception', function (): void {
98+
$integerKeys = new TestDataEntity([0 => ['id' => 1, 'value' => 'foo'], 1 => ['id' => 2, 'value' => 'bar']], ['other', 'first', 'second']);
99+
$processor = new HashSensitiveProcessor($integerKeys->getSensitiveKeys());
100+
101+
$record = $this->getRecord(context: $integerKeys->getInput());
102+
expect($processor($record)->context)->toBe(['test' => [0 => ['id' => 1, 'value' => 'foo'], 1 => ['id' => 2, 'value' => 'bar']]]);
85103
});

tests/HashSensitiveObjectTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,23 @@
168168
expect($processor($record)->context)->toBe(['nested' => $nested])
169169
->and($nested->test)->toBe('c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2')
170170
->and($nested->optionalKey)->toBeNull();
171+
});
172+
173+
# Prevent bugs from re-appearing
174+
# Issue: https://github.com/Globy-App/hash-sensitive/issues/
175+
it('does not throw an exception', function (): void {
176+
$nested1 = new \stdClass();
177+
$nested1->id = 1;
178+
$nested1->value = 'foo';
179+
180+
$nested2 = new \stdClass();
181+
$nested2->id = 2;
182+
$nested2->value = 'bar';
183+
184+
$input = [0 => $nested1, 1 => $nested2];
185+
$sensitive_keys = ['other', 'first', 'second'];
186+
$processor = new HashSensitiveProcessor($sensitive_keys);
187+
188+
$record = $this->getRecord(context: $input);
189+
expect($processor($record)->context)->toBe([0 => $nested1, 1 => $nested2]);
171190
});

0 commit comments

Comments
 (0)