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
113 changes: 112 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,34 @@ jobs:

name: PHP${{ matrix.php }} - Laravel${{ matrix.laravel }}

services:
mysql:
image: mysql:8
env:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_DATABASE: nestedset
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=5

postgres:
image: postgres:16
env:
POSTGRES_DB: nestedset
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready"
--health-interval=10s
--health-timeout=5s
--health-retries=5

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -35,6 +63,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pdo_sqlite, pdo_mysql, pdo_pgsql
coverage: none
tools: composer:v2

Expand All @@ -43,5 +72,87 @@ jobs:
composer require "illuminate/support:${{ matrix.laravel }}" "illuminate/database:${{ matrix.laravel }}" "illuminate/events:${{ matrix.laravel }}" --no-update
composer update -o --quiet --prefer-dist

- name: Execute Unit Tests
- name: Tests (SQLite)
run: composer test
env:
DB_CONNECTION: testbench

- name: Tests (MySQL)
run: composer test
env:
DB_CONNECTION: mysql
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_DATABASE: nestedset
DB_USERNAME: root
DB_PASSWORD: ''

- name: Tests (PostgreSQL)
run: composer test
env:
DB_CONNECTION: pgsql
DB_HOST: 127.0.0.1
DB_PORT: 5432
DB_DATABASE: nestedset
DB_USERNAME: postgres
DB_PASSWORD: password

static-analysis:
runs-on: ubuntu-latest

timeout-minutes: 15

env:
COMPOSER_NO_INTERACTION: 1

name: Static Analysis

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: none
tools: composer:v2

- name: Install dependencies
run: composer update -o --quiet --prefer-dist

- name: Run Pint
run: composer lint

- name: Run PHPStan
run: composer analyse

coverage:
runs-on: ubuntu-latest

timeout-minutes: 15

env:
COMPOSER_NO_INTERACTION: 1

name: Coverage

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: pdo_sqlite
coverage: pcov
tools: composer:v2

- name: Install dependencies
run: composer update -o --quiet --prefer-dist

- name: Execute tests with coverage
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml
env:
DB_CONNECTION: testbench
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Changelog

All notable changes to `lunarphp/nestedset` are documented here. The format is
based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]

### Fixed

- `NestedSet::isNode()` always returned `false` for genuine nodes because it
inspected object properties instead of used traits. It now uses
`class_uses_recursive()`.

### Added

- Native PHP type declarations across the library (PHP 8.3+).
- Laravel Pint for code style.
- Larastan static analysis (level 5) with a baseline for pre-existing findings.
- Test suite now runs against SQLite, MySQL and PostgreSQL in CI, plus a code
coverage job.
- `CONTRIBUTING.md` and this changelog.

### Changed

- Test suite migrated from a hand-rolled Capsule bootstrap to Orchestra
Testbench, exercising the package through a real Laravel application
(service provider registration and Blueprint macros are now covered).

## Fork

`lunarphp/nestedset` is a fork of
[`kalnoy/nestedset`](https://github.com/lazychaser/laravel-nestedset) by
Alexander Kalnoy, maintained for Lunar and kept current with modern Laravel
(12 and 13) and PHP 8.3+. For the history prior to the fork, see the upstream
project.
52 changes: 52 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Contributing

Thanks for contributing to `lunarphp/nestedset`.

## Getting started

```
git clone https://github.com/lunarphp/nestedset
cd nestedset
composer install
```

## Before opening a pull request

Run the full quality suite locally and make sure it passes:

```
composer lint # code style (Laravel Pint)
composer analyse # static analysis (Larastan)
composer test # test suite
```

`composer format` will fix most style issues automatically.

## Tests

The suite runs against SQLite by default. To run it against MySQL or
PostgreSQL, set the connection via environment variables — for example using
Docker:

```
docker run -d --rm -e POSTGRES_DB=nestedset -e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=password -p 5432:5432 postgres:16

DB_CONNECTION=pgsql DB_HOST=127.0.0.1 DB_PORT=5432 DB_DATABASE=nestedset \
DB_USERNAME=postgres DB_PASSWORD=password composer test
```

The CI workflow exercises PHP 8.3/8.4, Laravel 12/13 and all three database
engines, so changes that depend on engine-specific behaviour should be covered
by a test.

## Static analysis

New code is analysed at PHPStan level 5. Pre-existing findings are captured in
`phpstan-baseline.neon`; please do not add to the baseline — fix new findings
instead.

## Reporting bugs

Open an issue with a minimal reproduction (model definition, schema and the
sequence of calls that triggers the problem).
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ by Alexander Kalnoy, kept current for modern Laravel.
- [Helper methods](#helper-methods)
- [Checking consistency](#checking-consistency)
- [Scoping](#scoping)
- [Contributing](#contributing)
- [License](#license)

## What are nested sets?
Expand Down Expand Up @@ -659,6 +660,21 @@ After [setting up your model](#the-model), fix the tree to populate `_lft` and
MyModel::fixTree();
```

## Contributing

Contributions are welcome. The test suite runs against SQLite, MySQL and
PostgreSQL:

```
composer test # run the test suite
composer lint # check code style (Laravel Pint)
composer format # fix code style
composer analyse # run static analysis (Larastan)
```

See [CONTRIBUTING.md](CONTRIBUTING.md) for details, and
[CHANGELOG.md](CHANGELOG.md) for release notes.

## License

Released under the [MIT license](https://opensource.org/licenses/MIT).
Expand Down
19 changes: 18 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@
"Lunar\\Nestedset\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Lunar\\Nestedset\\Tests\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "^11.0"
"phpunit/phpunit": "^11.0",
"laravel/pint": "^1.29",
"orchestra/testbench": "^10.0|^11.0",
"larastan/larastan": "^3.0"
},
"minimum-stability": "stable",
"prefer-stable": true,
Expand All @@ -46,6 +54,15 @@
"scripts": {
"test": [
"@php ./vendor/bin/phpunit"
],
"format": [
"@php ./vendor/bin/pint"
],
"lint": [
"@php ./vendor/bin/pint --test"
],
"analyse": [
"@php ./vendor/bin/phpstan analyse"
]
}
}
Loading
Loading