Skip to content

Commit

Permalink
Fix: latest release breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
awcodes committed Jan 27, 2024
1 parent cdb950e commit f131812
Show file tree
Hide file tree
Showing 23 changed files with 710 additions and 84 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ name: "Build Assets"

on:
pull_request:
branches:
- 2.x
types:
- closed
paths:
- 'resources/views/**.php'
- 'resources/js/**.js'
- 'resources/css/**.css'

jobs:
if_merged:
Expand All @@ -12,6 +18,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Setup Node
uses: actions/setup-node@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ name: "Fix PHP code styling"

on:
pull_request:
branches:
- 2.x
types:
- closed
paths:
- '**.php'

jobs:
if_merged:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/[email protected]
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: "Tests"

on:
pull_request:
types:
- opened
branches:
- 2.x
paths:
- '**.php'
- '.github/workflows/run-tests.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'

jobs:
run-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [8.2, 8.1]
laravel: [10.*]
dependency-version: [prefer-stable]
include:
- laravel: 10.*
testbench: 8.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

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

- name: "Cache dependencies"
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, pdo, pdo_sqlite
coverage: none

- name: "Install dependencies"
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "filament/filament" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: "Execute tests"
run: ./vendor/bin/pest
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
],
"require": {
"php": "^8.1",
"filament/filament": "^3.0",
"filament/filament": "^3.1",
"spatie/laravel-package-tools": "^1.13.5"
},
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^7.0",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-faker": "^2.0",
"pestphp/pest-plugin-laravel": "^2.0",
"pestphp/pest-plugin-livewire": "^2.0",
"phpunit/phpunit": "^10.0",
Expand All @@ -37,7 +38,8 @@
},
"autoload-dev": {
"psr-4": {
"Awcodes\\FilamentTableRepeater\\Tests\\": "tests"
"Awcodes\\FilamentTableRepeater\\Tests\\": "tests/src",
"Awcodes\\FilamentTableRepeater\\Tests\\Database\\Factories\\": "tests/database/factories"
}
},
"scripts": {
Expand Down
33 changes: 10 additions & 23 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
backupStaticProperties="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
verbose="true"
cacheDirectory=".phpunit.cache"
>
<testsuites>
<testsuite name="Awcodes Test Suite">
<directory>tests</directory>
<testsuite name="Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<php>
<env name="APP_ENV" value="self-testing" />
<env name="APP_KEY" value="base64:4bHj7CIUiEzDxa9oAS3bncF3L5czGQHhyytRB7QAbUs=" />
<env name="DB_CONNECTION" value="testing" />
</php>
</phpunit>
21 changes: 11 additions & 10 deletions resources/views/components/table-repeater.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@php
use Filament\Forms\Components\Actions\Action;
$containers = $getChildComponentContainers();
$addAction = $getAction($getAddActionName());
Expand All @@ -20,14 +21,21 @@
$emptyLabel = $getEmptyLabel();
$hasActions = $reorderAction->isVisible() || $cloneAction->isVisible() || $deleteAction->isVisible() || $moveUpAction->isVisible() || $moveDownAction->isVisible() || count($visibleExtraItemActions);
$visibleExtraItemActions = [];
foreach ($containers as $uuid => $row) {
$visibleExtraItemActions = array_filter(
$extraItemActions,
fn (Action $action): bool => $action(['item' => $uuid])->isVisible(),
);
}
$hasActions = $reorderAction->isVisible()
|| $cloneAction->isVisible()
|| $deleteAction->isVisible()
|| $moveUpAction->isVisible()
|| $moveDownAction->isVisible()
|| filled($visibleExtraItemActions);
@endphp

<x-dynamic-component :component="$getFieldWrapperView()" :field="$field">
Expand All @@ -45,7 +53,7 @@
]) }}
>
@if (count($containers) || $emptyLabel !== false)
<ul @class([
<div @class([
'filament-table-repeater-container rounded-xl relative ring-1 ring-gray-950/5 dark:ring-white/20',
'sm:ring-gray-950/5 dark:sm:ring-white/20' => ! $hasContainers && $breakPoint === 'sm',
'md:ring-gray-950/5 dark:md:ring-white/20' => ! $hasContainers && $breakPoint === 'md',
Expand All @@ -55,7 +63,7 @@
])>
<table class="w-full">
<thead @class([
'sr-only' => $hasHiddenHeader,
'filament-table-repeater-header-hidden sr-only' => $hasHiddenHeader,
'filament-table-repeater-header rounded-t-xl overflow-hidden border-b border-gray-950/5 dark:border-white/20' => ! $hasHiddenHeader,
])>
<tr class="text-xs md:divide-x md:divide-gray-950/5 dark:md:divide-white/20">
Expand Down Expand Up @@ -127,13 +135,6 @@ class="filament-table-repeater-rows-wrapper divide-y divide-gray-950/5 dark:divi
>
@if (count($containers))
@foreach ($containers as $uuid => $row)
@php
$itemLabel = $getItemLabel($uuid);
$visibleExtraItemActions = array_filter(
$extraItemActions,
fn (Action $action): bool => $action(['item' => $uuid])->isVisible(),
);
@endphp
<tr
wire:key="{{ $this->getId() }}.{{ $row->getStatePath() }}.{{ $field::class }}.item"
x-sortable-item="{{ $uuid }}"
Expand Down
7 changes: 4 additions & 3 deletions src/Components/TableRepeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function columnWidths(array|Closure $widths = []): static
return $this;
}

public function emptyLabel(bool|string|Closure $label = null): static
public function emptyLabel(bool|string|Closure|null $label = null): static
{
$this->emptyLabel = $label;

Expand Down Expand Up @@ -98,6 +98,7 @@ public function getHeaders(): array
$customHeaders = $this->evaluate($this->headers);

foreach ($this->getChildComponents() as $field) {

if ($field instanceof Hidden || $field->isHidden()) {
continue;
}
Expand All @@ -109,7 +110,7 @@ public function getHeaders(): array
if (property_exists($field, 'isRequired') && is_bool($field->isRequired())) {
$isRequired = $field->isRequired();

if (property_exists($field, 'isMarkedAsRequired')) {
if (property_exists($field, 'isMarkedAsRequired') && is_bool($field->isMarkedAsRequired)) {
$isRequired = $field->isRequired() && $field->isMarkedAsRequired;
}
}
Expand Down Expand Up @@ -142,7 +143,7 @@ public function hideLabels(): static
return $this;
}

protected function shouldShowLabels(): bool
public function shouldShowLabels(): bool
{
return $this->evaluate($this->showLabels);
}
Expand Down
5 changes: 0 additions & 5 deletions tests/ExampleTest.php

This file was deleted.

40 changes: 0 additions & 40 deletions tests/TestCase.php

This file was deleted.

18 changes: 18 additions & 0 deletions tests/database/factories/PageFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Awcodes\FilamentTableRepeater\Tests\Database\Factories;

use Awcodes\FilamentTableRepeater\Tests\Models\Page;
use Illuminate\Database\Eloquent\Factories\Factory;

class PageFactory extends Factory
{
protected $model = Page::class;

public function definition(): array
{
return [
'seo' => null,
];
}
}
19 changes: 19 additions & 0 deletions tests/database/migrations/create_pages_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('pages', function (Blueprint $table) {
$table->id();

$table->longText('seo')->nullable();

$table->timestamps();
});
}
};
3 changes: 3 additions & 0 deletions tests/resources/views/fixtures/form.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
{{ $this->form }}
</div>
Loading

0 comments on commit f131812

Please sign in to comment.