-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] Run
clearstatcache
after deleting file and asserting `Storage…
…` using exists/missing (#40257) * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]>
- Loading branch information
Showing
5 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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,73 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Filesystem; | ||
|
||
use Illuminate\Support\Facades\File; | ||
use Orchestra\Testbench\TestCase; | ||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* @requires OS Linux|Darwin | ||
*/ | ||
class FilesystemTest extends TestCase | ||
{ | ||
protected $stubFile; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->afterApplicationCreated(function () { | ||
File::put($file = storage_path('app/public/StardewTaylor.png'), File::get(__DIR__.'/Fixtures/StardewTaylor.png')); | ||
$this->stubFile = $file; | ||
}); | ||
|
||
$this->beforeApplicationDestroyed(function () { | ||
if (File::exists($this->stubFile)) { | ||
File::delete($this->stubFile); | ||
} | ||
}); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function testItCanDeleteViaFilesystemShouldUpdatesFileExists() | ||
{ | ||
$this->assertTrue(File::exists($this->stubFile)); | ||
$this->assertTrue(File::isFile($this->stubFile)); | ||
|
||
File::delete($this->stubFile); | ||
|
||
$this->assertFalse(File::exists($this->stubFile)); | ||
} | ||
|
||
public function testItCanDeleteViaFilesystemRequiresManualClearStatCacheOnFileExistsFromDifferentProcess() | ||
{ | ||
$this->assertTrue(File::exists($this->stubFile)); | ||
$this->assertTrue(File::isFile($this->stubFile)); | ||
|
||
Process::fromShellCommandline("rm {$this->stubFile}")->run(); | ||
|
||
clearstatcache(true, $this->stubFile); | ||
$this->assertFalse(File::exists($this->stubFile)); | ||
} | ||
|
||
public function testItCanDeleteViaFilesystemShouldUpdatesIsFile() | ||
{ | ||
$this->assertTrue(File::exists($this->stubFile)); | ||
$this->assertTrue(File::isFile($this->stubFile)); | ||
|
||
File::delete($this->stubFile); | ||
|
||
$this->assertFalse(File::isFile($this->stubFile)); | ||
} | ||
|
||
public function testItCanDeleteViaFilesystemRequiresManualClearStatCacheOnIsFileFromDifferentProcess() | ||
{ | ||
$this->assertTrue(File::exists($this->stubFile)); | ||
$this->assertTrue(File::isFile($this->stubFile)); | ||
|
||
Process::fromShellCommandline("rm {$this->stubFile}")->run(); | ||
|
||
clearstatcache(true, $this->stubFile); | ||
$this->assertFalse(File::isFile($this->stubFile)); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,66 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Filesystem; | ||
|
||
use Illuminate\Support\Facades\File; | ||
use Illuminate\Support\Facades\Storage; | ||
use Orchestra\Testbench\TestCase; | ||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* @requires OS Linux|Darwin | ||
*/ | ||
class StorageTest extends TestCase | ||
{ | ||
protected $stubFile; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->afterApplicationCreated(function () { | ||
File::put($file = storage_path('app/public/StardewTaylor.png'), File::get(__DIR__.'/Fixtures/StardewTaylor.png')); | ||
$this->stubFile = $file; | ||
}); | ||
|
||
$this->beforeApplicationDestroyed(function () { | ||
if (File::exists($this->stubFile)) { | ||
File::delete($this->stubFile); | ||
} | ||
}); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function testItCanDeleteViaStorage() | ||
{ | ||
Storage::disk('public')->assertExists('StardewTaylor.png'); | ||
$this->assertTrue(Storage::disk('public')->exists('StardewTaylor.png')); | ||
|
||
Storage::disk('public')->delete('StardewTaylor.png'); | ||
|
||
Storage::disk('public')->assertMissing('StardewTaylor.png'); | ||
$this->assertFalse(Storage::disk('public')->exists('StardewTaylor.png')); | ||
} | ||
|
||
public function testItCanDeleteViaFilesystemShouldUpdatesStorage() | ||
{ | ||
Storage::disk('public')->assertExists('StardewTaylor.png'); | ||
$this->assertTrue(Storage::disk('public')->exists('StardewTaylor.png')); | ||
|
||
File::delete($this->stubFile); | ||
|
||
Storage::disk('public')->assertMissing('StardewTaylor.png'); | ||
$this->assertFalse(Storage::disk('public')->exists('StardewTaylor.png')); | ||
} | ||
|
||
public function testItCanDeleteViaFilesystemRequiresManualClearStatCacheOnStorageFromDifferentProcess() | ||
{ | ||
Storage::disk('public')->assertExists('StardewTaylor.png'); | ||
$this->assertTrue(Storage::disk('public')->exists('StardewTaylor.png')); | ||
|
||
Process::fromShellCommandline("rm {$this->stubFile}")->run(); | ||
|
||
clearstatcache(true, $this->stubFile); | ||
Storage::disk('public')->assertMissing('StardewTaylor.png'); | ||
$this->assertFalse(Storage::disk('public')->exists('StardewTaylor.png')); | ||
} | ||
} |