-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DependencyChecker::isExpired() can alter $phpFiles modification times […
…Closes #144]
- Loading branch information
Showing
4 changed files
with
103 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\DI\ContainerLoader expiration test. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\DI; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
$loader = new DI\ContainerLoader(TEMP_DIR . '/subdir', TRUE); | ||
|
||
// create container | ||
Assert::with($loader, function () { | ||
$this->loadFile('class1', function () {}); | ||
}); | ||
|
||
// ensure files are created | ||
$file = (new ReflectionClass('class1'))->getFileName(); | ||
Assert::true(is_file($file)); | ||
Assert::true(is_file("$file.meta")); | ||
|
||
|
||
// load again, nothing was modified | ||
Assert::with($loader, function () use ($file) { | ||
Assert::false($this->isExpired($file, $newMeta)); | ||
Assert::null($newMeta); | ||
}); | ||
|
||
|
||
// alter filemtime in files | ||
$meta = file_get_contents("$file.meta"); | ||
$altered = unserialize($meta); | ||
$altered[1][__FILE__] = 123; | ||
file_put_contents("$file.meta", serialize($altered)); | ||
|
||
Assert::with($loader, function () use ($file) { | ||
Assert::true($this->isExpired($file, $newMeta)); | ||
Assert::null($newMeta); | ||
}); | ||
|
||
|
||
// alter filemtime in classes | ||
$altered = unserialize($meta); | ||
$altered[2][key($altered[2])] = 123; | ||
file_put_contents("$file.meta", serialize($altered)); | ||
|
||
Assert::with($loader, function () use ($file, $meta) { | ||
Assert::true($this->isExpired($file, $newMeta)); | ||
Assert::same($meta, $newMeta); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\DI\ContainerLoader expiration test. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\DI; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
$loader = new DI\ContainerLoader(TEMP_DIR . '/subdir', TRUE); | ||
|
||
// create container | ||
Assert::with($loader, function () { | ||
$this->loadFile('class1', function () {}); | ||
}); | ||
|
||
// ensure files are created | ||
$file = (new ReflectionClass('class1'))->getFileName(); | ||
Assert::true(is_file($file)); | ||
Assert::true(is_file("$file.meta")); | ||
|
||
// load again | ||
file_put_contents($file, ''); // remove file to avoid class redeclare error | ||
Assert::with($loader, function () { | ||
$this->loadFile('class1', function () { Assert::fail('Should not be recreated'); }); | ||
}); |