Skip to content

Commit

Permalink
Do not allow empty cache paths (#14291)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell authored and taylorotwell committed Jul 18, 2016
1 parent 6f8c3ca commit 90f2edd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
9 changes: 8 additions & 1 deletion src/Illuminate/View/Compilers/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\View\Compilers;

use InvalidArgumentException;
use Illuminate\Filesystem\Filesystem;

abstract class Compiler
Expand All @@ -26,9 +27,15 @@ abstract class Compiler
* @param \Illuminate\Filesystem\Filesystem $files
* @param string $cachePath
* @return void
*
* @throws \InvalidArgumentException
*/
public function __construct(Filesystem $files, $cachePath)
{
if (! $cachePath) {
throw new InvalidArgumentException('The cache path must be non-empty.');
}

$this->files = $files;
$this->cachePath = $cachePath;
}
Expand Down Expand Up @@ -57,7 +64,7 @@ public function isExpired($path)
// If the compiled file doesn't exist we will indicate that the view is expired
// so that it can be re-compiled. Else, we will verify the last modification
// of the views is less than the modification times of the compiled views.
if (! $this->cachePath || ! $this->files->exists($compiled)) {
if (! $this->files->exists($compiled)) {
return true;
}

Expand Down
17 changes: 5 additions & 12 deletions tests/View/ViewBladeCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ public function testIsExpiredReturnsTrueIfCompiledFileDoesntExist()
$this->assertTrue($compiler->isExpired('foo'));
}

public function testIsExpiredReturnsTrueIfCachePathIsNull()
/**
* @expectedException \InvalidArgumentException
*/
public function testCannotConstructWithBadCachePath()
{
$compiler = new BladeCompiler($files = $this->getFiles(), null);
$files->shouldReceive('exists')->never();
$this->assertTrue($compiler->isExpired('foo'));
new BladeCompiler($this->getFiles(), null);
}

public function testIsExpiredReturnsTrueWhenModificationTimesWarrant()
Expand Down Expand Up @@ -75,14 +76,6 @@ public function testCompileWithPathSetBefore()
$this->assertEquals('foo', $compiler->getPath());
}

public function testCompileDoesntStoreFilesWhenCachePathIsNull()
{
$compiler = new BladeCompiler($files = $this->getFiles(), null);
$files->shouldReceive('get')->once()->with('foo')->andReturn('Hello World');
$files->shouldReceive('put')->never();
$compiler->compile('foo');
}

public function testEchosAreCompiled()
{
$compiler = new BladeCompiler($this->getFiles(), __DIR__);
Expand Down

0 comments on commit 90f2edd

Please sign in to comment.