Skip to content

feat: Laravel 11 #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.1, 8.2]
php: [8.2, 8.3]
stability: [prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
Expand Down Expand Up @@ -42,4 +42,4 @@ jobs:
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit --verbose
run: vendor/bin/phpunit
21 changes: 21 additions & 0 deletions .github/workflows/lock-closed-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Lock Closed Issues

on:
schedule:
- cron: "0 0 * * *"

permissions:
issues: write

jobs:
action:
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
issue-inactive-days: "14"
#issue-comment: |
# This issue has been locked since it has been closed for more than 14 days.
issue-lock-reason: ""
process-only: "issues"
20 changes: 20 additions & 0 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: PHP Linting
on:
pull_request:
push:
branches:
- master
jobs:
phplint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: "laravel-pint"
uses: aglipanci/laravel-pint-action@2.0.0
with:
preset: laravel
verboseMode: true
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "fix: pint"

17 changes: 10 additions & 7 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ jobs:

strategy:
matrix:
php-version:
- "8.1"
php: [8.2, 8.3]

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

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand All @@ -41,8 +40,12 @@ jobs:
php-version: "${{ matrix.php-version }}"
tools: "cs2pr"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: "Run a static analysis with phpstan/phpstan"
run: "vendor/bin/phpstan --error-format=checkstyle | cs2pr"
- name: Execute type checking
run: vendor/bin/phpstan --configuration="phpstan.neon.dist"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor
/coverage
/.phpunit.cache
composer.phar
composer.lock
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
}
],
"require": {
"php": "^8.1",
"yajra/laravel-datatables-oracle": "^10.0",
"php": "^8.2",
"yajra/laravel-datatables-oracle": "^11.0",
"league/fractal": "^0.20.1"
},
"require-dev": {
"nunomaduro/larastan": "^2.4",
"orchestra/testbench": "^7.21"
"nunomaduro/larastan": "^2.9.2",
"orchestra/testbench": "^9"
},
"autoload": {
"psr-4": {
Expand All @@ -35,7 +35,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "10.0-dev"
"dev-master": "11.x-dev"
},
"laravel": {
"providers": [
Expand Down
21 changes: 6 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
5 changes: 0 additions & 5 deletions src/Commands/TransformerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class TransformerMakeCommand extends GeneratorCommand
*
* @param string $stub Contents of the stub
* @param string $name The class name
* @return string
*/
protected function replaceClass($stub, $name): string
{
Expand All @@ -53,8 +52,6 @@ protected function replaceClass($stub, $name): string

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub(): string
{
Expand All @@ -67,7 +64,6 @@ protected function getStub(): string
* Get the default namespace for the class.
*
* @param string $rootNamespace The root namespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace): string
{
Expand All @@ -78,7 +74,6 @@ protected function getDefaultNamespace($rootNamespace): string
* Get the destination class path.
*
* @param string $name Name of the class with namespace
* @return string
*/
protected function getPath($name): string
{
Expand Down
17 changes: 0 additions & 17 deletions src/FractalServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,8 @@

class FractalServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected bool $defer = false;

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot(): void
{
Expand All @@ -32,8 +23,6 @@ public function boot(): void

/**
* Publish datatables assets.
*
* @return void
*/
protected function publishAssets(): void
{
Expand All @@ -46,8 +35,6 @@ protected function publishAssets(): void

/**
* Register DataTables macro methods.
*
* @return void
*/
protected function registerMacro(): void
{
Expand All @@ -72,8 +59,6 @@ protected function registerMacro(): void

/**
* Register the service provider.
*
* @return void
*/
public function register(): void
{
Expand Down Expand Up @@ -104,8 +89,6 @@ public function register(): void

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides(): array
{
Expand Down
14 changes: 1 addition & 13 deletions src/Transformers/FractalTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@

class FractalTransformer
{
/**
* @var \League\Fractal\Manager
*/
protected Manager $fractal;

/**
* FractalTransformer constructor.
*
* @param \League\Fractal\Manager $fractal
*/
public function __construct(Manager $fractal)
{
Expand All @@ -28,16 +23,11 @@ public function __construct(Manager $fractal)

/**
* Transform output using the given transformer and serializer.
*
* @param array|\Illuminate\Support\Collection $output
* @param iterable $transformer
* @param SerializerAbstract|null $serializer
* @return array
*/
public function transform(
array|LaravelCollection $output,
iterable $transformer,
SerializerAbstract $serializer = null
?SerializerAbstract $serializer = null
): array {
if ($serializer !== null) {
$this->fractal->setSerializer($this->createSerializer($serializer));
Expand Down Expand Up @@ -68,7 +58,6 @@ function ($item_collector, $item_transformed) {
* Get or create transformer serializer instance.
*
* @param class-string|SerializerAbstract $serializer
* @return \League\Fractal\Serializer\SerializerAbstract
*/
protected function createSerializer(SerializerAbstract|string $serializer): SerializerAbstract
{
Expand All @@ -83,7 +72,6 @@ protected function createSerializer(SerializerAbstract|string $serializer): Seri
* Get or create transformer instance.
*
* @param \Closure|class-string|TransformerAbstract $transformer
* @return \Closure|\League\Fractal\TransformerAbstract
*/
protected function createTransformer(Closure|string|TransformerAbstract $transformer): Closure|TransformerAbstract
{
Expand Down
28 changes: 15 additions & 13 deletions tests/FractalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
namespace Yajra\DataTables\Fractal\Tests;

use Illuminate\Foundation\Testing\DatabaseTransactions;
use PHPUnit\Framework\Attributes\Test;
use Yajra\DataTables\Facades\DataTables;
use Yajra\DataTables\Fractal\Tests\Models\User;
use Yajra\DataTables\Fractal\Tests\Transformers\UserTransformer;

class FractalTest extends TestCase
{
use DatabaseTransactions;

/** @test */
#[Test]
public function it_can_transform_response()
{
$json = $this->getAjax('/users');
Expand All @@ -25,7 +27,7 @@ public function it_can_transform_response()
$this->assertIsString($json['data'][0]['name']);
}

/** @test */
#[Test]
public function it_works_with_closure()
{
$json = $this->getAjax('/closure');
Expand All @@ -45,20 +47,20 @@ protected function setUp(): void
parent::setUp();

$this->app['router']->get('/users', function () {
return datatables()->eloquent(User::query())
->setTransformer(UserTransformer::class)
->toJson();
return DataTables::eloquent(User::query())
->setTransformer(UserTransformer::class)
->toJson();
});

$this->app['router']->get('/closure', function () {
return datatables()->eloquent(User::query())
->setTransformer(function (User $user) {
return [
'id' => (int) $user->id,
'name' => $user->name,
];
})
->toJson();
return DataTables::eloquent(User::query())
->setTransformer(function (User $user) {
return [
'id' => (int) $user->id,
'name' => $user->name,
];
})
->toJson();
});
}
}
4 changes: 0 additions & 4 deletions tests/Transformers/UserTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

class UserTransformer extends TransformerAbstract
{
/**
* @param \Yajra\DataTables\Fractal\Tests\Models\User $user
* @return array
*/
public function transform(User $user): array
{
return [
Expand Down