Skip to content

Commit

Permalink
Add support for Laravel 11 (#81)
Browse files Browse the repository at this point in the history
* Add Laravel 11 dependency

* Remove/replace broken links

* Tweak package versions

* Attempt to support PHPUnit v10 and v8 simultaneously

* Drop support of PHPUnit v8

Dropping support of PHPUnit v8 means dropping support of PHP 7.2 which means dropping support of Laravel v6 and v7

* Update workflow

* Update tests and upgrade phpunit.xml

* Update upgrade guide

* Attempt to use newer GH actions

* Configure Codecov

* Formatting

* Remove unneeded test case

IDE Helper-related issue was patched in v2.9.1, which only supported Laravel 7+. Since we dropped older Laravel versions, we can remove this.

@see barryvdh/laravel-ide-helper#627

* Improve phrasing

* Whoops

* Rearrange
  • Loading branch information
shengslogar authored Mar 12, 2024
1 parent b1e766f commit 88e8f01
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 93 deletions.
39 changes: 14 additions & 25 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,32 @@ jobs:
phpunit:
strategy:
matrix:
php: [ 8.2, 8.1, 8.0, 7.4, 7.3, 7.2 ]
laravel: [ 10.*, 9.*, 8.*, 7.*, 6.* ]
php: [ 8.2, 8.1, 8.0, 7.4, 7.3 ]
laravel: [ 11.*, 10.*, 9.*, 8.* ]
os: [ ubuntu-latest, windows-latest ]

# Unsupported combinations
exclude:
- laravel: 11.*
php: 8.1
- laravel: 11.*
php: 8.0
- laravel: 11.*
php: 7.4
- laravel: 11.*
php: 7.3

- laravel: 10.*
php: 8.0
- laravel: 10.*
php: 7.4
- laravel: 10.*
php: 7.3
- laravel: 10.*
php: 7.2

- laravel: 9.*
php: 7.4
- laravel: 9.*
php: 7.3
- laravel: 9.*
php: 7.2

- laravel: 8.*
php: 7.2

- laravel: 7.*
php: 8.2
- laravel: 7.*
php: 8.1
- laravel: 7.*
php: 8.0

- laravel: 6.*
php: 8.2
- laravel: 6.*
php: 8.1
- laravel: 6.*
php: 8.0

# Continue running through matrix even if one combination fails
fail-fast: false
Expand All @@ -61,7 +49,7 @@ jobs:

steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -81,6 +69,7 @@ jobs:
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml

- name: Report coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: build/logs/clover.xml
58 changes: 30 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

A simple Laravel-style way to create breadcrumbs.

This project is the [official fork](https://newsroom.diglactic.com/laravel-breadcrumbs/) of the fantastically original
[Laravel Breadcrumbs by Dave James Miller](https://github.com/davejamesmiller/laravel-breadcrumbs) and wouldn't have
been possible without
[a bunch of awesome day-one contributors](https://github.com/davejamesmiller/laravel-breadcrumbs/graphs/contributors).
This project is the official fork of the fantastically
original [Laravel Breadcrumbs by Dave James Miller](https://github.com/davejamesmiller/laravel-breadcrumbs) and wouldn't
have been possible
without [a bunch of awesome day-one contributors](https://github.com/davejamesmiller/laravel-breadcrumbs/graphs/contributors).
Thanks, all!


Expand All @@ -39,9 +39,10 @@ Compatibility Chart

| Laravel | Laravel Breadcrumbs |
|---------|---------------------|
| 10.x | 8.x |
| 9.x | 8.x |
| 8.x | 8.x |
| 11.x | 9.x |
| 10.x | 9.x |
| 9.x | 9.x |
| 8.x | 9.x |
| 7.x | 8.x |
| 6.x | 8.x |

Expand Down Expand Up @@ -117,7 +118,7 @@ The possible values are:
- `breadcrumbs::bootstrap4`[Bootstrap 4](https://getbootstrap.com/docs/4.0/components/breadcrumb/)
- `breadcrumbs::bulma`[Bulma](https://bulma.io/documentation/components/breadcrumb/)
- `breadcrumbs::foundation6`[Foundation 6](https://get.foundation/sites/docs/breadcrumbs.html)
- `breadcrumbs::json-ld`[JSON-LD Structured Data](https://developers.google.com/search/docs/data-types/breadcrumbs)
- `breadcrumbs::json-ld`[JSON-LD Structured Data](https://developers.google.com/search/docs/appearance/structured-data/breadcrumb)
- `breadcrumbs::materialize`[Materialize](https://materializecss.com/breadcrumbs.html)
- `breadcrumbs::tailwind`[Tailwind CSS](https://tailwindcss.com/)
- `breadcrumbs::uikit`[UIkit](https://getuikit.com/docs/breadcrumb)
Expand All @@ -141,8 +142,8 @@ parameters:
{{ Breadcrumbs::render('category', $category) }}
```

See the [Outputting Breadcrumbs](#outputting-breadcrumbs) section for other output options, and see
[Route-Bound Breadcrumbs](#route-bound-breadcrumbs) for a way to link breadcrumb names to route names automatically.
See the [Outputting Breadcrumbs](#outputting-breadcrumbs) section for other output options, and
see [Route-Bound Breadcrumbs](#route-bound-breadcrumbs) for a way to link breadcrumb names to route names automatically.


Defining Breadcrumbs
Expand Down Expand Up @@ -236,8 +237,9 @@ Breadcrumbs::for('post', function (BreadcrumbTrail $trail, Post $post) {
});
```

The `$post` object (probably an Eloquent [Model](https://laravel.com/api/10.x/Illuminate/Database/Eloquent/Model.html),
but could be anything) would be passed in from the view:
The `$post` object (probably an
Eloquent [Model](https://laravel.com/api/master/Illuminate/Database/Eloquent/Model.html), but could be anything) would
be passed in from the view:

```blade
{{ Breadcrumbs::render('post', $post) }}
Expand Down Expand Up @@ -348,7 +350,7 @@ you to make edits directly.

#### View data

The view will receive a [Collection](https://laravel.com/api/10.x/Illuminate/Support/Collection.html)
The view will receive a [Collection](https://laravel.com/api/master/Illuminate/Support/Collection.html)
called `$breadcrumbs`.

Each breadcrumb is an [object](https://www.php.net/manual/en/language.types.object.php) with the following keys:
Expand Down Expand Up @@ -399,7 +401,8 @@ Or with a parameter:
Structured Data
---------------

To render breadcrumbs as JSON-LD [structured data](https://developers.google.com/search/docs/data-types/breadcrumbs)
To render breadcrumbs as
JSON-LD [structured data](httpshttps://developers.google.com/search/docs/appearance/structured-data/breadcrumb)
(usually for SEO reasons), use `Breadcrumbs::view()` to render the `breadcrumbs::json-ld` template in addition to the
normal one. For example:

Expand Down Expand Up @@ -460,7 +463,7 @@ Route::name('home')->get('/', 'HomeController@index');
Route::name('post')->get('/post/{id}', 'PostController@show');
```

For more details, see [Named Routes](https://laravel.com/docs/10.x/routing#named-routes) in the Laravel documentation.
For more details, see [Named Routes](https://laravel.com/docs/routing#named-routes) in the Laravel documentation.

### Name your breadcrumbs to match

Expand All @@ -485,8 +488,8 @@ Breadcrumbs::for('post', function (BreadcrumbTrail $trail, Post $post) {
});
```

To add breadcrumbs to a [custom 404 Not Found page](https://laravel.com/docs/10.x/errors#custom-http-error-pages), use
the name `errors.404`:
To add breadcrumbs to a [custom 404 Not Found page](https://laravel.com/docs/errors#custom-http-error-pages), use the
name `errors.404`:

```php
Breadcrumbs::for('errors.404', function (BreadcrumbTrail $trail) {
Expand Down Expand Up @@ -576,7 +579,7 @@ Breadcrumbs::for('post', function (BreadcrumbTrail $trail, Post $post) { // <--

This makes your code less verbose and more efficient by only loading the post from the database once.

For more details see [Route Model Binding](https://laravel.com/docs/10.x/routing#route-model-binding) in the Laravel
For more details see [Route Model Binding](https://laravel.com/docs/routing#route-model-binding) in the Laravel
documentation.

### Resourceful controllers
Expand Down Expand Up @@ -641,7 +644,7 @@ Breadcrumbs::for('photo.edit', function (BreadcrumbTrail $trail, Photo $photo) {
});
```

For more details see [Resource Controllers](https://laravel.com/docs/10.x/controllers#resource-controllers) in the
For more details see [Resource Controllers](https://laravel.com/docs/controllers#resource-controllers) in the
Laravel documentation.

(Related FAQ: [Why is there no Breadcrumbs::resource() method?](#why-is-there-no-breadcrumbsresource-method).)
Expand Down Expand Up @@ -742,7 +745,7 @@ Breadcrumbs::after(function (BreadcrumbTrail $trail) {
```

For more advanced filtering, use `Breadcrumbs::generate()` and Laravel's
[Collection class](https://laravel.com/api/10.x/Illuminate/Support/Collection.html) methods instead:
[Collection class](https://laravel.com/api/master/Illuminate/Support/Collection.html) methods instead:

```php
<?php
Expand All @@ -754,8 +757,8 @@ $current = Breadcrumbs::generate()->where('current', '!==', false)->last();

### Switching views at runtime

You can use `Breadcrumbs::view()` in place of `Breadcrumbs::render()` to render a template other than the
[default one](#3-style):
You can use `Breadcrumbs::view()` in place of `Breadcrumbs::render()` to render a template other than
the [default one](#3-style):

```blade
{{ Breadcrumbs::view('partials.breadcrumbs2', 'category', $category) }}
Expand Down Expand Up @@ -846,7 +849,7 @@ class MyServiceProvider extends ServiceProvider

### Dependency injection

You can use [dependency injection](https://laravel.com/docs/10.x/providers#the-boot-method) to access the `Manager`
You can use [dependency injection](https://laravel.com/docs/providers#the-boot-method) to access the `Manager`
instance if you prefer, instead of using the `Breadcrumbs::` facade:

```php
Expand All @@ -866,9 +869,8 @@ class MyServiceProvider extends ServiceProvider

### Macros

The breadcrumbs `Manager` class is
[macroable](https://unnikked.ga/understanding-the-laravel-macroable-trait-dab051f09172), so you can add your own
methods. For example:
The breadcrumbs `Manager` class is [macroable](https://tighten.com/insights/the-magic-of-laravel-macros/), so you can
add your own methods. For example:

```php
<?php
Expand Down Expand Up @@ -912,7 +914,7 @@ FAQ
### Why is there no `Breadcrumbs::resource()` method?

A few people have suggested adding `Breadcrumbs::resource()` to match
[`Route::resource()`](https://laravel.com/docs/10.x/controllers#resource-controllers), but no one has come up with a
[`Route::resource()`](https://laravel.com/docs/controllers#resource-controllers), but no one has come up with a
good implementation that a) is flexible enough to deal with translations, nested resources, etc., and b) isn't overly
complex as a result.

Expand Down Expand Up @@ -1104,6 +1106,7 @@ The following files will need to be updated to run tests against a new Laravel v
- [`composer.json`](composer.json)
- `laravel/framework` (Laravel versions)
- `php` (minimum PHP version)
- Other dependencies (prefer bumping to the highest-available versions that work for all Laravel/PHP combinations)

- [`tests.yml`](.github/workflows/tests.yml)
- `jobs.phpunit.strategy.matrix.laravel` (Laravel versions)
Expand All @@ -1114,7 +1117,6 @@ And the following documentation, as needed:

- [`README.md`](README.md)
- [Compatibility Chart](#compatibility-chart)
- All links to `https://laravel.com/docs/*` and `https://laravel.com/api/*`

- [`UPGRADE.md`](UPGRADE.md)
- Add new section detailing any breaking package changes
Expand Down
7 changes: 6 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Upgrade Guide

## Upgrading to 9.x from 8.x

`9.x` drops support for Laravel v6 and v7 to support PHPUnit v10. There are no other breaking changes. If you're on
Laravel v8+, you may simply re-run `composer require diglactic/laravel-breadcrumbs`.

## Upgrading to 8.x from 7.x

`8.x` introduces a single breaking change over `7.x` by passing request parameters injected by middleware into
Expand Down Expand Up @@ -27,7 +32,7 @@ to this repository. Note that this library requires at least Laravel 6.

Begin by swapping libraries via Composer:

```shell script
```shell
composer remove davejamesmiller/laravel-breadcrumbs
composer require diglactic/laravel-breadcrumbs
```
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
],
"license": "MIT",
"require": {
"php": "^7.2 || ^8.0",
"php": "^7.3 || ^8.0",
"facade/ignition-contracts": "^1.0",
"laravel/framework": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0"
"laravel/framework": "^8.0 || ^9.0 || ^10.0 || ^11.0"
},
"require-dev": {
"orchestra/testbench": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0",
"phpunit/phpunit": "^8.5 || ^9.5",
"php-coveralls/php-coveralls": "^2.4",
"spatie/phpunit-snapshot-assertions": "^2.2 || ^4.2"
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"phpunit/phpunit": "^9.5 || ^10.5",
"php-coveralls/php-coveralls": "^2.7",
"spatie/phpunit-snapshot-assertions": "^4.2 || ^5.1"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
14 changes: 7 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutChangesToGlobalState="true"
Expand All @@ -15,19 +17,17 @@
stopOnFailure="false"
verbose="true"
>

<!-- List of files with tests inside -->
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix="Test.php">tests/</directory>
</testsuite>
</testsuites>

<!-- List of source files for code coverage checker -->
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

</include>
</coverage>
</phpunit>
1 change: 0 additions & 1 deletion tests/CustomGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ public function generate(array $callbacks, array $before, array $after, string $
{
return new Collection(['custom-generator']);
}

}
4 changes: 2 additions & 2 deletions tests/DeferredLoadingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected function getEnvironmentSetUp($app): void
$app->config->set('breadcrumbs.files', [__DIR__ . '/routes/should-not-be-loaded.php']);
}

protected function resolveApplicationConsoleKernel($app)
protected function resolveApplicationConsoleKernel($app): void
{
// Disable the console kernel because it calls loadDeferredProviders()
// which defeats the purpose of this test
Expand All @@ -36,7 +36,7 @@ public function testDeferredLoading()

class DisabledConsoleKernel extends \Orchestra\Testbench\Foundation\Console\Kernel
{
public function bootstrap()
public function bootstrap(): void
{
//
}
Expand Down
21 changes: 2 additions & 19 deletions tests/FacadePhpDocTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Diglactic\Breadcrumbs\Breadcrumbs;
use Diglactic\Breadcrumbs\Manager;
use Generator;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use ReflectionClass;
Expand All @@ -13,7 +14,7 @@

class FacadePhpDocTest extends TestCase
{
public function tags()
public static function tags(): Generator
{
$code = file_get_contents(__DIR__ . '/../src/Manager.php');

Expand All @@ -38,24 +39,6 @@ public function tags()
}
}

/** @dataProvider tags */
public function testFullyQualifiedClassNames($class, $line)
{
// IDE Helper (v2.4.3) doesn't rewrite class names to FQCNs, so make sure only
// fully qualified class names and built-in types are used in the Manager class
// ----------------------------------------------------------------------------
// Note: we'll eventually need to update with `assertMatchesRegularExpression`.
// This is currently slated for removal in PHPUnit 10, but hasn't been enforced
// yet. Laravel 10 supports PHPUnit 10 and 9, so we've stuck with v9 for now.
// @see https://github.com/laravel/framework/blob/10.x/composer.json#L101
// @see https://github.com/sebastianbergmann/phpunit/issues/4086
$this->assertRegExp(
'/^(\\\\.*|array|object|bool|callable|int|mixed|null|string|void)$/',
$class,
"Must use fully qualified class names in BreadcrumbsManger PhpDoc: $line"
);
}

public function testBreadcrumbsFacade()
{
$class = new ReflectionClass(Manager::class);
Expand Down
Loading

0 comments on commit 88e8f01

Please sign in to comment.