From db774be8588f9d30ce4577bc06fac9711e08d9cb Mon Sep 17 00:00:00 2001 From: Olga Strizhenko Date: Fri, 15 Feb 2019 16:02:26 +0100 Subject: [PATCH 1/3] provide a path to view in compiled view --- src/Illuminate/View/Compilers/BladeCompiler.php | 3 ++- tests/View/ViewBladeCompilerTest.php | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index ddbfd912c2ae..0175caf2b42f 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -118,7 +118,8 @@ public function compile($path = null) } if (! is_null($this->cachePath)) { - $contents = $this->compileString($this->files->get($this->getPath())); + $contents = "getPath()} */?>\n"; + $contents .= $this->compileString($this->files->get($this->getPath())); $this->files->put($this->getCompiledPath($this->getPath()), $contents); } diff --git a/tests/View/ViewBladeCompilerTest.php b/tests/View/ViewBladeCompilerTest.php index 1894daf3c898..495b936433c6 100644 --- a/tests/View/ViewBladeCompilerTest.php +++ b/tests/View/ViewBladeCompilerTest.php @@ -49,7 +49,7 @@ 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', 'Hello World'); + $files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "\nHello World"); $compiler->compile('foo'); } @@ -57,7 +57,7 @@ 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', 'Hello World'); + $files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "\nHello World"); $compiler->compile('foo'); $this->assertEquals('foo', $compiler->getPath()); } @@ -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', 'Hello World'); + $files->shouldReceive('put')->once()->with(__DIR__.'/'.sha1('foo').'.php', "\nHello World"); // set path before compilation $compiler->setPath('foo'); // trigger compilation with null $path @@ -93,6 +93,14 @@ public function testRawTagsCanBeSetToLegacyValues() }}')); } + 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', "\nHello World"); + $compiler->compile('foo'); + } + protected function getFiles() { return m::mock(Filesystem::class); From 5356a02d54385f369068400a1b2740649da6e3e0 Mon Sep 17 00:00:00 2001 From: Olga Strizhenko Date: Fri, 15 Feb 2019 17:07:36 +0100 Subject: [PATCH 2/3] provide a path to view in compiled view: fix tests --- tests/Integration/Mail/RenderingMailWithLocaleTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Integration/Mail/RenderingMailWithLocaleTest.php b/tests/Integration/Mail/RenderingMailWithLocaleTest.php index e6697a7edcb7..ee3494cc19fd 100644 --- a/tests/Integration/Mail/RenderingMailWithLocaleTest.php +++ b/tests/Integration/Mail/RenderingMailWithLocaleTest.php @@ -31,14 +31,14 @@ public function testMailableRendersInDefaultLocale() { $mail = new RenderedTestMail; - $this->assertEquals('name'.PHP_EOL, $mail->render()); + $this->assertContains('name'.PHP_EOL, $mail->render()); } public function testMailableRendersInSelectedLocale() { $mail = (new RenderedTestMail)->locale('es'); - $this->assertEquals('nombre'.PHP_EOL, $mail->render()); + $this->assertContains('nombre'.PHP_EOL, $mail->render()); } public function testMailableRendersInAppSelectedLocale() @@ -47,7 +47,7 @@ public function testMailableRendersInAppSelectedLocale() $mail = new RenderedTestMail; - $this->assertEquals('nombre'.PHP_EOL, $mail->render()); + $this->assertContains('nombre'.PHP_EOL, $mail->render()); } } From cc15ef23dc3283a5665eaae35b59910726376712 Mon Sep 17 00:00:00 2001 From: Olga Strizhenko Date: Fri, 15 Feb 2019 18:10:34 +0100 Subject: [PATCH 3/3] replace deprecated assertContains() with assertStringContainsString() --- tests/Integration/Mail/RenderingMailWithLocaleTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Integration/Mail/RenderingMailWithLocaleTest.php b/tests/Integration/Mail/RenderingMailWithLocaleTest.php index ee3494cc19fd..3e03084778f5 100644 --- a/tests/Integration/Mail/RenderingMailWithLocaleTest.php +++ b/tests/Integration/Mail/RenderingMailWithLocaleTest.php @@ -31,14 +31,14 @@ public function testMailableRendersInDefaultLocale() { $mail = new RenderedTestMail; - $this->assertContains('name'.PHP_EOL, $mail->render()); + $this->assertStringContainsString("name\n", $mail->render()); } public function testMailableRendersInSelectedLocale() { $mail = (new RenderedTestMail)->locale('es'); - $this->assertContains('nombre'.PHP_EOL, $mail->render()); + $this->assertStringContainsString("nombre\n", $mail->render()); } public function testMailableRendersInAppSelectedLocale() @@ -47,7 +47,7 @@ public function testMailableRendersInAppSelectedLocale() $mail = new RenderedTestMail; - $this->assertContains('nombre'.PHP_EOL, $mail->render()); + $this->assertStringContainsString("nombre\n", $mail->render()); } }