API Services AssertionService - evansims/openfga-php GitHub Wiki
Service implementation for managing OpenFGA authorization model assertions. Provides business-focused operations for working with assertions, which are test cases that validate the behavior of authorization models. This service abstracts the underlying repository implementation and adds value through validation, convenience methods, and enhanced error handling.
Table of Contents
OpenFGA\Services
- AssertionServiceInterface (interface)
public function clearAssertions(
string $authorizationModelId,
): OpenFGA\Results\FailureInterface|OpenFGA\Results\SuccessInterface
Clear all assertions from an authorization model. Removes all test assertions from the specified authorization model. This is useful when completely restructuring test cases or during development iterations.
Name | Type | Description |
---|---|---|
$authorizationModelId |
string |
The authorization model to clear |
FailureInterface
| SuccessInterface
— Success if cleared, or Failure with error details
public function executeAssertions(
string $authorizationModelId,
OpenFGA\Models\Collections\AssertionsInterface $assertions,
): OpenFGA\Results\Failure|OpenFGA\Results\Success|OpenFGA\Results\SuccessInterface
Execute assertions against the authorization model. Runs the specified assertions and returns the results, comparing expected outcomes with actual authorization check results. This helps verify that your authorization model works correctly.
Name | Type | Description |
---|---|---|
$authorizationModelId |
string |
The authorization model to test |
$assertions |
AssertionsInterface |
The assertions to execute |
Failure
| Success
| SuccessInterface
— Success with test results, or Failure with execution errors
public function getAssertionStatistics(
OpenFGA\Models\StoreInterface|string $store,
string $authorizationModelId,
): OpenFGA\Results\FailureInterface|OpenFGA\Results\SuccessInterface
Get assertion execution statistics. Provides insights into assertion test results, including pass/fail counts, execution times, and common failure patterns. Useful for monitoring authorization model health and test coverage.
Name | Type | Description |
---|---|---|
$store |
StoreInterface | string
|
The store to analyze |
$authorizationModelId |
string |
The authorization model to analyze |
FailureInterface
| SuccessInterface
— Success with statistics, or Failure with error details
public function readAssertions(
string $authorizationModelId,
): OpenFGA\Results\FailureInterface|OpenFGA\Results\SuccessInterface
Read assertions from an authorization model. Retrieves all test assertions defined in the specified authorization model. Assertions validate that the model behaves correctly for specific scenarios.
Name | Type | Description |
---|---|---|
$authorizationModelId |
string |
The authorization model ID containing assertions |
FailureInterface
| SuccessInterface
— Success with assertions collection, or Failure with error details
public function validateAssertions(
OpenFGA\Models\Collections\AssertionsInterface $assertions,
string $authorizationModelId,
): OpenFGA\Results\Failure|OpenFGA\Results\Success|OpenFGA\Results\SuccessInterface
Validate assertion syntax and logic. Checks that assertions are properly formatted and reference valid types and relations from the authorization model. This helps catch errors before deploying assertions to production.
Name | Type | Description |
---|---|---|
$assertions |
AssertionsInterface |
The assertions to validate |
$authorizationModelId |
string |
The authorization model to validate against |
Failure
| Success
| SuccessInterface
— Success if valid, or Failure with validation errors
public function writeAssertions(
string $authorizationModelId,
OpenFGA\Models\Collections\AssertionsInterface $assertions,
): OpenFGA\Results\FailureInterface|OpenFGA\Results\SuccessInterface
Write assertions to an authorization model. Updates the test assertions for the specified authorization model. Assertions help validate that your authorization model works as expected by defining specific test cases and their expected outcomes.
Name | Type | Description |
---|---|---|
$authorizationModelId |
string |
The authorization model ID to update |
$assertions |
AssertionsInterface |
The assertions to write |
FailureInterface
| SuccessInterface
— Success if written, or Failure with error details