Skip to content

test: remove redundant tests - #34

Merged
loadinglucian merged 4 commits into
mainfrom
test/remove-redundant-tests
Oct 10, 2025
Merged

test: remove redundant tests#34
loadinglucian merged 4 commits into
mainfrom
test/remove-redundant-tests

Conversation

@loadinglucian

@loadinglucian loadinglucian commented Oct 10, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Tests
    • Consolidated server add flow into a single end-to-end test verifying display and persistence.
    • Replaced multiple server delete tests with a data-driven test covering varied key path scenarios and output verification.
    • Retained non-interactive deletion and success/error behavior tests; removed redundant confirmation/display cases.
    • Simplified server list test suite by removing an overlapping full-field render test.
    • Removed an inventory loading test from the repository suite.
    • No user-facing behavior changes; improved test clarity and maintainability.

Remove 'loads existing servers from inventory' test as it duplicates
functionality already covered by the comprehensive CRUD lifecycle test.
The existing test already verifies server loading and findByName operations.
- Remove 'saves server when confirmation is given' (duplicate of SSH test)
- Remove 'shows default SSH key path when not provided' (covered by minimal options test)
- Consolidate 'persists server data' and 'displays complete server info' into single comprehensive test
- Maintain full coverage while reducing test redundancy by 75 lines
- Remove duplicate 'deletes server when confirmation is provided' test
- Consolidate two display verification tests into single dataset-driven test
- Use Pest's ->with() pattern to test both custom and default SSH key scenarios
- Reduce redundancy by 41 lines while maintaining comprehensive coverage
Remove 'displays all server fields correctly' test as it duplicates
functionality already covered by 'lists single server with complete details'.
The existing test already verifies all server field display behavior.
@coderabbitai

coderabbitai Bot commented Oct 10, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Consolidates and removes several integration and unit tests around server console commands and repository loading. Adds a parameterized deletion-display test, merges add-command display and persistence into one test, removes a comprehensive list-display test, and drops a repository load-from-inventory test. No production code or public APIs changed.

Changes

Cohort / File(s) Summary
Server Add command tests
tests/Integration/Console/Server/ServerAddCommandTest.php
Removed separate confirmation/non-interactive and preview tests; added a single test that both displays complete server info and persists to inventory; updated sample inputs (name/host/port/key) and assertions; ensures SUCCESS exit.
Server Delete command tests
tests/Integration/Console/Server/ServerDeleteCommandTest.php
Replaced multiple granular display/confirmation tests with one data-driven test verifying server info before deletion via a provider (covering custom/default key paths). Retained non-interactive delete and general success/error tests; removed legacy display assertions.
Server List command tests
tests/Integration/Console/Server/ServerListCommandTest.php
Removed a single test asserting full-field rendering for a complete server; other list tests unchanged.
Server repository unit tests
tests/Unit/Repositories/ServerRepositoryTest.php
Removed “loads existing servers from inventory” test that asserted multiple servers loaded by name; no other repository tests changed.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant CLI as Console: server:add
  participant Inv as Inventory

  User->>CLI: Provide Name, Host, Port, User, Key
  CLI->>CLI: Display server details (preview)
  User-->>CLI: Confirm add
  CLI->>Inv: Save server entry
  Inv-->>CLI: Persisted
  CLI-->>User: Success message and exit SUCCESS
Loading
sequenceDiagram
  autonumber
  actor User
  participant CLI as Console: server:delete
  participant Inv as Inventory

  User->>CLI: --name=<server>
  CLI->>Inv: Find server by name
  Inv-->>CLI: ServerDTO
  CLI->>CLI: Display server info (pre-delete)
  alt Confirmed/Non-interactive
    CLI->>Inv: Delete server
    Inv-->>CLI: Deleted
    CLI-->>User: Success/exit code
  else Not confirmed
    CLI-->>User: Aborted/exit code
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

Possibly related PRs

  • bigpixelrocket/deployer-php#27 — Updates around server console command tests and shared display logic align with consolidated add/delete display flows here.
  • bigpixelrocket/deployer-php#33 — Touches ServerRepository test expectations similar to the removed load-from-inventory test.
  • bigpixelrocket/deployer-php#25 — Overlaps with repository loading and server command integration coverage adjusted in this PR.

Poem

I twitch my whiskers, tests align,
One hop combines the add-and-sign,
A carrot’s nod—delete in stride,
Arrays parade in data’s tide.
Old trails trimmed, the burrow neat—
Green buds bloom where asserts meet. 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately captures the primary change of removing redundant test cases across the test suite without introducing extraneous details, making it clear to any reviewer what the pull request does.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/remove-redundant-tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ebe602 and 27dbafb.

📒 Files selected for processing (4)
  • tests/Integration/Console/Server/ServerAddCommandTest.php (1 hunks)
  • tests/Integration/Console/Server/ServerDeleteCommandTest.php (1 hunks)
  • tests/Integration/Console/Server/ServerListCommandTest.php (0 hunks)
  • tests/Unit/Repositories/ServerRepositoryTest.php (0 hunks)
💤 Files with no reviewable changes (2)
  • tests/Unit/Repositories/ServerRepositoryTest.php
  • tests/Integration/Console/Server/ServerListCommandTest.php
🧰 Additional context used
📓 Path-based instructions (3)
**/*.php

📄 CodeRabbit inference engine (.cursor/rules/00-main.mdc)

**/*.php: Eliminate single-use private methods by inlining them directly
Cache expensive computed values by initializing them in the constructor instead of recomputing
Prefer direct property access over method calls when appropriate to avoid call overhead
Organize code into comment-separated sections; prefer alphabetical ordering when it does not conflict with logical grouping

**/*.php: Adhere to PSR-12 coding style in all PHP files
Declare strict_types=1 at the top of every PHP file
Prefer PHP 8.x features (union types, match, attributes, readonly) where appropriate
Always import classes with use statements; avoid fully qualified class names in code bodies
All methods must declare explicit return types; use proper generics in types/docblocks (e.g., Collection<int, User>)
Use dependency injection instead of manually resolving or instantiating classes
Prefer Symfony component classes (e.g., Filesystem, Process) over native PHP functions for testability
All object creation must use $container->build(ClassName::class) instead of new, except for value objects/DTOs/pure data structures
In production code, access the Container via constructor injection, not via static/global access
Add minimal DocBlock comments with descriptions, parameters, and return types for classes and functions
Use comments as visual separators for sections/subsections with a single newline between header, subheader, and paragraph; avoid obvious or stale comments
Run rector on changed PHP files before completing a task
Run pint on changed PHP files to fix code style before completing a task

Files:

  • tests/Integration/Console/Server/ServerDeleteCommandTest.php
  • tests/Integration/Console/Server/ServerAddCommandTest.php
{tests/**,test/**,**/*@(Test|Spec).php}

📄 CodeRabbit inference engine (.cursor/rules/00-main.mdc)

Do not run or edit tests unless explicitly instructed

Files:

  • tests/Integration/Console/Server/ServerDeleteCommandTest.php
  • tests/Integration/Console/Server/ServerAddCommandTest.php
tests/**/*.php

📄 CodeRabbit inference engine (.cursor/rules/01-architecture.mdc)

tests/**/*.php: In tests, direct Container instantiation and bind() for mocks is allowed and encouraged for isolation
Do not run PHPStan on test files; tests are excluded from static analysis

tests/**/*.php: Unit tests must instantiate services manually (no DI container)
Command/integration tests must use mockCommandContainer() for building commands and overriding services
Only use container auto-wiring in tests to verify DI configuration or multi-service integration (edge cases)
Keep test files under 1.8x the size of the source they test (without sacrificing readability)
Test core business logic; avoid testing the framework itself
Prefer dataset-driven testing using ->with([...]) for multiple scenarios
Consolidate related assertions (e.g., expect($x)->toBe(...)->and($y)->toBe(...))
Mock only external dependencies; keep unit tests isolated from filesystem/HTTP/processes
Avoid performance tests unless performance is the primary concern
Use the AAA pattern in tests (Arrange, Act, Assert; optional Cleanup)
In exception tests, use a combined // ACT & ASSERT step when the act triggers the assertion
Organize tests with describe() blocks, beforeEach() setup, and shared helpers/traits for DRY
Forbidden assertions in tests: type-only or generic checks (e.g., toBeInstanceOf, toBeArray, not->toBeNull, expect(true)->toBeTrue) and sleep(...); prefer time mocking
Preferred assertions: assert observable behavior and interactions (e.g., domain values, validator outcomes, mock expectations)
Unit tests: mock all external dependencies, test single units in isolation, and complete in milliseconds
Integration tests: use real file operations and external processes; cover CLI commands and full workflows
Do not require PHPStan compliance in tests; avoid excessive phpdoc solely to satisfy types in tests

Files:

  • tests/Integration/Console/Server/ServerDeleteCommandTest.php
  • tests/Integration/Console/Server/ServerAddCommandTest.php
🧬 Code graph analysis (2)
tests/Integration/Console/Server/ServerDeleteCommandTest.php (2)
app/DTOs/ServerDTO.php (1)
  • ServerDTO (7-17)
app/Console/Server/ServerDeleteCommand.php (1)
  • execute (41-132)
tests/Integration/Console/Server/ServerAddCommandTest.php (3)
tests/TestHelpers.php (1)
  • mockSSHServiceWithBehavior (228-231)
app/Contracts/BaseCommand.php (1)
  • execute (113-134)
app/Console/Server/ServerAddCommand.php (1)
  • execute (50-202)
🔇 Additional comments (1)
tests/Integration/Console/Server/ServerDeleteCommandTest.php (1)

130-154: Good consolidation with parameterized testing.

The data-driven approach effectively reduces duplication while maintaining coverage for both custom and default key path scenarios. The test structure follows best practices.

As per coding guidelines: "Prefer dataset-driven testing using ->with([...]) for multiple scenarios"

Comment on lines +260 to 293
it('displays complete server information and persists to inventory', function () {
// ARRANGE
$sshService = mockSSHServiceWithBehavior(true);
$tester = createServerAddCommandTester($sshService);

// ACT - Provide all required options
ob_start();
$tester->execute([
'--name' => 'display-test',
$exitCode = $tester->execute([
'--name' => 'complete-test',
'--host' => 'example.com',
'--port' => '22',
'--port' => '8022',
'--username' => 'deployer',
'--private-key-path' => '~/.ssh/key',
'--skip' => true,
'--yes' => true,
]);
ob_end_clean();

// ASSERT
// ASSERT - Verify display AND persistence
$output = $tester->getDisplay();
expect($output)->toContain('Name:')
->and($output)->toContain('display-test')
expect($exitCode)->toBe(Command::SUCCESS)
->and($output)->toContain('Name:')
->and($output)->toContain('complete-test')
->and($output)->toContain('Host:')
->and($output)->toContain('example.com')
->and($output)->toContain('Port:')
->and($output)->toContain('22')
->and($output)->toContain('8022')
->and($output)->toContain('User:')
->and($output)->toContain('deployer')
->and($output)->toContain('Key:')
->and($output)->toContain('~/.ssh/key');
});

it('shows default SSH key path when not provided', function () {
// ARRANGE
$sshService = mockSSHServiceWithBehavior(true);
$tester = createServerAddCommandTester($sshService);

// ACT - Provide all required options except private-key-path to test default
ob_start();
$tester->execute([
'--name' => 'default-key',
'--host' => '192.168.1.1',
'--port' => '22',
'--username' => 'root',
'--private-key-path' => '',
'--skip' => true,
'--yes' => true,
]);
ob_end_clean();

// ASSERT
$output = $tester->getDisplay();
expect($output)->toContain('Key:')
->and($output)->toContain('default')
->and($output)->toContain('~/.ssh/id_ed25519')
->and($output)->toContain('~/.ssh/id_rsa');
->and($output)->toContain('~/.ssh/key')
->and($output)->toContain('✓')
->and($output)->toContain('Server added successfully');
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Clarify indirect persistence verification in comment.

The test verifies persistence indirectly through the success exit code and message, which is appropriate for integration tests. However, the comment at line 278 says "Verify display AND persistence" without noting this is indirect verification.

Consider updating the comment to be more explicit:

-        // ASSERT - Verify display AND persistence
+        // ASSERT - Verify display and indirect persistence (via success indicators)

Also, note that the test uses a custom key path. Explicit verification of default key path display (when --private-key-path is empty) appears to have been removed, though it's still implicitly tested by the "adds server with minimal options using defaults" test at lines 61-87.

Run the following verification to confirm default key path display is still tested:


🏁 Script executed:

#!/bin/bash
# Description: Verify that default SSH key path display is tested

# Search for test assertions checking default key path output
rg -nP --type=php -A5 -B5 'id_ed25519|id_rsa' tests/Integration/Console/Server/ServerAddCommandTest.php

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Search for any default SSH key path references in the test
rg -n "~/.ssh" -C3 tests/Integration/Console/Server/ServerAddCommandTest.php

Length of output: 867


🏁 Script executed:

#!/bin/bash
# Locate minimal-options test to verify default key-path assertion
rg -n --type=php "minimal options" -C5 tests/Integration/Console/Server/ServerAddCommandTest.php

Length of output: 479


Clarify indirect persistence verification.

  • Update the assertion comment at line 278:
-        // ASSERT - Verify display AND persistence
+        // ASSERT - Verify display and indirect persistence (via exit code + message)
  • Optional: In the “adds server with minimal options using defaults” test (lines 61–87), add an assertion for the default SSH key path (e.g., ~/.ssh/id_rsa).
🤖 Prompt for AI Agents
In tests/Integration/Console/Server/ServerAddCommandTest.php around lines 260 to
293 (specifically update the assertion comment at line 278), clarify that the
test verifies display output and indirectly confirms persistence to inventory by
checking the success message and output strings; replace the vague comment "//
ASSERT - Verify display AND persistence" with a clearer one like "// ASSERT -
Verify display output and that command indicates server was persisted (success
message used as indirect persistence check)". Also optionally add an assertion
in the "adds server with minimal options using defaults" test (lines 61–87) to
assert the default SSH key path (e.g., expect output or stored value toContain
'~/.ssh/id_rsa') so the default key behavior is explicitly tested.

@loadinglucian
loadinglucian merged commit 6deaf3a into main Oct 10, 2025
5 checks passed
@loadinglucian
loadinglucian deleted the test/remove-redundant-tests branch October 10, 2025 11:53
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