-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add missing formatters in config and UT #508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andrestejerina97
wants to merge
2
commits into
main
Choose a base branch
from
feature/add-missing-ut-formatters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
tests/OpenTelemetry/Formatters/CompanyAuditLogFormatterTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\OpenTelemetry\Formatters; | ||
|
|
||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use App\Audit\ConcreteFormatters\CompanyAuditLogFormatter; | ||
| use App\Audit\Interfaces\IAuditStrategy; | ||
| use Tests\OpenTelemetry\Formatters\Support\AuditContextBuilder; | ||
| use Mockery; | ||
| use Tests\TestCase; | ||
|
|
||
| class CompanyAuditLogFormatterTest extends TestCase | ||
| { | ||
| private mixed $mockSubject; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| $this->mockSubject = $this->createMockSubject(); | ||
| } | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| Mockery::close(); | ||
| parent::tearDown(); | ||
| } | ||
|
|
||
| private function createMockSubject(): mixed | ||
| { | ||
| $mock = Mockery::mock('models\main\Company'); | ||
|
|
||
| // Configure return values | ||
| $mock->shouldReceive('getId')->andReturn(1); | ||
| $mock->shouldReceive('getName')->andReturn('TechCorp Inc'); | ||
| $mock->shouldReceive('getCity')->andReturn('San Francisco'); | ||
| $mock->shouldReceive('getCountry')->andReturn('USA'); | ||
| $mock->shouldReceive('isDisplayOnSite')->andReturn(true); | ||
|
|
||
| return $mock; | ||
| } | ||
|
|
||
| public function testSubjectCreationAuditMessage(): void | ||
| { | ||
| $formatter = new CompanyAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION); | ||
| $formatter->setContext(AuditContextBuilder::default()->build()); | ||
| $result = $formatter->format($this->mockSubject, []); | ||
|
|
||
| $this->assertNotNull($result); | ||
| $this->assertStringContainsString('created', $result); | ||
| $this->assertStringContainsString('TechCorp Inc', $result); | ||
| $this->assertStringContainsString('San Francisco', $result); | ||
| } | ||
|
|
||
| public function testSubjectUpdateAuditMessage(): void | ||
| { | ||
| $formatter = new CompanyAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_UPDATE); | ||
| $formatter->setContext(AuditContextBuilder::default()->build()); | ||
| $changeSet = [ | ||
| 'city' => ['San Francisco', 'Los Angeles'], | ||
| 'country' => ['USA', 'USA'] | ||
| ]; | ||
|
|
||
| $result = $formatter->format($this->mockSubject, $changeSet); | ||
|
|
||
| $this->assertNotNull($result); | ||
| $this->assertStringContainsString('updated', $result); | ||
| } | ||
|
|
||
| public function testSubjectDeletionAuditMessage(): void | ||
| { | ||
| $formatter = new CompanyAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_DELETION); | ||
| $formatter->setContext(AuditContextBuilder::default()->build()); | ||
| $result = $formatter->format($this->mockSubject, []); | ||
|
|
||
| $this->assertNotNull($result); | ||
| $this->assertStringContainsString('deleted', $result); | ||
| } | ||
|
|
||
| public function testFormatterReturnsNullForInvalidSubject(): void | ||
| { | ||
| $formatter = new CompanyAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION); | ||
| $result = $formatter->format(new \stdClass(), []); | ||
| $this->assertNull($result); | ||
| } | ||
| } | ||
104 changes: 104 additions & 0 deletions
104
tests/OpenTelemetry/Formatters/PresentationCategoryAuditLogFormatterTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\OpenTelemetry\Formatters; | ||
|
|
||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use App\Audit\ConcreteFormatters\PresentationCategoryAuditLogFormatter; | ||
| use App\Audit\Interfaces\IAuditStrategy; | ||
| use Tests\OpenTelemetry\Formatters\Support\AuditContextBuilder; | ||
| use Mockery; | ||
| use Tests\TestCase; | ||
|
|
||
| class PresentationCategoryAuditLogFormatterTest extends TestCase | ||
| { | ||
| private mixed $mockSubject; | ||
| private mixed $mockSummit; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| $this->mockSummit = $this->createMockSummit(); | ||
| $this->mockSubject = $this->createMockSubject(); | ||
| } | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| Mockery::close(); | ||
| parent::tearDown(); | ||
| } | ||
|
|
||
| private function createMockSummit(): mixed | ||
| { | ||
| $mock = Mockery::mock('models\summit\Summit'); | ||
| $mock->shouldReceive('getName')->andReturn('OpenStack Summit 2024'); | ||
| return $mock; | ||
| } | ||
|
|
||
| private function createMockSubject(): mixed | ||
| { | ||
| $mock = Mockery::mock('models\summit\PresentationCategory'); | ||
|
|
||
| // Configure return values | ||
| $mock->shouldReceive('getId')->andReturn(10); | ||
| $mock->shouldReceive('getTitle')->andReturn('Cloud Architecture'); | ||
| $mock->shouldReceive('getCode')->andReturn('CLOUD-ARCH'); | ||
| $mock->shouldReceive('getSummit')->andReturn($this->mockSummit); | ||
|
|
||
| return $mock; | ||
| } | ||
|
|
||
| public function testSubjectCreationAuditMessage(): void | ||
| { | ||
| $formatter = new PresentationCategoryAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION); | ||
| $formatter->setContext(AuditContextBuilder::default()->build()); | ||
| $result = $formatter->format($this->mockSubject, []); | ||
|
|
||
| $this->assertNotNull($result); | ||
| $this->assertStringContainsString('created', $result); | ||
| $this->assertStringContainsString('Cloud Architecture', $result); | ||
| $this->assertStringContainsString('CLOUD-ARCH', $result); | ||
| } | ||
|
|
||
| public function testSubjectUpdateAuditMessage(): void | ||
| { | ||
| $formatter = new PresentationCategoryAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_UPDATE); | ||
| $formatter->setContext(AuditContextBuilder::default()->build()); | ||
| $changeSet = [ | ||
| 'title' => ['Cloud Architecture', 'Infrastructure & Architecture'] | ||
| ]; | ||
|
|
||
| $result = $formatter->format($this->mockSubject, $changeSet); | ||
|
|
||
| $this->assertNotNull($result); | ||
| $this->assertStringContainsString('updated', $result); | ||
| } | ||
|
|
||
| public function testSubjectDeletionAuditMessage(): void | ||
| { | ||
| $formatter = new PresentationCategoryAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_DELETION); | ||
| $formatter->setContext(AuditContextBuilder::default()->build()); | ||
| $result = $formatter->format($this->mockSubject, []); | ||
|
|
||
| $this->assertNotNull($result); | ||
| $this->assertStringContainsString('deleted', $result); | ||
| } | ||
|
|
||
| public function testFormatterReturnsNullForInvalidSubject(): void | ||
| { | ||
| $formatter = new PresentationCategoryAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION); | ||
| $result = $formatter->format(new \stdClass(), []); | ||
| $this->assertNull($result); | ||
| } | ||
| } |
99 changes: 99 additions & 0 deletions
99
tests/OpenTelemetry/Formatters/PresentationCategoryGroupAuditLogFormatterTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\OpenTelemetry\Formatters; | ||
|
|
||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use App\Audit\ConcreteFormatters\PresentationCategoryGroupAuditLogFormatter; | ||
| use App\Audit\Interfaces\IAuditStrategy; | ||
| use Tests\OpenTelemetry\Formatters\Support\AuditContextBuilder; | ||
| use Mockery; | ||
| use Tests\TestCase; | ||
|
|
||
| class PresentationCategoryGroupAuditLogFormatterTest extends TestCase | ||
| { | ||
| private mixed $mockSubject; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| $this->mockSubject = $this->createMockSubject(); | ||
| } | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| Mockery::close(); | ||
| parent::tearDown(); | ||
| } | ||
|
|
||
| private function createMockSubject(): mixed | ||
| { | ||
| $mockSummit = Mockery::mock('models\summit\Summit'); | ||
| $mockSummit->shouldReceive('getName')->andReturn('OpenStack Summit'); | ||
|
|
||
| $mock = Mockery::mock('models\summit\PresentationCategoryGroup'); | ||
|
|
||
| // Configure return values | ||
| $mock->shouldReceive('getId')->andReturn(5); | ||
| $mock->shouldReceive('getName')->andReturn('Technical Tracks'); | ||
| $mock->shouldReceive('getDescription')->andReturn('Group for technical presentations'); | ||
| $mock->shouldReceive('getSummit')->andReturn($mockSummit); | ||
| $mock->shouldReceive('getColor')->andReturn('#FF5733'); | ||
| $mock->shouldReceive('getMaxAttendeeVotes')->andReturn(3); | ||
|
|
||
| return $mock; | ||
| } | ||
|
|
||
| public function testSubjectCreationAuditMessage(): void | ||
| { | ||
| $formatter = new PresentationCategoryGroupAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION); | ||
| $formatter->setContext(AuditContextBuilder::default()->build()); | ||
| $result = $formatter->format($this->mockSubject, []); | ||
|
|
||
| $this->assertNotNull($result); | ||
| $this->assertStringContainsString('created', $result); | ||
| $this->assertStringContainsString('Technical Tracks', $result); | ||
| } | ||
|
|
||
| public function testSubjectUpdateAuditMessage(): void | ||
| { | ||
| $formatter = new PresentationCategoryGroupAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_UPDATE); | ||
| $formatter->setContext(AuditContextBuilder::default()->build()); | ||
| $changeSet = [ | ||
| 'name' => ['Technical Tracks', 'Core Technical Topics'] | ||
| ]; | ||
|
|
||
| $result = $formatter->format($this->mockSubject, $changeSet); | ||
|
|
||
| $this->assertNotNull($result); | ||
| $this->assertStringContainsString('updated', $result); | ||
| } | ||
|
|
||
| public function testSubjectDeletionAuditMessage(): void | ||
| { | ||
| $formatter = new PresentationCategoryGroupAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_DELETION); | ||
| $formatter->setContext(AuditContextBuilder::default()->build()); | ||
| $result = $formatter->format($this->mockSubject, []); | ||
|
|
||
| $this->assertNotNull($result); | ||
| $this->assertStringContainsString('deleted', $result); | ||
| } | ||
|
|
||
| public function testFormatterReturnsNullForInvalidSubject(): void | ||
| { | ||
| $formatter = new PresentationCategoryGroupAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION); | ||
| $result = $formatter->format(new \stdClass(), []); | ||
| $this->assertNull($result); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set formatter context in invalid-subject test to isolate the assertion.
This test currently verifies
nullwithout the same context setup used elsewhere, so a future context-related failure could mask the real intent (invalid subject handling).Proposed patch
public function testFormatterReturnsNullForInvalidSubject(): void { $formatter = new CompanyAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION); + $formatter->setContext(AuditContextBuilder::default()->build()); $result = $formatter->format(new \stdClass(), []); $this->assertNull($result); }📝 Committable suggestion
🤖 Prompt for AI Agents