Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Tests

on:
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5

strategy:
fail-fast: true
matrix:
php: ['8.2', '8.3', '8.4']

name: PHP ${{ matrix.php }}

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install dependencies
uses: ramsey/composer-install@v3

- name: List installed dependencies
run: composer show -D

- name: Execute tests
run: vendor/bin/phpunit
10 changes: 9 additions & 1 deletion src/BreadcrumbsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class BreadcrumbsServiceProvider extends ServiceProvider implements DeferrableProvider
{
private bool $breadcrumbsRegistered = false;

public function provides(): array
{
return [Manager::class];
Expand All @@ -32,6 +34,12 @@ public function boot(): void

public function registerBreadcrumbs(): void
{
if ($this->breadcrumbsRegistered) {
return;
}

$this->breadcrumbsRegistered = true;

$files = config('breadcrumbs.files');

if (! $files) {
Expand All @@ -46,7 +54,7 @@ public function registerBreadcrumbs(): void
$breadcrumbs = $this->app->make(Manager::class);

foreach ((array) $files as $file) {
require $file;
require_once $file;
}
}
}
26 changes: 26 additions & 0 deletions tests/BreadcrumbsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,30 @@ public function test_manager_is_a_singleton(): void

$this->assertSame($a, $b);
}

// -------------------------------------------------------------------------
// registerBreadcrumbs() — double-boot guard
// -------------------------------------------------------------------------

public function test_register_breadcrumbs_called_twice_does_not_throw(): void
{
// Simulates DeferrableProvider double-boot: the service provider's boot()
// is triggered a second time when a deferred provider is resolved mid-boot.
// Both require_once and the $breadcrumbsRegistered guard must prevent re-execution.
$provider = new BreadcrumbsServiceProvider($this->app);

$file = tempnam(sys_get_temp_dir(), 'breadcrumbs_test_').'.php';
file_put_contents($file, '<?php Breadcrumbs::for("double-boot-test", fn($t) => $t->push("Test", "/"));');

try {
config(['breadcrumbs.files' => $file]);

$provider->registerBreadcrumbs();
$provider->registerBreadcrumbs(); // second call must be a no-op

$this->assertTrue(Breadcrumbs::exists('double-boot-test'));
} finally {
unlink($file);
}
Comment on lines +289 to +301

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tempnam() already creates a file; appending '.php' produces a second filename and leaves the original temp file behind, so this test leaks a temp file on disk. Use the path returned by tempnam() directly (no suffix) or rename/unlink the original temp file so both are cleaned up in the finally block.

Copilot uses AI. Check for mistakes.
}
}
Loading