Skip to content
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

Adding the ability to use setUp and tearDown methods in traits #62

Merged
merged 2 commits into from
Oct 3, 2023

Conversation

msmakouz
Copy link
Member

@msmakouz msmakouz commented Sep 28, 2023

Feature

This pull request introduces a new feature to enhance testing capabilities. It enables the usage of setUpTraitName and tearDownTraitName methods in traits, which will be automatically invoked within the setUp and tearDown methods before and after test execution, respectively. Instead of TraitName, the specific trait name should be provided.

Example

Trait

trait ShowQueries
{
    protected function setUpShowQueries(): void
    {
        $this->configureLogger();
    }

    protected function tearDownShowQueries(): void
    {
        $this->restoreLogger();
    }

    private function configureLogger(): void
    {
        // ...
    }

    private function restoreLogger(): void
    {
        // ... 
    }
}

TestCase

use Spiral\Testing\TestCase;

final class SomeTest extends TestCase
{
    use ShowQueries;
}

@msmakouz msmakouz marked this pull request as draft September 28, 2023 10:30
@msmakouz msmakouz self-assigned this Sep 28, 2023
@msmakouz msmakouz added the enhancement New feature or request label Sep 28, 2023
@msmakouz msmakouz added this to the 2.x milestone Sep 28, 2023
@butschster butschster linked an issue Sep 28, 2023 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Sep 28, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (c217343) 40.79% compared to head (50e36bf) 42.38%.

Additional details and impacted files
@@             Coverage Diff              @@
##                2.x      #62      +/-   ##
============================================
+ Coverage     40.79%   42.38%   +1.59%     
- Complexity      310      318       +8     
============================================
  Files            33       33              
  Lines           956      972      +16     
============================================
+ Hits            390      412      +22     
+ Misses          566      560       -6     
Files Coverage Δ
src/TestCase.php 90.90% <100.00%> (+12.22%) ⬆️

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

@msmakouz msmakouz requested a review from butschster September 28, 2023 11:35
@msmakouz msmakouz marked this pull request as ready for review September 28, 2023 11:35
@butschster butschster merged commit 333f209 into 2.x Oct 3, 2023
4 of 6 checks passed
@butschster butschster deleted the feature/setup-traits branch October 3, 2023 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add hooks for traits
2 participants