Skip to content

Commit

Permalink
fix(tests): fix storage tests for linux
Browse files Browse the repository at this point in the history
File writing does not respect locks on linux
  • Loading branch information
m-thalmann committed Apr 14, 2024
1 parent 823779d commit edd7729
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ abstract class TestCase extends BaseTestCase {

protected const REDIRECT_TEST_ROUTE = '/redirect-test-route';

protected FilesystemAdapter $storageFake;
protected FilesystemAdapter|MockInterface $storageFake;

protected function setUp(): void {
parent::setUp();

$this->storageFake = Storage::fake('files');
$this->storageFake = Mockery::mock(Storage::fake('files'));

$this->withoutVite();
}
Expand Down
14 changes: 6 additions & 8 deletions tests/Unit/Services/FileVersionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -949,13 +949,13 @@ public function testStoreFileFailsIfTheEncryptionFails(): void {
public function testStoreFileFailsIfTemporaryFileCantBeMoved(): void {
$this->expectException(FileWriteException::class);

$this->storageFake->shouldReceive('move')->andReturnFalse();

$path = 'test-path';
$tmpPath = $path . $this->service->getTmpSuffix();

$resource = $this->createStream(fake()->text());

$lockFile = fopen($this->storageFake->path($path), 'w');

try {
$this->service->storeFile(
$resource,
Expand All @@ -967,23 +967,21 @@ public function testStoreFileFailsIfTemporaryFileCantBeMoved(): void {
$this->storageFake->assertMissing($tmpPath);

fclose($resource);
fclose($lockFile);

$this->assertEmpty(
file_get_contents($this->storageFake->path($path))
);
$this->assertFalse($this->storageFake->exists($path));

throw $e;
}

fclose($resource);
fclose($lockFile);
}

public function testStoreFileFailsIfFileCantBeStoredWithoutEncryption(): void {
$this->expectException(FileWriteException::class);

$path = '<illegal-path>';
$this->storageFake->shouldReceive('writeStream')->andReturnFalse();

$path = 'test-path';

$resource = $this->createStream(fake()->text());

Expand Down

0 comments on commit edd7729

Please sign in to comment.