Skip to content

Commit dc2f6cc

Browse files
authored
Merge pull request #316 from binaryfire/fix/service-provider-paths-to-publish
fix: pathsToPublish returning empty array instead of all paths
2 parents 57cb40b + 6445fe5 commit dc2f6cc

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/support/src/ServiceProvider.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,11 @@ public static function pathsToPublish(?string $provider = null, ?string $group =
255255

256256
/**
257257
* Get the paths for the provider or group (or both).
258+
*
259+
* Returns null when no filter is specified, allowing caller to fall back to all paths.
260+
* Returns empty array when a filter is specified but not found.
258261
*/
259-
protected static function pathsForProviderOrGroup(?string $provider, ?string $group): array
262+
protected static function pathsForProviderOrGroup(?string $provider, ?string $group): ?array
260263
{
261264
if ($provider && $group) {
262265
return static::pathsForProviderAndGroup($provider, $group);
@@ -268,7 +271,9 @@ protected static function pathsForProviderOrGroup(?string $provider, ?string $gr
268271
return static::$publishes[$provider];
269272
}
270273

271-
return [];
274+
// Return [] if a filter was specified but not found
275+
// Return null if no filter was specified (allows fallback to all paths)
276+
return ($provider || $group) ? [] : null;
272277
}
273278

274279
/**

tests/Support/SupportServiceProviderTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,36 @@ public function testPublishesMigrations()
139139

140140
$this->assertContains('source/tagged/four', ServiceProvider::publishableMigrationPaths());
141141
}
142+
143+
public function testAllPathsAreReturnedWhenNoFilterIsSpecified()
144+
{
145+
$allPaths = ServiceProvider::pathsToPublish();
146+
147+
// Should contain paths from both providers
148+
$this->assertArrayHasKey('source/unmarked/one', $allPaths);
149+
$this->assertArrayHasKey('source/tagged/one', $allPaths);
150+
$this->assertArrayHasKey('source/unmarked/two/a', $allPaths);
151+
$this->assertArrayHasKey('source/tagged/two/a', $allPaths);
152+
153+
// Should have all 11 paths from both providers
154+
$this->assertCount(11, $allPaths);
155+
}
156+
157+
public function testEmptyArrayIsReturnedWhenProviderNotFound()
158+
{
159+
$paths = ServiceProvider::pathsToPublish('NonExistent\Provider');
160+
161+
$this->assertIsArray($paths);
162+
$this->assertEmpty($paths);
163+
}
164+
165+
public function testEmptyArrayIsReturnedWhenGroupNotFound()
166+
{
167+
$paths = ServiceProvider::pathsToPublish(null, 'nonexistent_group');
168+
169+
$this->assertIsArray($paths);
170+
$this->assertEmpty($paths);
171+
}
142172
}
143173

144174
class ServiceProviderForTestingOne extends ServiceProvider

0 commit comments

Comments
 (0)