From 97e36c0dfc0986bd73e6b527f11af09f6d34f1de Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Tue, 2 Apr 2024 13:40:42 +0200 Subject: [PATCH 1/2] Add failing test --- test/Sentry/Features/StorageIntegrationTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/Sentry/Features/StorageIntegrationTest.php b/test/Sentry/Features/StorageIntegrationTest.php index 343c7765..83289462 100644 --- a/test/Sentry/Features/StorageIntegrationTest.php +++ b/test/Sentry/Features/StorageIntegrationTest.php @@ -22,6 +22,7 @@ public function testCreatesSpansFor(): void Storage::delete('foo'); Storage::delete(['foo', 'bar']); Storage::files(); + Storage::assertMissing(['foo', 'bar']); $spans = $transaction->getSpanRecorder()->getSpans(); @@ -61,6 +62,12 @@ public function testCreatesSpansFor(): void $this->assertSame('file.files', $span->getOp()); $this->assertNull($span->getDescription()); $this->assertSame(['directory' => null, 'recursive' => false, 'disk' => 'local', 'driver' => 'local'], $span->getData()); + + $this->assertArrayHasKey(7, $spans); + $span = $spans[7]; + $this->assertSame('file.assertMissing', $span->getOp()); + $this->assertSame('2 paths', $span->getDescription()); + $this->assertSame(['paths' => ['foo', 'bar'], 'disk' => 'local', 'driver' => 'local'], $span->getData()); } public function testDoesntCreateSpansWhenDisabled(): void From 0821dee430aca4c7bdb432e196c430db8699621a Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Tue, 2 Apr 2024 13:41:29 +0200 Subject: [PATCH 2/2] Fix filesystem `assertExists`/`assertMissing` not handling array as path argument --- .../Storage/FilesystemAdapterDecorator.php | 8 +++++-- .../Features/Storage/FilesystemDecorator.php | 21 ++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Sentry/Laravel/Features/Storage/FilesystemAdapterDecorator.php b/src/Sentry/Laravel/Features/Storage/FilesystemAdapterDecorator.php index 46bd6e4b..6414a9e5 100644 --- a/src/Sentry/Laravel/Features/Storage/FilesystemAdapterDecorator.php +++ b/src/Sentry/Laravel/Features/Storage/FilesystemAdapterDecorator.php @@ -8,12 +8,16 @@ trait FilesystemAdapterDecorator public function assertExists($path, $content = null) { - return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path')); + [$description, $data] = $this->getDescriptionAndDataForPathOrPaths($path); + + return $this->withSentry(__FUNCTION__, func_get_args(), $description, $data); } public function assertMissing($path) { - return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path')); + [$description, $data] = $this->getDescriptionAndDataForPathOrPaths($path); + + return $this->withSentry(__FUNCTION__, func_get_args(), $description, $data); } public function assertDirectoryEmpty($path) diff --git a/src/Sentry/Laravel/Features/Storage/FilesystemDecorator.php b/src/Sentry/Laravel/Features/Storage/FilesystemDecorator.php index ee745d18..6d765119 100644 --- a/src/Sentry/Laravel/Features/Storage/FilesystemDecorator.php +++ b/src/Sentry/Laravel/Features/Storage/FilesystemDecorator.php @@ -135,13 +135,7 @@ public function append($path, $data, $separator = PHP_EOL) public function delete($paths) { - if (is_array($paths)) { - $data = compact('paths'); - $description = sprintf('%s paths', count($paths)); - } else { - $data = ['path' => $paths]; - $description = $paths; - } + [$description, $data] = $this->getDescriptionAndDataForPathOrPaths($paths); return $this->withSentry(__FUNCTION__, func_get_args(), $description, $data); } @@ -200,4 +194,17 @@ public function __call($name, $arguments) { return $this->filesystem->{$name}(...$arguments); } + + protected function getDescriptionAndDataForPathOrPaths($pathOrPaths): array + { + if (is_array($pathOrPaths)) { + $description = sprintf('%s paths', count($pathOrPaths)); + $data = ['paths' => $pathOrPaths]; + } else { + $description = $pathOrPaths; + $data = ['path' => $pathOrPaths]; + } + + return [$description, $data]; + } }