Skip to content

Commit

Permalink
$refreshed is set in rebuildCallback()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 29, 2016
1 parent 51b4778 commit 1e6bcad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/RobotLoader/RobotLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

Expand All @@ -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)) {
Expand Down
16 changes: 12 additions & 4 deletions tests/Loaders/RobotLoader.rebuild.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

use Nette\Loaders\RobotLoader;
use Nette\Caching\Storages\DevNullStorage;
use Nette\Caching\Storages\FileStorage;
use Tester\Assert;


Expand All @@ -16,13 +16,21 @@ file_put_contents(TEMP_DIR . '/file1.php', '<?php class A {}');
file_put_contents(TEMP_DIR . '/file2.php', '<?php class B {}');

$loader = new RobotLoader;
$loader->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');

Expand Down

0 comments on commit 1e6bcad

Please sign in to comment.