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
39 changes: 0 additions & 39 deletions .github/workflows/php.yml

This file was deleted.

43 changes: 43 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Tests

on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]

jobs:
test:
name: PHP 8.5 - Laravel 12
runs-on: ubuntu-latest

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
extensions: sockets, bcmath, dom, curl, libxml, mbstring, zip, pcov
coverage: pcov

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer update --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: composer run phpunit

- name: Check code style
run: composer run checkstyle
56 changes: 28 additions & 28 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests');
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests');

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'],
'new_with_parentheses' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
'no_empty_comment' => true,
'no_leading_import_slash' => true,
'no_trailing_comma_in_singleline' => true,
'no_unused_imports' => true,
'ordered_imports' => ['imports_order' => null, 'sort_algorithm' => 'alpha'],
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'],
'new_with_parentheses' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
'no_empty_comment' => true,
'no_leading_import_slash' => true,
'no_trailing_comma_in_singleline' => true,
'no_unused_imports' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true],
'phpdoc_align' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_to_comment' => true,
'psr_autoloading' => true,
'return_type_declaration' => ['space_before' => 'none'],
'blank_lines_before_namespace' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
'whitespace_after_comma_in_array' => true,
'phpdoc_align' => ['align' => 'left'],
'phpdoc_no_empty_return' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_to_comment' => true,
'psr_autoloading' => true,
'return_type_declaration' => ['space_before' => 'none'],
'single_quote' => true,
'space_after_semicolon' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'trim_array_spaces' => true,
'whitespace_after_comma_in_array' => true,
])
->setFinder($finder);
->setFinder($finder);
30 changes: 0 additions & 30 deletions .travis.yaml

This file was deleted.

27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM composer:2

# Install build dependencies
RUN apk add --no-cache $PHPIZE_DEPS linux-headers

# Install PCOV (for fast code coverage)
RUN pecl install pcov && docker-php-ext-enable pcov

# Install Xdebug (for debugging when needed)
RUN pecl install xdebug && docker-php-ext-enable xdebug

# Clean up
RUN apk del $PHPIZE_DEPS linux-headers

# Configure PCOV (enabled by default for tests)
RUN echo "pcov.enabled=1" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini

# Configure Xdebug (disabled by default, enable when debugging)
RUN echo "xdebug.mode=off" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# Disable Xdebug by default to use PCOV for coverage
RUN mv /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini.disabled

WORKDIR /app
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"issues": "https://github.com/softonic/rest-api-nested-resources/issues"
},
"require": {
"php": ">=8.3"
"php": ">=8.5"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"laravel/framework": "^11.0",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^11.0",
"rector/rector": "^1.0",
"laravel/framework": "^12.0",
"mockery/mockery": "^1.6",
"phpunit/phpunit": "^12.0",
"rector/rector": "^2.0",
"squizlabs/php_codesniffer": "^3"
},
"autoload": {
Expand All @@ -36,10 +36,10 @@
],
"phpunit": "phpunit",
"checkstyle": [
"PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --diff --allow-risky=yes",
"PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --diff --dry-run --allow-risky=yes",
"rector process"
],
"fix-checkstyle": [
"fix-cs": [
"@php-cs-fixer",
"@rector"
],
Expand Down
30 changes: 15 additions & 15 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
services:
php:
build: .
volumes:
- ./:/app
image: composer:2.2

install:
build: .
volumes:
- ./:/app
image: composer:2.2
command: composer install --ignore-platform-req=ext-sockets
command: sh -c "git config --global --add safe.directory /app && composer install"

update:
phpunit:
build: .
volumes:
- ./:/app
image: composer:2.2
command: composer update --ignore-platform-req=ext-sockets
command: sh -c "git config --global --add safe.directory /app && composer run phpunit"

phpunit:
tests:
build: .
volumes:
- ./:/app
image: composer:2.2
command: composer phpunit
command: sh -c "git config --global --add safe.directory /app && composer run tests"

test:
fixcs:
build: .
volumes:
- ./:/app
image: composer:2.2
command: composer run tests
command: sh -c "git config --global --add safe.directory /app && composer run fix-cs"

fix-cs:
debug:
build: .
volumes:
- ./:/app
image: composer:2.2
command: composer run fix-cs
command: sh -c "mv /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini.disabled /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 2>/dev/null || true; php -dxdebug.mode=debug -dpcov.enabled=0 $@"
33 changes: 21 additions & 12 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true">

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
failOnRisky="true"
failOnWarning="true"
cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="All">
<directory>./tests</directory>
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
<coverage>
<report>
<clover outputFile="build/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
</phpunit>
4 changes: 2 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
__DIR__ . '/tests',
])
->withImportNames()
->withPhpSets(php83: true)
->withPhpSets(php85: true)
->withSets(
[
PHPUnitSetList::PHPUNIT_100,
PHPUnitSetList::PHPUNIT_120,
PHPUnitSetList::PHPUNIT_110,
]
)
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/SubstituteBindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SubstituteBindings
/**
* Create a new bindings substitutor.
*/
public function __construct(protected Registrar $router, Container $container = null)
public function __construct(protected Registrar $router, ?Container $container = null)
{
$this->container = $container ?: new Container();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Traits/PathParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function getPathParameters(Request $request): array
->parameters();

$pathParametersKeys = array_map(
fn ($key) => 'id_' . $key,
fn (int|string $key) => 'id_' . $key,
array_keys($pathParameters)
);

Expand Down
5 changes: 3 additions & 2 deletions src/Http/Traits/SplitPutPatchVerbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\Facades\App;
use ReflectionClass;
use ReflectionMethod;
use ReflectionParameter;
use Softonic\RestApiNestedResources\Models\MultiKeyModel;

trait SplitPutPatchVerbs
Expand Down Expand Up @@ -35,11 +36,11 @@ public function update(Request $request)

private function bindModelParameters(array $parameters): array
{
$methodArguments = (new ReflectionMethod(self::class, 'modify'))->getParameters();
$methodArguments = new ReflectionMethod(self::class, 'modify')->getParameters();

$modelMethodArguments = array_filter(
$methodArguments,
function ($argument): bool {
function (ReflectionParameter $argument): bool {
if ($argument->getType() && !$argument->getType()->isBuiltin()) {
$class = new ReflectionClass($argument->getType()->getName());

Expand Down
2 changes: 1 addition & 1 deletion src/Models/MultiKeyModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function getGeneratedIds(array $values, ?array $generatedIdsConfig
return $generatedIds;
}

public static function generateIdForField(string $field, array $values, array $generatedIds = null): string
public static function generateIdForField(string $field, array $values, ?array $generatedIds = null): string
{
$generatedIds ??= static::$generatedIds;

Expand Down