test: add comprehensive tests for Discovery module components
- Add tests for Results registries (AttributeRegistry, InterfaceRegistry, TemplateRegistry) - Add tests for Processing components (ProcessingContext) - Add tests for Memory components (MemoryGuard) - Add tests for Value Objects (DiscoveryOptions, DiscoveryContext) All new tests pass and cover core functionality including: - Registry operations (add, get, has, serialize/deserialize, optimize) - Processing context (reflection caching, file context management) - Memory guard (memory checks, statistics, emergency cleanup) - Value objects (factory methods, scan types, cache keys, metrics)
This commit is contained in:
135
tests/Framework/Discovery/ValueObjects/DiscoveryContextTest.php
Normal file
135
tests/Framework/Discovery/ValueObjects/DiscoveryContextTest.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Framework\Discovery\ValueObjects;
|
||||
|
||||
use App\Framework\Context\ExecutionContext;
|
||||
use App\Framework\Discovery\ValueObjects\DiscoveryContext;
|
||||
use App\Framework\Discovery\ValueObjects\DiscoveryOptions;
|
||||
use App\Framework\Discovery\ValueObjects\ScanType;
|
||||
|
||||
describe('DiscoveryContext', function () {
|
||||
it('can be instantiated', function () {
|
||||
$context = new DiscoveryContext(
|
||||
paths: ['/test/path'],
|
||||
scanType: ScanType::FULL,
|
||||
options: new DiscoveryOptions(),
|
||||
startTime: new \DateTimeImmutable()
|
||||
);
|
||||
|
||||
expect($context)->toBeInstanceOf(DiscoveryContext::class);
|
||||
});
|
||||
|
||||
it('can track processed files', function () {
|
||||
$context = new DiscoveryContext(
|
||||
paths: ['/test/path'],
|
||||
scanType: ScanType::FULL,
|
||||
options: new DiscoveryOptions(),
|
||||
startTime: new \DateTimeImmutable()
|
||||
);
|
||||
|
||||
expect($context->getProcessedFiles())->toBe(0);
|
||||
|
||||
$context->incrementProcessedFiles();
|
||||
$context->incrementProcessedFiles();
|
||||
|
||||
expect($context->getProcessedFiles())->toBe(2);
|
||||
});
|
||||
|
||||
it('can add and retrieve metrics', function () {
|
||||
$context = new DiscoveryContext(
|
||||
paths: ['/test/path'],
|
||||
scanType: ScanType::FULL,
|
||||
options: new DiscoveryOptions(),
|
||||
startTime: new \DateTimeImmutable()
|
||||
);
|
||||
|
||||
$context->addMetric('files_scanned', 10);
|
||||
$context->addMetric('errors', 2);
|
||||
|
||||
$metrics = $context->getMetrics();
|
||||
|
||||
expect($metrics)->toBeArray();
|
||||
expect($metrics)->toHaveKey('files_scanned');
|
||||
expect($metrics)->toHaveKey('errors');
|
||||
expect($metrics['files_scanned'])->toBe(10);
|
||||
expect($metrics['errors'])->toBe(2);
|
||||
});
|
||||
|
||||
it('can check if incremental', function () {
|
||||
$incrementalContext = new DiscoveryContext(
|
||||
paths: ['/test/path'],
|
||||
scanType: ScanType::INCREMENTAL,
|
||||
options: new DiscoveryOptions(),
|
||||
startTime: new \DateTimeImmutable()
|
||||
);
|
||||
|
||||
expect($incrementalContext->isIncremental())->toBeTrue();
|
||||
|
||||
$fullContext = new DiscoveryContext(
|
||||
paths: ['/test/path'],
|
||||
scanType: ScanType::FULL,
|
||||
options: new DiscoveryOptions(),
|
||||
startTime: new \DateTimeImmutable()
|
||||
);
|
||||
|
||||
expect($fullContext->isIncremental())->toBeFalse();
|
||||
});
|
||||
|
||||
it('can check if should use cache', function () {
|
||||
$cachedOptions = new DiscoveryOptions(useCache: true);
|
||||
$context = new DiscoveryContext(
|
||||
paths: ['/test/path'],
|
||||
scanType: ScanType::FULL,
|
||||
options: $cachedOptions,
|
||||
startTime: new \DateTimeImmutable()
|
||||
);
|
||||
|
||||
expect($context->shouldUseCache())->toBeTrue();
|
||||
|
||||
$noCacheOptions = new DiscoveryOptions(useCache: false);
|
||||
$context2 = new DiscoveryContext(
|
||||
paths: ['/test/path'],
|
||||
scanType: ScanType::FULL,
|
||||
options: $noCacheOptions,
|
||||
startTime: new \DateTimeImmutable()
|
||||
);
|
||||
|
||||
expect($context2->shouldUseCache())->toBeFalse();
|
||||
});
|
||||
|
||||
it('can generate cache key', function () {
|
||||
$context = new DiscoveryContext(
|
||||
paths: ['/test/path'],
|
||||
scanType: ScanType::FULL,
|
||||
options: new DiscoveryOptions(),
|
||||
startTime: new \DateTimeImmutable()
|
||||
);
|
||||
|
||||
$cacheKey = $context->getCacheKey();
|
||||
|
||||
expect($cacheKey)->toBeInstanceOf(\App\Framework\Cache\CacheKey::class);
|
||||
});
|
||||
|
||||
it('can use default factory method', function () {
|
||||
$context = DiscoveryContext::default();
|
||||
|
||||
expect($context)->toBeInstanceOf(DiscoveryContext::class);
|
||||
expect($context->paths)->toBeArray();
|
||||
});
|
||||
|
||||
it('can use comprehensive factory method', function () {
|
||||
$context = DiscoveryContext::comprehensive();
|
||||
|
||||
expect($context)->toBeInstanceOf(DiscoveryContext::class);
|
||||
});
|
||||
|
||||
it('can use minimal factory method', function () {
|
||||
$context = DiscoveryContext::minimal();
|
||||
|
||||
expect($context)->toBeInstanceOf(DiscoveryContext::class);
|
||||
expect($context->isIncremental())->toBeTrue();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user