Skip to content

Commit

Permalink
Merge pull request #29 from deligoez/add-laravel-11-support-and-php-8.3
Browse files Browse the repository at this point in the history
add laravel 11 support and php 8.3 - remove php 8.1 & laravel 9 support
  • Loading branch information
frkcn authored Jul 23, 2024
2 parents 93b79a2 + c274bb5 commit 4cf350c
Show file tree
Hide file tree
Showing 28 changed files with 234 additions and 273 deletions.
76 changes: 63 additions & 13 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,77 @@
name: types
name: tests

on:
push:
branches:
- main
paths:
- '**.php'
- 'composer.json'
- 'phpstan.neon.dist'
- composer.json
- .github/**
pull_request:
branches:
- main
paths:
- '**.php'
- composer.json
- .github/**

jobs:
phpstan:
name: phpstan
runs-on: ubuntu-latest
test:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.2, 8.3]
laravel: ['10.*', '11.*']
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
phpunit: 10.*
- laravel: 11.*
testbench: 9.*
phpunit: 11.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
coverage: none
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: xdebug

- name: Setup problem matchers
run: |
mkdir -p build/logs
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 }}" "phpunit/phpunit:${{ matrix.phpunit }}" --no-interaction --dev
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Execute tests
run: vendor/bin/testbench package:test

- name: Install composer dependencies
uses: ramsey/composer-install@v1
- name: Replace clover.xml paths
run: |
sed -i 's|/home/runner/work/laravel-model-hashid/laravel-model-hashid/src|/github/workspace/src|g' build/logs/clover.xml
sed -i 's|/home/runner/work/laravel-model-hashid/laravel-model-hashid/src|/github/workspace/src|g' build/logs/tests.xml
- name: Run PHPStan
run: ./vendor/bin/phpstan --error-format=github
- name: SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34 changes: 17 additions & 17 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,34 @@ on:
branches:
- main
paths:
- **.php
- '**.php'
- composer.json
- .github/**
pull_request:
branches:
- main
paths:
- **.php
- '**.php'
- composer.json
- .github/**

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.0, 8.1, 8.2]
laravel: ['9.*', '10.*', '11.*']
dependency-version: [prefer-lowest, prefer-stable]
os: [ ubuntu-latest ]
php: [ 8.2, 8.3 ]
laravel: [ '10.*', '11.*' ]
dependency-version: [ prefer-lowest, prefer-stable ]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
phpunit: 10.*
- laravel: 11.*
testbench: 9.*
exclude:
- laravel: 10.*
php: 8.0
- laravel: 11.*
php: 8.0
- laravel: 11.*
php: 8.1
phpunit: 11.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand All @@ -63,13 +55,21 @@ jobs:
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --dev
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "phpunit/phpunit:${{ matrix.phpunit }}" --no-interaction --dev
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Create Database
run: |
mkdir -p database
touch database/database.sqlite
- name: Execute tests
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
run: vendor/bin/testbench package:test

- name: Replace clover.xml paths
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

</div>

Using this package you can generate, save and, route [Stripe-like](https://gist.github.com/fnky/76f533366f75cf75802c8052b577e2a5) Hash Ids for your Eloquent Models.
Using this package you can generate, save and, route [Stripe-like](https://gist.github.com/fnky/76f533366f75cf75802c8052b577e2a5) Hash Ids for your Eloquent Models.

Hash Ids are short, unique, and non-sequential, and can generate unique Ids for URLs and hide database row numbers from
the user. For more information about Hash Ids please visit [hashids.org](https://hashids.org/).
Expand All @@ -32,7 +32,7 @@ With this package, you can customize Hash Id generation and add a model prefix a

For a `User` model with an id of `1234`, you can generate Hash Ids like `user_kqYZeLgo`.

So instead of;
So instead of;
`https://your-endpoint.com/user/1234`

You can have endpoints like;
Expand Down Expand Up @@ -404,7 +404,7 @@ Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

## Security Vulnerabilities

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

## Credits

Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@
"source": "https://github.com/deligoez/laravel-model-hashid"
},
"require": {
"php": "^8.0|^8.1|^8.2",
"php": "^8.2|^8.3",
"ext-mbstring": "*",
"hashids/hashids": "^4.1|^5.0",
"illuminate/contracts": "^9.0|^10.0|^11.0"
},
"require-dev": {
"laravel/pint": "^1.10",
"nunomaduro/collision": "^6.4|^8.0",
"nunomaduro/larastan": "^2.4",
"orchestra/testbench": "^7.21|^8.0|^9.0",
"orchestra/testbench": "^8.0|^9.0",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan-deprecation-rules": "^1.1.1",
"phpstan/phpstan-phpunit": "^1.3.3",
"phpunit/phpunit": "^9.6.1|^10.5"
"phpunit/phpunit": "^10.0|^11.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
58 changes: 21 additions & 37 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="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"
>
<testsuites>
<testsuite name="Deligoez Test Suite">
<directory>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/logs/tests.xml"/>
</logging>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Deligoez Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/logs/tests.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
39 changes: 39 additions & 0 deletions phpunit.xml.dist.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="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"
>
<testsuites>
<testsuite name="Deligoez Test Suite">
<directory>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/logs/tests.xml"/>
</logging>
</phpunit>
2 changes: 1 addition & 1 deletion src/Mixins/FindOrByHashIdMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function findOrByHashId(): Closure
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*/
return function ($id, $columns = ['*'], Closure $callback = null) {
return function ($id, $columns = ['*'], ?Closure $callback = null) {
/* @var \Illuminate\Database\Eloquent\Builder $this */
return $this->findOr($this->getModel()->keyFromHashId($id), $columns, $callback);
};
Expand Down
6 changes: 3 additions & 3 deletions src/Support/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Config
*
* @throws \Deligoez\LaravelModelHashId\Exceptions\UnknownHashIdConfigParameterException
*/
public static function get(string $parameter, Model|string $model = null): string|int|array
public static function get(string $parameter, Model|string|null $model = null): string|int|array
{
self::checkIfParameterDefined($parameter);

Expand All @@ -38,7 +38,7 @@ public static function get(string $parameter, Model|string $model = null): strin
*
* @throws \Deligoez\LaravelModelHashId\Exceptions\UnknownHashIdConfigParameterException
*/
public static function has(string $parameter, Model|string $model = null): bool
public static function has(string $parameter, Model|string|null $model = null): bool
{
self::checkIfParameterDefined($parameter);

Expand All @@ -56,7 +56,7 @@ public static function has(string $parameter, Model|string $model = null): bool
*
* @throws \Deligoez\LaravelModelHashId\Exceptions\UnknownHashIdConfigParameterException
*/
public static function set(string $parameter, string|int $value, Model|string $model = null): void
public static function set(string $parameter, string|int $value, Model|string|null $model = null): void
{
self::checkIfParameterDefined($parameter);

Expand Down
2 changes: 1 addition & 1 deletion src/Support/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function forModel(Model $model): ?string
*
* @throws \Deligoez\LaravelModelHashId\Exceptions\UnknownHashIdConfigParameterException
*/
public static function parseHashIDForModel(string $hashId, string $className = null): ?HashIdDTO
public static function parseHashIDForModel(string $hashId, ?string $className = null): ?HashIdDTO
{
$generators = Config::get(ConfigParameters::MODEL_GENERATORS);

Expand Down
3 changes: 1 addition & 2 deletions src/Support/HashIdDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ public function __construct(
public string $separator,
public string $hashIdForKey,
public ?string $modelClassName
) {
}
) {}
}
1 change: 0 additions & 1 deletion src/Traits/HasHashIdRouting.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function resolveRouteBinding($value, $field = null): ?Model
*
* @param Model|Relation $query
* @param mixed $value
* @param null $field
*/
public function resolveRouteBindingQuery($query, $value, $field = null): Builder|Relation
{
Expand Down
Loading

0 comments on commit 4cf350c

Please sign in to comment.