Skip to content

Commit

Permalink
Merge pull request #27914 from bzixilu/5.8
Browse files Browse the repository at this point in the history
[5.8] Path of the view in compiled template causes regression with declare(strict_types=1) in templates #27704
  • Loading branch information
taylorotwell authored Mar 18, 2019
2 parents c2410f0 + c633f22 commit bf3a602
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public function compile($path = null)
}

if (! is_null($this->cachePath)) {
$contents = "<?php /* {$this->getPath()} */ ?>\n".
$this->compileString($this->files->get($this->getPath()));
$contents = $this->compileString($this->files->get($this->getPath())).
"\n<?php /* {$this->getPath()} */ ?>";

$this->files->put($this->getCompiledPath($this->getPath()), $contents);
}
Expand Down
16 changes: 12 additions & 4 deletions tests/View/ViewBladeCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public function testCompileCompilesFileAndReturnsContents()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "<?php /* foo */ ?>\nHello World");
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "Hello World\n<?php /* foo */ ?>");
$compiler->compile('foo');
}

public function testCompileCompilesAndGetThePath()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "<?php /* foo */ ?>\nHello World");
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "Hello World\n<?php /* foo */ ?>");
$compiler->compile('foo');
$this->assertEquals('foo', $compiler->getPath());
}
Expand All @@ -73,7 +73,7 @@ public function testCompileWithPathSetBefore()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "<?php /* foo */ ?>\nHello World");
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "Hello World\n<?php /* foo */ ?>");
// set path before compilation
$compiler->setPath('foo');
// trigger compilation with null $path
Expand All @@ -97,10 +97,18 @@ public function testIncludePathToTemplate()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "<?php /* foo */ ?>\nHello World");
$files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "Hello World\n<?php /* foo */ ?>");
$compiler->compile('foo');
}

public function testShouldStartFromStrictTypesDeclaration()
{
$compiler = new BladeCompiler($files = $this->getFiles(), __DIR__);
$strictTypeDecl = "<?php\ndeclare(strict_types = 1);";
$this->assertTrue(substr($compiler->compileString("<?php\ndeclare(strict_types = 1);\nHello World"),
0, strlen($strictTypeDecl)) === $strictTypeDecl);
}

protected function getFiles()
{
return m::mock(Filesystem::class);
Expand Down

0 comments on commit bf3a602

Please sign in to comment.