-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Use relative paths in templates paths cache #19687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fabpot
merged 1 commit into
symfony:master
from
tgalopin:templates-cache-relative-paths
Aug 23, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
102 changes: 102 additions & 0 deletions
102
src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/TemplatePathsCacheWarmerTest.php
This file contains hidden or 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,102 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer; | ||
|
||
use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface; | ||
use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplatePathsCacheWarmer; | ||
use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator; | ||
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference; | ||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
class TemplatePathsCacheWarmerTest extends TestCase | ||
{ | ||
/** @var Filesystem */ | ||
private $filesystem; | ||
|
||
/** @var TemplateFinderInterface */ | ||
private $templateFinder; | ||
|
||
/** @var FileLocator */ | ||
private $fileLocator; | ||
|
||
/** @var TemplateLocator */ | ||
private $templateLocator; | ||
|
||
private $tmpDir; | ||
|
||
public function setUp() | ||
{ | ||
$this->templateFinder = $this | ||
->getMockBuilder(TemplateFinderInterface::class) | ||
->setMethods(array('findAllTemplates')) | ||
->getMock(); | ||
|
||
$this->fileLocator = $this | ||
->getMockBuilder(FileLocator::class) | ||
->setMethods(array('locate')) | ||
->setConstructorArgs(array('/path/to/fallback')) | ||
->getMock(); | ||
|
||
$this->templateLocator = new TemplateLocator($this->fileLocator); | ||
|
||
$this->tmpDir = sys_get_temp_dir().DIRECTORY_SEPARATOR.uniqid('cache_template_paths_', true); | ||
|
||
$this->filesystem = new Filesystem(); | ||
$this->filesystem->mkdir($this->tmpDir); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
$this->filesystem->remove($this->tmpDir); | ||
} | ||
|
||
public function testWarmUp() | ||
{ | ||
$template = new TemplateReference('bundle', 'controller', 'name', 'format', 'engine'); | ||
|
||
$this->templateFinder | ||
->expects($this->once()) | ||
->method('findAllTemplates') | ||
->will($this->returnValue(array($template))); | ||
|
||
$this->fileLocator | ||
->expects($this->once()) | ||
->method('locate') | ||
->with($template->getPath()) | ||
->will($this->returnValue(dirname($this->tmpDir).'/path/to/template.html.twig')); | ||
|
||
$warmer = new TemplatePathsCacheWarmer($this->templateFinder, $this->templateLocator); | ||
$warmer->warmUp($this->tmpDir); | ||
|
||
$this->assertFileEquals(__DIR__.'/../Fixtures/TemplatePathsCache/templates.php', $this->tmpDir.'/templates.php'); | ||
} | ||
|
||
public function testWarmUpEmpty() | ||
{ | ||
$this->templateFinder | ||
->expects($this->once()) | ||
->method('findAllTemplates') | ||
->will($this->returnValue(array())); | ||
|
||
$this->fileLocator | ||
->expects($this->never()) | ||
->method('locate'); | ||
|
||
$warmer = new TemplatePathsCacheWarmer($this->templateFinder, $this->templateLocator); | ||
$warmer->warmUp($this->tmpDir); | ||
|
||
$this->assertFileExists($this->tmpDir.'/templates.php'); | ||
$this->assertSame(file_get_contents(__DIR__.'/../Fixtures/TemplatePathsCache/templates-empty.php'), file_get_contents($this->tmpDir.'/templates.php')); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TemplatePathsCache/templates-empty.php
This file contains hidden or 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,2 @@ | ||
<?php return array ( | ||
); |
3 changes: 3 additions & 0 deletions
3
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TemplatePathsCache/templates.php
This file contains hidden or 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,3 @@ | ||
<?php return array ( | ||
'bundle:controller:name.format.engine' => __DIR__.'/../path/to/template.html.twig', | ||
); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file_exists is faster and is_file have no advantage over it here.