Skip to content

Commit da94a17

Browse files
feat: add new test for the formatter
1 parent b33f118 commit da94a17

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

tests/OpenTelemetry/Formatters/SummitBadgeFeatureTypeAuditLogFormatterTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ class SummitBadgeFeatureTypeAuditLogFormatterTest extends TestCase
2828
private const USER_EMAIL = 'designer@example.com';
2929
private const USER_FIRST_NAME = 'Sarah';
3030
private const USER_LAST_NAME = 'Williams';
31-
private const MOCK_ID = 1;
3231
private const SUMMIT_NAME = 'Test Summit';
32+
private const NULL_SUMMIT_BADGE_FEATURE_NAME = 'VIP Badge Feature';
33+
private const NULL_SUMMIT_BADGE_FEATURE_ID = 1;
34+
private const NULL_SUMMIT_LABEL = 'Unknown Summit';
3335

3436
private SummitBadgeFeatureTypeAuditLogFormatter $formatter_creation;
3537
private SummitBadgeFeatureTypeAuditLogFormatter $formatter_update;
@@ -133,6 +135,21 @@ public function testPropertiesExist(): void
133135
$this->assertTrue(method_exists($badge_feature, 'getSummit'));
134136
}
135137

138+
public function testFormatCreationWithNullSummit(): void
139+
{
140+
$badge_feature = Mockery::mock(SummitBadgeFeatureType::class);
141+
$badge_feature->shouldReceive('getName')->andReturn(self::NULL_SUMMIT_BADGE_FEATURE_NAME);
142+
$badge_feature->shouldReceive('getId')->andReturn(self::NULL_SUMMIT_BADGE_FEATURE_ID);
143+
$badge_feature->shouldReceive('getSummit')->andReturn(null);
144+
145+
$this->formatter_creation->setContext($this->audit_context);
146+
$result = $this->formatter_creation->format($badge_feature, []);
147+
148+
$this->assertNotNull($result);
149+
$this->assertStringContainsString(self::NULL_SUMMIT_LABEL, $result);
150+
$this->assertStringContainsString(self::NULL_SUMMIT_BADGE_FEATURE_NAME, $result);
151+
}
152+
136153
private function createMockBadgeFeatureType(string $name, int $id): object
137154
{
138155
$mock = Mockery::mock(SummitBadgeFeatureType::class);

tests/OpenTelemetry/Formatters/SummitBadgeTypeAuditLogFormatterTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ class SummitBadgeTypeAuditLogFormatterTest extends TestCase
2828
private const USER_EMAIL = 'coordinator@example.com';
2929
private const USER_FIRST_NAME = 'Robert';
3030
private const USER_LAST_NAME = 'Brown';
31-
private const MOCK_ID = 1;
3231
private const SUMMIT_NAME = 'Test Summit';
32+
private const NULL_SUMMIT_BADGE_TYPE_NAME = 'Standard Badge Type';
33+
private const NULL_SUMMIT_BADGE_TYPE_ID = 1;
34+
private const NULL_SUMMIT_LABEL = 'Unknown Summit';
3335

3436
private SummitBadgeTypeAuditLogFormatter $formatter_creation;
3537
private SummitBadgeTypeAuditLogFormatter $formatter_update;
@@ -134,6 +136,21 @@ public function testPropertiesExist(): void
134136
$this->assertTrue(method_exists($badge_type, 'getSummit'));
135137
}
136138

139+
public function testFormatCreationWithNullSummit(): void
140+
{
141+
$badge_type = Mockery::mock(SummitBadgeType::class);
142+
$badge_type->shouldReceive('getName')->andReturn(self::NULL_SUMMIT_BADGE_TYPE_NAME);
143+
$badge_type->shouldReceive('getId')->andReturn(self::NULL_SUMMIT_BADGE_TYPE_ID);
144+
$badge_type->shouldReceive('getSummit')->andReturn(null);
145+
146+
$this->formatter_creation->setContext($this->audit_context);
147+
$result = $this->formatter_creation->format($badge_type, []);
148+
149+
$this->assertNotNull($result);
150+
$this->assertStringContainsString(self::NULL_SUMMIT_LABEL, $result);
151+
$this->assertStringContainsString(self::NULL_SUMMIT_BADGE_TYPE_NAME, $result);
152+
}
153+
137154
private function createMockBadgeType(string $name, int $id): object
138155
{
139156
$mock = Mockery::mock(SummitBadgeType::class);

tests/OpenTelemetry/Formatters/SummitBadgeViewTypeAuditLogFormatterTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ class SummitBadgeViewTypeAuditLogFormatterTest extends TestCase
2828
private const USER_EMAIL = 'admin@example.com';
2929
private const USER_FIRST_NAME = 'Jane';
3030
private const USER_LAST_NAME = 'Smith';
31-
private const MOCK_ID = 1;
3231
private const SUMMIT_NAME = 'Test Summit';
32+
private const NULL_SUMMIT_BADGE_VIEW_NAME = 'Standard Badge';
33+
private const NULL_SUMMIT_BADGE_VIEW_ID = 1;
34+
private const NULL_SUMMIT_LABEL = 'Unknown Summit';
3335

3436
private SummitBadgeViewTypeAuditLogFormatter $formatter_creation;
3537
private SummitBadgeViewTypeAuditLogFormatter $formatter_update;
@@ -133,6 +135,21 @@ public function testPropertiesExist(): void
133135
$this->assertTrue(method_exists($badge_view, 'getSummit'));
134136
}
135137

138+
public function testFormatCreationWithNullSummit(): void
139+
{
140+
$badge_view = Mockery::mock(SummitBadgeViewType::class);
141+
$badge_view->shouldReceive('getName')->andReturn(self::NULL_SUMMIT_BADGE_VIEW_NAME);
142+
$badge_view->shouldReceive('getId')->andReturn(self::NULL_SUMMIT_BADGE_VIEW_ID);
143+
$badge_view->shouldReceive('getSummit')->andReturn(null);
144+
145+
$this->formatter_creation->setContext($this->audit_context);
146+
$result = $this->formatter_creation->format($badge_view, []);
147+
148+
$this->assertNotNull($result);
149+
$this->assertStringContainsString(self::NULL_SUMMIT_LABEL, $result);
150+
$this->assertStringContainsString(self::NULL_SUMMIT_BADGE_VIEW_NAME, $result);
151+
}
152+
136153
private function createMockBadgeViewType(string $name, int $id): object
137154
{
138155
$mock = Mockery::mock(SummitBadgeViewType::class);

0 commit comments

Comments
 (0)