From 1e6bcadb633eb0b22ec0c3bd73c7dc7452e22218 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 29 Sep 2016 17:48:24 +0200 Subject: [PATCH] $refreshed is set in rebuildCallback() --- src/RobotLoader/RobotLoader.php | 2 +- tests/Loaders/RobotLoader.rebuild.phpt | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/RobotLoader/RobotLoader.php b/src/RobotLoader/RobotLoader.php index 173d289..b4ccc77 100644 --- a/src/RobotLoader/RobotLoader.php +++ b/src/RobotLoader/RobotLoader.php @@ -143,7 +143,6 @@ public function getIndexedClasses() */ public function rebuild() { - $this->refreshed = TRUE; // prevents calling rebuild() or updateFile() in tryLoad() $this->getCache()->save($this->getKey(), Nette\Utils\Callback::closure($this, 'rebuildCallback')); } @@ -153,6 +152,7 @@ public function rebuild() */ public function rebuildCallback() { + $this->refreshed = TRUE; // prevents calling rebuild() or updateFile() in tryLoad() $files = $missing = []; foreach ($this->classes as $class => $info) { if (is_array($info)) { diff --git a/tests/Loaders/RobotLoader.rebuild.phpt b/tests/Loaders/RobotLoader.rebuild.phpt index 0a35340..47dc730 100644 --- a/tests/Loaders/RobotLoader.rebuild.phpt +++ b/tests/Loaders/RobotLoader.rebuild.phpt @@ -5,7 +5,7 @@ */ use Nette\Loaders\RobotLoader; -use Nette\Caching\Storages\DevNullStorage; +use Nette\Caching\Storages\FileStorage; use Tester\Assert; @@ -16,13 +16,21 @@ file_put_contents(TEMP_DIR . '/file1.php', 'setCacheStorage(new DevNullStorage); +$loader->setCacheStorage(new FileStorage(TEMP_DIR)); $loader->addDirectory(TEMP_DIR); -$loader->register(); +$loader->register(); // rebuilds cache rename(TEMP_DIR . '/file1.php', TEMP_DIR . '/file3.php'); -$a = new A; +Assert::false(class_exists('A')); + + +$loader2 = new RobotLoader; +$loader2->setCacheStorage(new FileStorage(TEMP_DIR)); +$loader2->addDirectory(TEMP_DIR); +$loader2->register(); + +Assert::true(class_exists('A')); rename(TEMP_DIR . '/file2.php', TEMP_DIR . '/file4.php');