Skip to content

Commit

Permalink
Add the ability to use array of scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
msmakouz committed Feb 17, 2024
1 parent 500759f commit fdf9904
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Attribute/TestScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
final class TestScope
{
public function __construct(

Check warning on line 12 in src/Attribute/TestScope.php

View check run for this annotation

Codecov / codecov/patch

src/Attribute/TestScope.php#L12

Added line #L12 was not covered by tests
public readonly string|\BackedEnum $scope,
public readonly string|\BackedEnum|array $scope,
public readonly array $bindings = [],
) {
}
Expand Down
28 changes: 21 additions & 7 deletions src/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,12 @@ protected function runTest(): mixed

$previousApp = $this->getApp();

Check warning on line 236 in src/TestCase.php

View check run for this annotation

Codecov / codecov/patch

src/TestCase.php#L236

Added line #L236 was not covered by tests

$result = $this->getApp()->getContainer()->runScope(
new Scope($scope->scope, $scope->bindings),
function (Container $container): mixed {
$this->initApp([...static::ENV, ...$this->getEnvVariablesFromConfig()], $container);
$scopes = \is_array($scope->scope) ? $scope->scope : [$scope->scope];
$result = $this->runScopes($scopes, function (Container $container): mixed {
$this->initApp([...static::ENV, ...$this->getEnvVariablesFromConfig()], $container);

Check warning on line 240 in src/TestCase.php

View check run for this annotation

Codecov / codecov/patch

src/TestCase.php#L238-L240

Added lines #L238 - L240 were not covered by tests

return parent::runTest();
},
);
return parent::runTest();
}, $this->getContainer(), $scope->bindings);

Check warning on line 243 in src/TestCase.php

View check run for this annotation

Codecov / codecov/patch

src/TestCase.php#L242-L243

Added lines #L242 - L243 were not covered by tests

$this->app = $previousApp;

Check warning on line 245 in src/TestCase.php

View check run for this annotation

Codecov / codecov/patch

src/TestCase.php#L245

Added line #L245 was not covered by tests

Expand Down Expand Up @@ -287,4 +285,20 @@ private function getTestScope(): ?TestScope

return null;
}

private function runScopes(array $scopes, Closure $callback, Container $container, array $bindings): mixed

Check warning on line 289 in src/TestCase.php

View check run for this annotation

Codecov / codecov/patch

src/TestCase.php#L289

Added line #L289 was not covered by tests
{
if ($scopes === []) {
return $container->runScope($bindings, $callback);

Check warning on line 292 in src/TestCase.php

View check run for this annotation

Codecov / codecov/patch

src/TestCase.php#L291-L292

Added lines #L291 - L292 were not covered by tests
}

$scope = \array_shift($scopes);

Check warning on line 295 in src/TestCase.php

View check run for this annotation

Codecov / codecov/patch

src/TestCase.php#L295

Added line #L295 was not covered by tests

return $container->runScope(
new Scope($scope, []),
function (Container $container) use ($scopes, $callback, $bindings): mixed {
return $this->runScopes($scopes, $callback, $container, $bindings);
},

Check warning on line 301 in src/TestCase.php

View check run for this annotation

Codecov / codecov/patch

src/TestCase.php#L297-L301

Added lines #L297 - L301 were not covered by tests
);
}
}

0 comments on commit fdf9904

Please sign in to comment.