From 6445fe5284f554ae93cb797f3ebd495dd43dd273 Mon Sep 17 00:00:00 2001 From: Raj Siva-Rajah <5361908+binaryfire@users.noreply.github.com> Date: Fri, 26 Dec 2025 02:26:06 +0000 Subject: [PATCH] Fix pathsToPublish returning empty array instead of all paths When pathsToPublish() is called with no arguments, it should return all published paths from all providers. Instead, it was returning an empty array. The bug: pathsForProviderOrGroup() always returned [] at the end, even when no filter was specified. The calling code checks for null to determine whether to fall back to returning all paths. The fix: Return null when no filter is specified (both $provider and $group are null), and return [] only when a filter was specified but not found. This matches Laravel's behavior. Added tests for: - pathsToPublish() with no args returns all paths - pathsToPublish() with non-existent provider returns [] - pathsToPublish() with non-existent group returns [] --- src/support/src/ServiceProvider.php | 9 ++++-- tests/Support/SupportServiceProviderTest.php | 30 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/support/src/ServiceProvider.php b/src/support/src/ServiceProvider.php index 92a97a236..e186d4a34 100644 --- a/src/support/src/ServiceProvider.php +++ b/src/support/src/ServiceProvider.php @@ -255,8 +255,11 @@ public static function pathsToPublish(?string $provider = null, ?string $group = /** * Get the paths for the provider or group (or both). + * + * Returns null when no filter is specified, allowing caller to fall back to all paths. + * Returns empty array when a filter is specified but not found. */ - protected static function pathsForProviderOrGroup(?string $provider, ?string $group): array + protected static function pathsForProviderOrGroup(?string $provider, ?string $group): ?array { if ($provider && $group) { return static::pathsForProviderAndGroup($provider, $group); @@ -268,7 +271,9 @@ protected static function pathsForProviderOrGroup(?string $provider, ?string $gr return static::$publishes[$provider]; } - return []; + // Return [] if a filter was specified but not found + // Return null if no filter was specified (allows fallback to all paths) + return ($provider || $group) ? [] : null; } /** diff --git a/tests/Support/SupportServiceProviderTest.php b/tests/Support/SupportServiceProviderTest.php index fb69453ef..725c7e818 100644 --- a/tests/Support/SupportServiceProviderTest.php +++ b/tests/Support/SupportServiceProviderTest.php @@ -139,6 +139,36 @@ public function testPublishesMigrations() $this->assertContains('source/tagged/four', ServiceProvider::publishableMigrationPaths()); } + + public function testAllPathsAreReturnedWhenNoFilterIsSpecified() + { + $allPaths = ServiceProvider::pathsToPublish(); + + // Should contain paths from both providers + $this->assertArrayHasKey('source/unmarked/one', $allPaths); + $this->assertArrayHasKey('source/tagged/one', $allPaths); + $this->assertArrayHasKey('source/unmarked/two/a', $allPaths); + $this->assertArrayHasKey('source/tagged/two/a', $allPaths); + + // Should have all 11 paths from both providers + $this->assertCount(11, $allPaths); + } + + public function testEmptyArrayIsReturnedWhenProviderNotFound() + { + $paths = ServiceProvider::pathsToPublish('NonExistent\Provider'); + + $this->assertIsArray($paths); + $this->assertEmpty($paths); + } + + public function testEmptyArrayIsReturnedWhenGroupNotFound() + { + $paths = ServiceProvider::pathsToPublish(null, 'nonexistent_group'); + + $this->assertIsArray($paths); + $this->assertEmpty($paths); + } } class ServiceProviderForTestingOne extends ServiceProvider