Skip to content

Commit e077ac6

Browse files
committed
Remove internal validate existence flag
1 parent a39ba5b commit e077ac6

File tree

3 files changed

+2
-28
lines changed

3 files changed

+2
-28
lines changed

packages/framework/src/Support/Filesystem/MediaFile.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ class MediaFile extends ProjectFile
2525
/** @var array<string> The default extensions for media types */
2626
final public const EXTENSIONS = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'ico', 'css', 'js'];
2727

28-
/** @internal Controls whether to validate the existence of the file, intended for unit testing. Turning this off may lead to unexpected behavior. */
29-
public static bool $validateExistence = true;
30-
3128
public readonly int $length;
3229
public readonly string $mimeType;
3330
public readonly string $hash;
@@ -36,7 +33,7 @@ public function __construct(string $path)
3633
{
3734
$path = $this->normalizePath($path);
3835

39-
if (static::$validateExistence && Filesystem::missing($path)) {
36+
if (Filesystem::missing($path)) {
4037
throw new FileNotFoundException($path);
4138
}
4239

packages/framework/tests/Unit/Foundation/FilesystemHasMediaFilesTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,10 @@ protected function setUp(): void
2828
$this->filesystem = new TestableFilesystem(Hyde::getInstance());
2929

3030
$mock = Mockery::mock(BaseFilesystem::class)->makePartial();
31+
$mock->shouldReceive('missing')->andReturn(false)->byDefault();
3132
$mock->shouldReceive('size')->andReturn(100)->byDefault();
3233
$mock->shouldReceive('hash')->andReturn('hash')->byDefault();
3334
app()->instance(BaseFilesystem::class, $mock);
34-
35-
MediaFile::$validateExistence = false;
36-
}
37-
38-
protected function tearDown(): void
39-
{
40-
parent::tearDown();
41-
MediaFile::$validateExistence = true;
4235
}
4336

4437
public function testAssetsMethodReturnsSameInstanceOnSubsequentCalls()

packages/framework/tests/Unit/Support/MediaFileUnitTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ protected function setUp(): void
4545
{
4646
parent::setUp();
4747

48-
MediaFile::$validateExistence = false;
49-
5048
$this->mockFilesystem = Mockery::mock(BaseFilesystem::class);
5149
app()->instance(BaseFilesystem::class, $this->mockFilesystem);
5250

@@ -68,7 +66,6 @@ protected function tearDown(): void
6866
{
6967
parent::tearDown();
7068

71-
MediaFile::$validateExistence = true;
7269
Mockery::close();
7370
}
7471

@@ -147,15 +144,6 @@ public function testConstructorWithVariousInputFormats()
147144
$this->assertSame('_media/foo.txt', MediaFile::make('media/foo.txt')->path);
148145
}
149146

150-
public function testConstructorWithValidationDisabled()
151-
{
152-
MediaFile::$validateExistence = false;
153-
$this->mockFilesystem->shouldReceive('missing')->never();
154-
155-
$file = new MediaFile('non_existent_file.txt');
156-
$this->assertInstanceOf(MediaFile::class, $file);
157-
}
158-
159147
public function testConstructorSetsProperties()
160148
{
161149
$file = new MediaFile('foo.txt');
@@ -285,8 +273,6 @@ public function testGetHashReturnsHash()
285273

286274
public function testExceptionIsThrownWhenConstructingFileThatDoesNotExist()
287275
{
288-
MediaFile::$validateExistence = true;
289-
290276
$this->mockFilesystem->shouldReceive('missing')
291277
->with(Hyde::path('_media/foo'))
292278
->andReturn(true);
@@ -299,8 +285,6 @@ public function testExceptionIsThrownWhenConstructingFileThatDoesNotExist()
299285

300286
public function testExceptionIsNotThrownWhenConstructingFileThatDoesExist()
301287
{
302-
MediaFile::$validateExistence = true;
303-
304288
$this->mockFilesystem->shouldReceive('missing')
305289
->with(Hyde::path('_media/foo'))
306290
->andReturn(false);

0 commit comments

Comments
 (0)