Skip to content

Commit aabd1a9

Browse files
committed
Add tests for file permissions
1 parent 9834f6c commit aabd1a9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/Cache/CacheFileStoreTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Contracts\Filesystem\FileNotFoundException;
77
use Illuminate\Filesystem\Filesystem;
88
use Illuminate\Support\Carbon;
9+
use Mockery as m;
910
use PHPUnit\Framework\TestCase;
1011

1112
class CacheFileStoreTest extends TestCase
@@ -79,6 +80,27 @@ public function testStoreItemProperlyStoresValues()
7980
$this->assertTrue($result);
8081
}
8182

83+
public function testStoreItemProperlySetsPermissions()
84+
{
85+
$files = m::mock(Filesystem::class);
86+
$files->shouldIgnoreMissing();
87+
$store = $this->getMockBuilder(FileStore::class)->setMethods(['expiration'])->setConstructorArgs([$files, __DIR__, 0644])->getMock();
88+
$hash = sha1('foo');
89+
$cache_dir = substr($hash, 0, 2).'/'.substr($hash, 2, 2);
90+
$files->shouldReceive('put')->withArgs([__DIR__.'/'.$cache_dir.'/'.$hash, m::any(), m::any()])->andReturnUsing(function ($name, $value) {
91+
return strlen($value);
92+
});
93+
$files->shouldReceive('chmod')->withArgs([__DIR__.'/'.$cache_dir.'/'.$hash])->andReturnValues(["0600", "0644"])->times(3);
94+
$files->shouldReceive('chmod')->withArgs([__DIR__.'/'.$cache_dir.'/'.$hash, 0644])->andReturn([true])->once();
95+
$result = $store->put('foo', 'foo', 10);
96+
$this->assertTrue($result);
97+
$result = $store->put('foo', 'bar', 10);
98+
$this->assertTrue($result);
99+
$result = $store->put('foo', 'baz', 10);
100+
$this->assertTrue($result);
101+
m::close();
102+
}
103+
82104
public function testForeversAreStoredWithHighTimestamp()
83105
{
84106
$files = $this->mockFilesystem();

0 commit comments

Comments
 (0)