Skip to content

Commit 3b329c9

Browse files
authored
Fix filesystem assertExists/assertMissing not handling array as path argument (#877)
* Add failing test * Fix filesystem `assertExists`/`assertMissing` not handling array as path argument
1 parent 6766731 commit 3b329c9

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/Sentry/Laravel/Features/Storage/FilesystemAdapterDecorator.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ trait FilesystemAdapterDecorator
88

99
public function assertExists($path, $content = null)
1010
{
11-
return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path'));
11+
[$description, $data] = $this->getDescriptionAndDataForPathOrPaths($path);
12+
13+
return $this->withSentry(__FUNCTION__, func_get_args(), $description, $data);
1214
}
1315

1416
public function assertMissing($path)
1517
{
16-
return $this->withSentry(__FUNCTION__, func_get_args(), $path, compact('path'));
18+
[$description, $data] = $this->getDescriptionAndDataForPathOrPaths($path);
19+
20+
return $this->withSentry(__FUNCTION__, func_get_args(), $description, $data);
1721
}
1822

1923
public function assertDirectoryEmpty($path)

src/Sentry/Laravel/Features/Storage/FilesystemDecorator.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,7 @@ public function append($path, $data, $separator = PHP_EOL)
135135

136136
public function delete($paths)
137137
{
138-
if (is_array($paths)) {
139-
$data = compact('paths');
140-
$description = sprintf('%s paths', count($paths));
141-
} else {
142-
$data = ['path' => $paths];
143-
$description = $paths;
144-
}
138+
[$description, $data] = $this->getDescriptionAndDataForPathOrPaths($paths);
145139

146140
return $this->withSentry(__FUNCTION__, func_get_args(), $description, $data);
147141
}
@@ -200,4 +194,17 @@ public function __call($name, $arguments)
200194
{
201195
return $this->filesystem->{$name}(...$arguments);
202196
}
197+
198+
protected function getDescriptionAndDataForPathOrPaths($pathOrPaths): array
199+
{
200+
if (is_array($pathOrPaths)) {
201+
$description = sprintf('%s paths', count($pathOrPaths));
202+
$data = ['paths' => $pathOrPaths];
203+
} else {
204+
$description = $pathOrPaths;
205+
$data = ['path' => $pathOrPaths];
206+
}
207+
208+
return [$description, $data];
209+
}
203210
}

test/Sentry/Features/StorageIntegrationTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function testCreatesSpansFor(): void
2222
Storage::delete('foo');
2323
Storage::delete(['foo', 'bar']);
2424
Storage::files();
25+
Storage::assertMissing(['foo', 'bar']);
2526

2627
$spans = $transaction->getSpanRecorder()->getSpans();
2728

@@ -61,6 +62,12 @@ public function testCreatesSpansFor(): void
6162
$this->assertSame('file.files', $span->getOp());
6263
$this->assertNull($span->getDescription());
6364
$this->assertSame(['directory' => null, 'recursive' => false, 'disk' => 'local', 'driver' => 'local'], $span->getData());
65+
66+
$this->assertArrayHasKey(7, $spans);
67+
$span = $spans[7];
68+
$this->assertSame('file.assertMissing', $span->getOp());
69+
$this->assertSame('2 paths', $span->getDescription());
70+
$this->assertSame(['paths' => ['foo', 'bar'], 'disk' => 'local', 'driver' => 'local'], $span->getData());
6471
}
6572

6673
public function testDoesntCreateSpansWhenDisabled(): void

0 commit comments

Comments
 (0)