Skip to content

refactor: clean up tests by removing redundant cases and improving validation logic#61

Merged
konradmichalik merged 4 commits intomainfrom
minify-test-sute
Jul 29, 2025
Merged

refactor: clean up tests by removing redundant cases and improving validation logic#61
konradmichalik merged 4 commits intomainfrom
minify-test-sute

Conversation

@konradmichalik
Copy link
Copy Markdown
Contributor

@konradmichalik konradmichalik commented Jul 29, 2025

Automatically generated tests are all well and good, but this has gotten a bit out of hand here.

Summary by CodeRabbit

  • Tests
    • Simplified and refactored multiple test suites, removing numerous detailed and edge-case tests to focus on core behaviors.
    • Consolidated and replaced individual tests with parameterized tests for improved coverage and maintainability.
    • Reduced complexity and coverage in file collection, validation rendering, and key naming convention tests, resulting in a more streamlined test suite.
  • Features
    • Updated key naming convention options to rely on a refined list of configurable conventions, improving clarity and maintainability.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 29, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update significantly reduces and refactors test coverage across several test suites. Many detailed and edge-case tests were removed from CollectorTest, ValidationResultCliRendererTest, and ValidationRunTest, focusing the suites on core behaviors. KeyNamingConventionValidatorTest was refactored to use parameterized tests with data providers, consolidating and simplifying previous individual tests. Additionally, the method getAvailableConventions() in KeyNamingConventionValidator was updated to rely on KeyNamingConvention::getConfigurableConventions() for retrieving conventions.

Changes

Cohort / File(s) Change Summary
File Collection Test Simplification
tests/src/FileDetector/CollectorTest.php
Removed numerous edge-case and error-handling tests; renamed and simplified remaining tests to focus on core file collection and exclusion behaviors.
CLI Renderer Test Reduction
tests/src/Result/ValidationResultCliRendererTest.php
Deleted many tests covering verbose/compact output, sorting, formatting, statistics, and grouping; kept only basic rendering and exit code tests, renaming and simplifying where appropriate.
Validation Run Test Cleanup
tests/src/Result/ValidationRunTest.php
Removed tests for empty file sets, parser exceptions, and null key handling; deleted related mock parser classes and unused imports.
Key Naming Convention Test Refactor
tests/src/Validator/KeyNamingConventionValidatorTest.php
Replaced multiple specific tests with parameterized tests using data providers for edge cases, mixed conventions, and dot notation; removed redundant tests and imports, improving structure and maintainability.
Key Naming Convention Validator Update
src/Validator/KeyNamingConventionValidator.php
Modified getAvailableConventions() to use KeyNamingConvention::getConfigurableConventions() instead of manual filtering to obtain configurable key naming conventions, simplifying the method implementation.

Sequence Diagram(s)

sequenceDiagram
    participant Tester as Test Suite
    participant Collector as Collector
    participant Validator as Validator
    participant CLI as CLI Renderer

    Tester->>Collector: Test core file collection (recursive, exclusion)
    Tester->>Validator: Test naming conventions (parameterized)
    Tester->>CLI: Test rendering with/without issues (basic cases)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Possibly related PRs

Poem

In the warren where test bunnies dwell,
We trimmed the hedges, pruned quite well.
Edge-cases hopped away,
Parameterized, they stay—
Now our garden is tidy, concise, and swell!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34487e6 and b1bb980.

📒 Files selected for processing (2)
  • src/Validator/KeyNamingConventionValidator.php (1 hunks)
  • tests/src/FileDetector/CollectorTest.php (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch minify-test-sute

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

… notation directly in the configurable conventions method
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
tests/src/FileDetector/CollectorTest.php (1)

213-228: Hard-coded expectation may be brittle

The test expects exactly 4 debug log calls, which appears to correspond to the number of parser classes being checked. This hard-coded value could break if parser types are added or removed in the future.

Consider making the test more maintainable by either:

  1. Adding a comment explaining why exactly 4 calls are expected
  2. Making the expectation more flexible or based on the actual number of parser classes
         $logger = $this->createMock(LoggerInterface::class);
+        // Expecting 4 calls: one for each parser type (Xliff, Yaml, Json, PHP)
         $logger->expects($this->exactly(4))
             ->method('debug')
             ->with($this->stringContains('No files found for parser class'));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e3eff1a and 34487e6.

📒 Files selected for processing (4)
  • tests/src/FileDetector/CollectorTest.php (1 hunks)
  • tests/src/Result/ValidationResultCliRendererTest.php (5 hunks)
  • tests/src/Result/ValidationRunTest.php (0 hunks)
  • tests/src/Validator/KeyNamingConventionValidatorTest.php (1 hunks)
💤 Files with no reviewable changes (1)
  • tests/src/Result/ValidationRunTest.php
🔇 Additional comments (11)
tests/src/Result/ValidationResultCliRendererTest.php (5)

240-241: LGTM!

The addition of the assertion for "Parsers cached: 0" appropriately tests the new statistics output.


243-257: LGTM!

The test correctly verifies that statistics are not displayed in compact mode (normal verbosity).


288-308: LGTM!

Good test coverage for warning handling in compact mode. The test correctly verifies that warnings result in exit code 0 and display the appropriate message.


310-331: LGTM!

Good test coverage for error handling in compact mode. The test correctly verifies exit code 1 and appropriate error messaging.


353-372: LGTM!

The test properly verifies warning display in verbose mode, including the [WARNING] tag.

tests/src/Validator/KeyNamingConventionValidatorTest.php (6)

707-729: LGTM!

Well-structured parameterized test with clear data provider covering important edge cases for snake_case validation.


731-750: LGTM!

Excellent data provider with clear, descriptive test case names and comprehensive edge case coverage.


752-771: LGTM!

Well-implemented test for mixed convention detection with proper handling of optional assertions.


773-800: LGTM!

Comprehensive data provider with excellent coverage of mixed convention scenarios.


802-825: LGTM!

Thorough test implementation for dot notation handling across different naming conventions, with proper suggestion verification.


827-857: LGTM!

Excellent data provider with comprehensive coverage of dot notation scenarios across different naming conventions.

Comment on lines +152 to 167
public function testCollectFilesRecursive(): void
{
// Create nested directory structure
mkdir($this->tempDir.'/level1', 0777, true);
mkdir($this->tempDir.'/level1/level2', 0777, true);

file_put_contents($this->tempDir.'/root.xlf', 'root content');
file_put_contents($this->tempDir.'/level1/nested.xlf', 'nested content');
file_put_contents($this->tempDir.'/level1/level2/deep.xlf', 'deep content');

// Debug: verify files exist
$this->assertFileExists($this->tempDir.'/root.xlf', 'root.xlf should exist');
$this->assertFileExists($this->tempDir.'/level1/nested.xlf', 'nested.xlf should exist');
$this->assertFileExists($this->tempDir.'/level1/level2/deep.xlf', 'deep.xlf should exist');

// Debug: test RecursiveDirectoryIterator directly
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($this->tempDir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::LEAVES_ONLY,
);
$foundFiles = [];
foreach ($iterator as $file) {
$foundFiles[] = $file->getPathname();
}
$this->assertNotEmpty($foundFiles, 'RecursiveDirectoryIterator should find files');
$this->assertContains($this->tempDir.'/root.xlf', $foundFiles, 'Should find root.xlf');
$this->assertContains($this->tempDir.'/level1/nested.xlf', $foundFiles, 'Should find nested.xlf');

$logger = $this->createMock(LoggerInterface::class);
$detector = $this->createMock(DetectorInterface::class);
$detector->method('mapTranslationSet')->willReturn(['recursive_mapped_data']);
$detector->method('mapTranslationSet')->willReturn(['recursive_data']);

$collector = new Collector($logger);

// Test with recursive = true
$result = $collector->collectFiles([$this->tempDir], $detector, null, true);

$this->assertArrayHasKey(XliffParser::class, $result);
$this->assertArrayHasKey($this->tempDir, $result[XliffParser::class]);
$this->assertEquals(['recursive_mapped_data'], $result[XliffParser::class][$this->tempDir]);
}

public function testCollectFilesNonRecursiveOnlyFindsRootFiles(): void
{
// Create nested directory structure
mkdir($this->tempDir.'/level1', 0777, true);

file_put_contents($this->tempDir.'/root.xlf', 'root content');
file_put_contents($this->tempDir.'/level1/nested.xlf', 'nested content');

$logger = $this->createMock(LoggerInterface::class);
$detector = $this->createMock(DetectorInterface::class);
$detector->method('mapTranslationSet')->willReturn(['non_recursive_mapped_data']);

$collector = new Collector($logger);

// Test with recursive = false (default)
$result = $collector->collectFiles([$this->tempDir], $detector, null, false);

$this->assertArrayHasKey(XliffParser::class, $result);
$this->assertArrayHasKey($this->tempDir, $result[XliffParser::class]);
$this->assertEquals(['non_recursive_mapped_data'], $result[XliffParser::class][$this->tempDir]);
$this->assertEquals(['recursive_data'], $result[XliffParser::class][$this->tempDir]);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Test may not adequately verify recursive file collection behavior

The test has been simplified to only verify that the mocked data is returned, but it doesn't actually verify that files from both the root and nested directories are collected. The test creates files at different levels but doesn't assert that both files were found during recursive collection.

Consider adding assertions to verify that files from multiple directory levels are actually collected when recursive mode is enabled.

🤖 Prompt for AI Agents
In tests/src/FileDetector/CollectorTest.php around lines 152 to 167, the test
does not verify that files from both root and nested directories are collected
recursively. To fix this, add assertions that check the presence of both
'root.xlf' and 'level1/nested.xlf' files in the collected results, ensuring the
recursive collection behavior is properly tested.

@konradmichalik konradmichalik merged commit 76d0f14 into main Jul 29, 2025
25 of 28 checks passed
@konradmichalik konradmichalik deleted the minify-test-sute branch September 7, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant