Skip to content

Conversation

@huangdijia
Copy link
Member

Summary

  • Added NonCoroutine attribute to provide fine-grained control over coroutine execution in tests
  • Refactored RunTestsInCoroutine trait to use reflection-based attribute detection
  • Removed the hardcoded $enableCoroutine property in favor of a more flexible approach
  • Added isCoroutineEnabled() method that checks both class-level and method-level attributes

Changes

  1. New NonCoroutine Attribute: Created Hyperf\Testing\Attributes\NonCoroutine attribute that can be applied to test classes or methods to disable coroutine execution
  2. Refactored RunTestsInCoroutine Trait:
    • Removed protected bool $enableCoroutine = true; property
    • Added isCoroutineEnabled() method using reflection to check for NonCoroutine attributes
    • Improved code organization and maintainability
  3. Added Tests: Created RunTestsInCoroutineTest to verify the functionality

Benefits

  • More flexible and declarative way to control coroutine execution
  • Allows per-test or per-class control using PHP 8 attributes
  • Better code maintainability and readability
  • Follows modern PHP practices

Test Plan

  • Added unit tests for the new functionality
  • Verified that tests with NonCoroutine attribute run without coroutines
  • Verified that tests without the attribute continue to run in coroutines
  • Tested both class-level and method-level attribute application

…tion control

- Added NonCoroutine attribute to disable coroutine execution for specific tests
- Refactored RunTestsInCoroutine trait to use attribute-based detection
- Removed hardcoded $enableCoroutine property in favor of reflection-based approach
- Added isCoroutineEnabled() method to check class and method attributes
- Improved code maintainability and flexibility for test execution control
@huangdijia huangdijia added this to the v3.2 milestone Nov 8, 2025
@limingxinleo limingxinleo merged commit d9a640d into hyperf:3.2 Nov 8, 2025
76 checks passed
@huangdijia huangdijia deleted the refactor/testing-noncoroutine-attribute branch November 8, 2025 03:26
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.

2 participants