Skip to content

Commit f317dd8

Browse files
authored
Merge pull request #62 from mirko-bukilic/master
Updated FieldsTruncator
2 parents 10f5617 + 4592c13 commit f317dd8

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

src/Buffer/FieldsTruncator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private function truncateValue(string $fieldName, $value)
7777
public function shouldTruncateField(string $fieldName): bool
7878
{
7979
if (!isset($this->config[$this->logType])) {
80-
return true;
80+
return false;
8181
}
8282
return in_array($fieldName, $this->config[$this->logType], true);
8383
}

test/src/Buffer/FieldsTruncatorTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ protected function setUp(): void
1515
'enabled' => 1,
1616
'truncate_above' => 100,
1717
'truncate_to' => 50,
18+
'nd_test' => [
19+
'app_message',
20+
'code',
21+
'params',
22+
],
1823
'nd_requests' => [
1924
'resource',
2025
'params',
26+
'profiler',
2127
],
2228
];
2329
}
@@ -38,9 +44,19 @@ public function testShouldTruncateField(): void
3844
$fieldsTruncator = new FieldsTruncator(new StringLiteral('nd_requests'), $this->config);
3945
self::assertTrue($fieldsTruncator->shouldTruncateField('resource'));
4046
self::assertTrue($fieldsTruncator->shouldTruncateField('params'));
47+
self::assertTrue($fieldsTruncator->shouldTruncateField('profiler'));
4148
self::assertFalse($fieldsTruncator->shouldTruncateField('app_message'));
4249
}
4350

51+
/**
52+
* @dataProvider truncateDataProvider
53+
*/
54+
public function testTruncateField(string $indexName, string $fieldName, bool $expectedResult): void
55+
{
56+
$truncator = new FieldsTruncator(new StringLiteral($indexName), $this->config);
57+
self::assertSame($expectedResult, $truncator->shouldTruncateField($fieldName));
58+
}
59+
4460
public function testTruncate(): void
4561
{
4662
$fieldsTruncator = new FieldsTruncator(new StringLiteral('nd_requests'), $this->config);
@@ -63,4 +79,27 @@ public function testTruncate(): void
6379

6480
self::assertSame($expected, $fieldsTruncator->truncate($logData));
6581
}
82+
83+
public function truncateDataProvider(): array
84+
{
85+
return [
86+
['nd_requests', 'params', true],
87+
['nd_requests', 'resource', true],
88+
['nd_requests', 'profiler', true],
89+
['nd_requests', 'app_message', false],
90+
['nd_requests', 'app_version', false],
91+
['nd_requests', 'method', false],
92+
['mailer_sent_emails', 'params', false],
93+
['mailer_sent_emails', 'resource', false],
94+
['mailer_sent_emails', 'profiler', false],
95+
['mailer_sent_emails', 'app_message', false],
96+
['mailer_sent_emails', 'app_version', false],
97+
['mailer_sent_emails', 'method', false],
98+
['nd_test', 'profiler', false],
99+
['nd_test', 'resource', false],
100+
['nd_test', 'app_message', true],
101+
['nd_test', 'code', true],
102+
['nd_test', 'params', true],
103+
];
104+
}
66105
}

0 commit comments

Comments
 (0)