reflectionProvider = new CachedReflectionProvider(); $this->context = new ProcessingContext($this->reflectionProvider); }); it('can be instantiated', function () { expect($this->context)->toBeInstanceOf(ProcessingContext::class); }); it('can set current file context', function () { $file = File::fromPath(FilePath::create('/test/file.php')); $fileContext = FileContext::fromFile($file); $this->context->setCurrentFile($fileContext); $current = $this->context->getCurrentFileContext(); expect($current)->toBeInstanceOf(FileContext::class); expect($current)->toBe($fileContext); }); it('can get reflection for a class', function () { $className = ClassName::create('stdClass'); $reflection = $this->context->getReflection($className); // stdClass should be reflectable expect($reflection)->not->toBeNull(); }); it('returns null for non-existent class', function () { $className = ClassName::create('NonExistent\\Class\\That\\Does\\Not\\Exist'); $reflection = $this->context->getReflection($className); expect($reflection)->toBeNull(); }); it('caches reflection for the same class', function () { $className = ClassName::create('stdClass'); $reflection1 = $this->context->getReflection($className); $reflection2 = $this->context->getReflection($className); // Should return the same instance (cached) expect($reflection1)->toBe($reflection2); }); it('clears reflection cache when switching files', function () { $file1 = File::fromPath(FilePath::create('/test/file1.php')); $fileContext1 = FileContext::fromFile($file1); $this->context->setCurrentFile($fileContext1); $className = ClassName::create('stdClass'); $reflection1 = $this->context->getReflection($className); // Switch to different file $file2 = File::fromPath(FilePath::create('/test/file2.php')); $fileContext2 = FileContext::fromFile($file2); $this->context->setCurrentFile($fileContext2); // Reflection should be cleared $reflection2 = $this->context->getReflection($className); // Should still work, but might be a new instance expect($reflection2)->not->toBeNull(); }); it('can cleanup resources', function () { $file = File::fromPath(FilePath::create('/test/file.php')); $fileContext = FileContext::fromFile($file); $this->context->setCurrentFile($fileContext); $className = ClassName::create('stdClass'); $this->context->getReflection($className); $this->context->cleanup(); // After cleanup, current file context should be null $current = $this->context->getCurrentFileContext(); expect($current)->toBeNull(); }); it('handles reflection errors gracefully', function () { // Use a class that might cause reflection errors $className = ClassName::create('NonExistent\\Class\\With\\Parse\\Error'); $reflection = $this->context->getReflection($className); // Should return null instead of throwing expect($reflection)->toBeNull(); }); });