php-agentic/tests/Pest.php
Snider e70e078bcb refactor(tests): convert AgentApiKey tests to Pest functional syntax
- Convert AgentApiKeyTest from PHPUnit class-based syntax to Pest functional syntax
- Add tests/Pest.php configuration with helper functions (createWorkspace, createApiKey)
- Organise tests using describe() blocks for better structure
- Add additional test coverage for key rotation and security edge cases
- Update TODO.md to reflect Pest syntax usage

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 18:42:56 +00:00

74 lines
2 KiB
PHP

<?php
declare(strict_types=1);
/*
|--------------------------------------------------------------------------
| Pest Configuration
|--------------------------------------------------------------------------
|
| Configure Pest testing framework for the core-agentic package.
| This file binds test traits to test cases and provides helper functions.
|
*/
use Core\Mod\Agentic\Models\AgentApiKey;
use Core\Tenant\Models\Workspace;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure passed to the "uses()" method binds an abstract test case
| to all Feature and Unit tests. The TestCase class provides a bridge
| between Laravel's testing utilities and Pest's expressive syntax.
|
*/
uses(TestCase::class)->in('Feature', 'Unit', 'UseCase');
/*
|--------------------------------------------------------------------------
| Database Refresh
|--------------------------------------------------------------------------
|
| Apply RefreshDatabase to Feature tests that need a clean database state.
| Unit tests typically don't require database access.
|
*/
uses(RefreshDatabase::class)->in('Feature');
/*
|--------------------------------------------------------------------------
| Helper Functions
|--------------------------------------------------------------------------
|
| Custom helper functions for agent-related tests.
|
*/
/**
* Create a workspace for testing.
*/
function createWorkspace(array $attributes = []): Workspace
{
return Workspace::factory()->create($attributes);
}
/**
* Create an API key for testing.
*/
function createApiKey(
Workspace|int|null $workspace = null,
string $name = 'Test Key',
array $permissions = [],
int $rateLimit = 100
): AgentApiKey {
$workspace ??= createWorkspace();
return AgentApiKey::generate($workspace, $name, $permissions, $rateLimit);
}