Skip to content

refactor: Raise code coverage 100%. #11

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

Merged
merged 1 commit into from
Jun 28, 2025
Merged

refactor: Raise code coverage 100%. #11

merged 1 commit into from
Jun 28, 2025

Conversation

terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Jun 28, 2025

Q A
Is bugfix? ✔️
New feature?
Breaks BC?

Summary by CodeRabbit

  • Tests
    • Added new tests to verify deletion and root creation behaviors, including handling of transactions, exceptions, and missing primary keys.
    • Improved type annotations and class structure in test support models to facilitate subclassing and enhance type safety.
    • Added explicit constructors to query classes for better type handling and extensibility.

@terabytesoftw terabytesoftw added the bug Something isn't working label Jun 28, 2025
Copy link

codecov bot commented Jun 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (cdce23b) to head (7b37d58).
Report is 1 commits behind head on main.

Additional details and impacted files
@@              Coverage Diff              @@
##               main       #11      +/-   ##
=============================================
+ Coverage     97.59%   100.00%   +2.40%     
  Complexity       82        82              
=============================================
  Files             2         2              
  Lines           457       457              
=============================================
+ Hits            446       457      +11     
+ Misses           11         0      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

coderabbitai bot commented Jun 28, 2025

Walkthrough

This update introduces new test cases to the NestedSetsBehaviorTest class, expands the extensibility of Tree and MultipleTree model classes, and enhances type safety and late static binding in their query methods. Constructors are added to query classes for explicit model class configuration, and transactional behavior is customized for deletion operations.

Changes

File(s) Change Summary
tests/NestedSetsBehaviorTest.php Added four new test methods for deleteWithChildren() and makeRoot() behaviors; refactored imports.
tests/support/model/Tree.php Made class non-final, added isTransactional() override, improved find() for late static binding and typing.
tests/support/model/MultipleTree.php Made class non-final, updated PHPStan return type and find() for late static binding and typing.
tests/support/model/TreeQuery.php,
tests/support/model/MultipleTreeQuery.php
Added constructors with explicit model class and config parameters, improved type annotations.

Sequence Diagram(s)

sequenceDiagram
    participant Test as NestedSetsBehaviorTest
    participant Model as Tree/MultipleTree
    participant Query as TreeQuery/MultipleTreeQuery
    participant DB as Database

    Test->>Model: call deleteWithChildren()
    Model->>DB: begin transaction (if transactional)
    Model->>Model: beforeDelete()
    alt beforeDelete returns false
        Model-->>Test: return false
    else beforeDelete passes
        Model->>DB: delete node and children
        Model->>DB: update tree structure
        Model-->>Test: return affected rows
    end
    Note over Test,Model: If exception during delete, propagate exception
Loading

Possibly related PRs

  • #5: Refactored and improved NestedSetsBehavior, including deleteWithChildren() and makeRoot() methods, which are directly targeted by the new tests in this PR.
  • #7: Enhanced and refactored the same test class, focusing on test structure and naming; related through shared test coverage but not overlapping specific new tests.

Poem

In the code’s deep forest, roots entwine,
New tests now check each branch and line.
Trees can grow or fall with grace,
Queries know their proper place.
With every node and child in view,
The garden thrives—thanks to you!
🐇🌲

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 phpcs (3.7.2)
tests/NestedSetsBehaviorTest.php

Warning: PHP Startup: Invalid date.timezone value 'UTC', using 'UTC' instead in Unknown on line 0

Fatal error: Uncaught Error: Class "Phar" not found in /usr/local/bin/phpcs:3
Stack trace:
#0 {main}
thrown in /usr/local/bin/phpcs on line 3

tests/support/model/MultipleTree.php

Warning: PHP Startup: Invalid date.timezone value 'UTC', using 'UTC' instead in Unknown on line 0

Fatal error: Uncaught Error: Class "Phar" not found in /usr/local/bin/phpcs:3
Stack trace:
#0 {main}
thrown in /usr/local/bin/phpcs on line 3

tests/support/model/MultipleTreeQuery.php

Warning: PHP Startup: Invalid date.timezone value 'UTC', using 'UTC' instead in Unknown on line 0

Fatal error: Uncaught Error: Class "Phar" not found in /usr/local/bin/phpcs:3
Stack trace:
#0 {main}
thrown in /usr/local/bin/phpcs on line 3

  • 2 others

📜 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 cdce23b and 7b37d58.

📒 Files selected for processing (5)
  • tests/NestedSetsBehaviorTest.php (2 hunks)
  • tests/support/model/MultipleTree.php (2 hunks)
  • tests/support/model/MultipleTreeQuery.php (1 hunks)
  • tests/support/model/Tree.php (3 hunks)
  • tests/support/model/TreeQuery.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
tests/support/model/TreeQuery.php (1)
tests/support/model/MultipleTreeQuery.php (1)
  • __construct (21-24)
tests/support/model/MultipleTreeQuery.php (1)
tests/support/model/TreeQuery.php (1)
  • __construct (21-24)
tests/support/model/Tree.php (1)
tests/support/model/TreeQuery.php (1)
  • TreeQuery (15-32)
tests/support/model/MultipleTree.php (2)
tests/support/model/Tree.php (1)
  • find (60-63)
tests/support/model/MultipleTreeQuery.php (1)
  • MultipleTreeQuery (15-32)
🪛 PHPMD (2.15.0)
tests/NestedSetsBehaviorTest.php

1473-1473: Avoid using static access to class '\yii2\extensions\nestedsets\tests\support\model\Tree' in method 'testReturnAffectedRowsAndUpdateTreeAfterDeleteWithChildrenWhenManualTransactionIsUsed'. (Clean Code Rules)

(StaticAccess)


1517-1517: Avoid using static access to class '\yii2\extensions\nestedsets\tests\support\model\Tree' in method 'testReturnAffectedRowsAndUpdateTreeAfterDeleteWithChildrenWhenManualTransactionIsUsed'. (Clean Code Rules)

(StaticAccess)


1521-1521: Avoid using static access to class '\yii2\extensions\nestedsets\tests\support\model\Tree' in method 'testReturnAffectedRowsAndUpdateTreeAfterDeleteWithChildrenWhenManualTransactionIsUsed'. (Clean Code Rules)

(StaticAccess)


1525-1525: Avoid using static access to class '\yii2\extensions\nestedsets\tests\support\model\Tree' in method 'testReturnAffectedRowsAndUpdateTreeAfterDeleteWithChildrenWhenManualTransactionIsUsed'. (Clean Code Rules)

(StaticAccess)


1529-1529: Avoid using static access to class '\yii2\extensions\nestedsets\tests\support\model\Tree' in method 'testReturnAffectedRowsAndUpdateTreeAfterDeleteWithChildrenWhenManualTransactionIsUsed'. (Clean Code Rules)

(StaticAccess)

⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: phpunit-compatibility / PHP 8.3-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.4-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.1-ubuntu-latest
  • GitHub Check: phpunit-compatibility / PHP 8.2-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.2-ubuntu-latest
  • GitHub Check: phpunit-compatibility / PHP 8.1-windows-latest
  • GitHub Check: phpunit / PHP 8.2-windows-latest
  • GitHub Check: phpunit / PHP 8.1-windows-latest
  • GitHub Check: phpunit / PHP 8.3-windows-latest
🔇 Additional comments (13)
tests/support/model/TreeQuery.php (1)

17-24: Well-structured constructor with proper type annotations.

The explicit constructor with PHPStan generics enhances type safety and supports the late static binding pattern used in the Tree::find() method. The implementation correctly delegates to the parent constructor.

tests/support/model/MultipleTreeQuery.php (1)

17-24: Consistent constructor implementation.

The constructor maintains consistency with TreeQuery while correctly using the MultipleTree template type. This supports the late static binding pattern and improves type safety.

tests/support/model/Tree.php (3)

17-17: Correctly enables inheritance for extensibility.

Removing the final modifier allows the class to be subclassed, which supports the testing patterns and enhances reusability.


31-38: Proper transaction control for delete operations.

The isTransactional() override correctly disables transactions for delete operations while preserving default behavior for other operations. This aligns with the test expectations and provides appropriate control over transactional behavior.


58-62: Excellent implementation of late static binding.

The updates to both the PHPStan annotation (TreeQuery<static>) and the instantiation (static::class) ensure that subclasses will receive properly typed query objects. This is a best practice for inheritance hierarchies.

tests/support/model/MultipleTree.php (2)

18-18: Consistent inheritance enablement.

Removing the final modifier aligns with the Tree class changes and enables proper extensibility patterns.


53-57: Proper late static binding implementation.

The PHPStan annotation and instantiation updates ensure correct type handling for inheritance, maintaining consistency with the Tree class implementation.

tests/NestedSetsBehaviorTest.php (6)

10-10: Good use of grouped imports.

The grouped import syntax for yii\db classes improves readability and maintainability.


15-16: Appropriate global function imports.

Explicitly importing get_class and sprintf improves code clarity and is used properly in the new test method for exception message formatting.


1469-1532: Comprehensive test for manual transaction behavior.

This test properly verifies that:

  • The node correctly reports non-transactional delete behavior
  • The correct number of nodes are deleted
  • Tree structure is properly updated
  • Specific nodes are removed while preserving others

The test logic is sound and provides good coverage for the manual transaction scenario.


1534-1567: Effective test for beforeDelete abortion scenario.

The test uses proper mocking to simulate beforeDelete() returning false and verifies that:

  • deleteWithChildren() returns false when aborted
  • The method correctly handles the abortion scenario
  • Transactional behavior is properly checked

Good use of PHPUnit mocking capabilities.


1569-1600: Proper exception handling test.

The test correctly:

  • Detaches and mocks the behavior to simulate exceptions
  • Verifies exception propagation
  • Uses appropriate exception testing patterns

The mock setup and expectation handling are implemented correctly.


1602-1622: Well-designed test for primary key validation.

The test uses an anonymous class to override primaryKey() and return an empty array, properly simulating the edge case. The exception message verification using sprintf() and get_class() ensures accurate error reporting.

✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

@terabytesoftw terabytesoftw requested a review from Copilot June 28, 2025 17:56
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors test support models for improved type safety and extends test coverage to cover deletion and root-creation edge cases.

  • Added explicit constructors to TreeQuery and MultipleTreeQuery for PHPStan generics support
  • Made Tree and MultipleTree non-final, updated find() to use static::class, and added isTransactional() override
  • Introduced new tests in NestedSetsBehaviorTest to verify delete-with-children behavior under manual transactions, exceptions, and missing primary keys

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/support/model/TreeQuery.php Added __construct with PHPStan param annotations
tests/support/model/Tree.php Removed final, added isTransactional(), updated find()
tests/support/model/MultipleTreeQuery.php Added __construct with PHPStan param annotations
tests/support/model/MultipleTree.php Removed final, updated find()
tests/NestedSetsBehaviorTest.php Added tests for deletion with children, exception handling, root creation without PK
Comments suppressed due to low confidence (2)

tests/support/model/TreeQuery.php:17

  • Add a class-level @template T of ActiveRecord docblock above the class declaration so PHPStan can correctly resolve the generic T used in the method annotations.
    /**

tests/support/model/MultipleTreeQuery.php:17

  • Add a class-level @template T of ActiveRecord docblock above the class declaration so PHPStan can correctly resolve the generic T used in the method annotations.
    /**

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy