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

PHP Attributes for Environment and Configuration Variables, and Exception Handling #55

Merged
merged 2 commits into from
Jun 7, 2023

Conversation

butschster
Copy link
Member

This pull request introduces several new features to the testing package, enhancing its capabilities for unit testing. The following features have been added:

1. Redefining Environment (ENV) Variables

You can now redefine specific ENV variables for unit tests using PHP attributes. This allows for more granular control over the test environment.

use Spiral\Testing\Attribute\Env;

#[Env('FOO', 'BAZ')]
#[Env('BAZ', 'BAZ')]
public function testMultipleAttributes(): void
{
    // Test logic here
}

2. Configuring spiral config variables

Configuration variables can now be modified using attributes in unit tests.

use Spiral\Testing\Attribute\Config;

#[Config('storage.default', 'replaced')]
#[Config('storage.servers.static.adapter', 'test')]
public function testMultipleAttributes(): void
{
    // Test logic here
}

3. Disabling Exception Handler

#[WithoutExceptionHandling]
public function testSuppressWithAttribute(): void
{
    // Test logic here
}

@butschster butschster added the enhancement New feature or request label May 29, 2023
@butschster butschster requested review from roxblnfk and msmakouz May 29, 2023 10:30
@butschster butschster self-assigned this May 29, 2023
@codecov
Copy link

codecov bot commented May 29, 2023

Codecov Report

Patch coverage: 93.33% and project coverage change: +2.94 🎉

Comparison is base (8e571fb) 37.20% compared to head (0df8bd1) 40.14%.

Additional details and impacted files
@@             Coverage Diff              @@
##                2.x      #55      +/-   ##
============================================
+ Coverage     37.20%   40.14%   +2.94%     
- Complexity      297      310      +13     
============================================
  Files            32       34       +2     
  Lines          1051     1076      +25     
============================================
+ Hits            391      432      +41     
+ Misses          660      644      -16     
Impacted Files Coverage Δ
src/TestCase.php 80.30% <87.50%> (+0.67%) ⬆️
src/Attribute/Config.php 100.00% <100.00%> (ø)
src/Attribute/Env.php 100.00% <100.00%> (ø)
src/Traits/InteractsWithConfig.php 47.61% <100.00%> (+47.61%) ⬆️
src/Traits/InteractsWithCore.php 63.29% <100.00%> (+10.58%) ⬆️
src/Traits/InteractsWithExceptions.php 63.63% <100.00%> (+63.63%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@butschster butschster merged commit fa72faa into 2.x Jun 7, 2023
@butschster butschster deleted the feature/config-attribute branch June 7, 2023 11:35
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
None yet
Development

Successfully merging this pull request may close these issues.

1 participant