From b3e9295c8e7883e9dc2c7fd800c0936deb319016 Mon Sep 17 00:00:00 2001 From: Simon Barrett Date: Sat, 7 Mar 2026 10:51:58 +0000 Subject: [PATCH] Modernise to Livewire 4: replace legacy getXProperty() and $listeners - Replace getRowsQueryProperty()/getRowsProperty() with #[Computed] attributes - Replace $listeners array with #[On('refreshTable')] attribute - Fix ArchTest broken toBeUsed() assertion for Pest 3 compatibility - Simplify CI workflow to single PHP 8.2 run matching actual requirements Closes #107 Co-Authored-By: Claude Opus 4.6 --- .github/workflows/run-tests.yml | 29 ++++------------------------- src/QueryBuilder.php | 17 +++++++++-------- src/TableBuilder.php | 15 +++++++++------ tests/ArchTest.php | 2 +- 4 files changed, 23 insertions(+), 40 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 060bc51..b2e28d0 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -8,20 +8,9 @@ on: jobs: test: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: true - matrix: - os: [ubuntu-latest, windows-latest] - php: [8.2, 8.1] - laravel: [10.*] - stability: [prefer-lowest, prefer-stable] - include: - - laravel: 10.* - testbench: 8.* - carbon: ^2.63 + runs-on: ubuntu-latest - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + name: Tests steps: - name: Checkout code @@ -30,22 +19,12 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php }} + php-version: 8.2 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 - run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update - composer update --${{ matrix.stability }} --prefer-dist --no-interaction - - - name: List Installed Dependencies - run: composer show -D + run: composer install --prefer-dist --no-interaction - name: Execute tests run: vendor/bin/pest --ci diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index b2b2a5f..c0790cb 100755 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -28,6 +28,8 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; +use Livewire\Attributes\Computed; +use Livewire\Attributes\On; use Livewire\Component; /** @@ -60,14 +62,11 @@ abstract class QueryBuilder extends Component public array $rowOptions = [10, 25, 50]; - protected $listeners = [ - 'refreshTable' => '$refresh', - ]; - - // protected array $queryString = ['perPage']; - abstract public function query(): Builder; + #[On('refreshTable')] + public function refreshTable(): void {} + public function booted(): void { $this->config(); @@ -98,7 +97,8 @@ public function showQueryBuilder(): bool return $this->enableQueryBuilder && count($this->conditions()); } - public function getRowsQueryProperty() + #[Computed] + public function rowsQuery() { /* @phpstan-ignore-next-line */ $query = $this @@ -135,7 +135,8 @@ public function getRowsQueryProperty() return $query; } - public function getRowsProperty() + #[Computed] + public function rows() { // return $this->cache(function () { return $this->applyPagination($this->rowsQuery); /* @phpstan-ignore-line */ diff --git a/src/TableBuilder.php b/src/TableBuilder.php index 30e228f..1d9b931 100755 --- a/src/TableBuilder.php +++ b/src/TableBuilder.php @@ -25,6 +25,8 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Arr; use Illuminate\Support\Str; +use Livewire\Attributes\Computed; +use Livewire\Attributes\On; use Livewire\Component; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; @@ -50,12 +52,11 @@ abstract class TableBuilder extends Component public array $rowOptions = [10, 25, 50]; - protected $listeners = [ - 'refreshTable' => '$refresh', - ]; - abstract public function query(): Builder; + #[On('refreshTable')] + public function refreshTable(): void {} + protected function queryString(): array { return [ @@ -78,7 +79,8 @@ public function config(): void // } - public function getRowsQueryProperty() + #[Computed] + public function rowsQuery() { $query = $this->query()->when($this->sortBy !== '', function ($query) { if (Str::contains($this->sortBy, '.')) { @@ -183,7 +185,8 @@ public function getRowsQueryProperty() * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - public function getRowsProperty() + #[Computed] + public function rows() { return $this->applyPagination($this->rowsQuery); /* @phpstan-ignore-line */ } diff --git a/tests/ArchTest.php b/tests/ArchTest.php index ccc19b2..d994e39 100644 --- a/tests/ArchTest.php +++ b/tests/ArchTest.php @@ -2,4 +2,4 @@ it('will not use debugging functions') ->expect(['dd', 'dump', 'ray']) - ->each->not->toBeUsed(); + ->each->not->toBeUsedIn('ACTTraining\QueryBuilder');