expect($this->interceptor->loadFile($sourcePath))->toBe(true); expect(class_exists('loadFileNamespace\\ClassA', false))->toBe(true); }); it("loads cached files", function () { $sourcePath = $this->loadFileNamespacePath . DS . 'ClassCached.php'; $body = $this->classBuilder('ClassCached'); file_put_contents($sourcePath, $body); $sourceTimestamp = filemtime($sourcePath); $this->interceptor->cache($sourcePath, $body, $sourceTimestamp + 1); expect($this->interceptor->loadFile($sourcePath))->toBe(true); expect(class_exists('loadFileNamespace\\ClassCached', false))->toBe(true); }); it("throws an exception for unexisting files", function () { $path = $this->loadFileNamespacePath . DS . 'ClassUnexisting.php'; $closure = function () use($path) { $interceptor = Interceptor::instance(); $interceptor->loadFile($path); }; expect($closure)->toThrow("Error, the file `'{$path}'` doesn't exist."); }); it("caches a loaded files and set the cached file motification time to be the same as the source file", function () { $sourcePath = $this->loadFileNamespacePath . DS . 'ClassB.php'; file_put_contents($sourcePath, $this->classBuilder('ClassB')); $currentTimestamp = time(); $sourceTimestamp = $currentTimestamp - 5 * 60; touch($sourcePath, $sourceTimestamp); expect($this->interceptor->loadFile($sourcePath))->toBe(true); expect(class_exists('loadFileNamespace\\ClassB', false))->toBe(true); $cacheTimestamp = filemtime($this->interceptor->cachePath() . DS . ltrim(preg_replace('~:~', '', $sourcePath), DS)); expect($sourceTimestamp)->toBe($cacheTimestamp - 1); });