Skip to content

Commit

Permalink
Support Hyperf 3.0 (#2)
Browse files Browse the repository at this point in the history
* Support Hyperf 3.0

* Added test cases for php 8.1 8.2 and 8.3

* Added branch alias
  • Loading branch information
limingxinleo authored Apr 29, 2024
1 parent 310c6b8 commit 63722b4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 34 deletions.
55 changes: 32 additions & 23 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
name: PHPUnit

on: [push, pull_request]
on: [ push, pull_request ]

env:
SWOOLE_VERSION: '4.8.0'
SWOW_VERSION: 'develop'

jobs:
ci:
name: Test PHP ${{ matrix.php-version }} on ${{ matrix.engine }}
swow-ci:
name: Test PHP ${{ matrix.php-version }} on Swow
runs-on: "${{ matrix.os }}"
strategy:
matrix:
os: [ubuntu-latest]
php-version: ['8.0']
engine: ['swoole', 'swow']
max-parallel: 5
os: [ ubuntu-latest ]
php-version: [ '8.0', '8.1', '8.2', '8.3' ]
max-parallel: 4
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -26,21 +25,6 @@ jobs:
tools: phpize
ini-values: opcache.enable_cli=1
coverage: none
- name: Setup Swoole
if: ${{ matrix.engine == 'swoole' }}
run: |
sudo apt-get install libcurl4-openssl-dev
wget https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz -O swoole.tar.gz
mkdir -p swoole
tar -xf swoole.tar.gz -C swoole --strip-components=1
rm swoole.tar.gz
cd swoole
phpize
./configure --enable-openssl --enable-http2 --enable-swoole-curl --enable-swoole-json
make -j$(nproc)
sudo make install
sudo sh -c "echo extension=swoole > /etc/php/${{ matrix.php-version }}/cli/conf.d/swoole.ini"
php --ri swoole
- name: Setup Swow
if: ${{ matrix.engine == 'swow' }}
run: |
Expand All @@ -59,10 +43,35 @@ jobs:
- name: Setup Redis Server
run: docker run --name redis --restart always -p 6379:6379 -d redis
- name: Setup Swow
if: ${{ matrix.engine == 'swow' }}
run: composer require hyperf/engine-swow
- name: Setup Packages
run: composer update -o
- name: Run Test Cases
run: |
composer test
swoole-ci:
name: Test PHP ${{ matrix.php-version }} on Swoole
runs-on: "${{ matrix.os }}"
strategy:
matrix:
os: [ ubuntu-latest ]
php-version: [ '8.0', '8.1', '8.2', '8.3' ]
max-parallel: 4
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: phpize
ini-values: opcache.enable_cli=1
extensions: redis, pdo, pdo_mysql, bcmath, swoole
coverage: none
- name: Setup Redis Server
run: docker run --name redis --restart always -p 6379:6379 -d redis
- name: Setup Packages
run: composer update -o
- name: Run Test Cases
run: |
composer test
14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"description": "KK validation library",
"require": {
"php": ">=8.0",
"ext-mbstring": "*",
"ext-ctype": "*"
"ext-ctype": "*",
"ext-mbstring": "*"
},
"require-dev": {
"hyperf/utils": "^2.2",
"hyperf/validation": "^2.2",
"hyperf/server": "^3.0",
"hyperf/utils": "^3.0",
"hyperf/validation": "^3.0",
"jchook/phpunit-assert-throws": "^1.0",
"mockery/mockery": "^1.4",
"phpunit/phpunit": "^9.5"
Expand All @@ -37,6 +38,11 @@
"optimize-autoloader": true,
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "0.3-dev"
}
},
"scripts": {
"test": "phpunit -c phpunit.xml --colors=always"
}
Expand Down
15 changes: 9 additions & 6 deletions src/Adapter/HyperfValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use Hyperf\Contract\TranslatorInterface;
use Hyperf\Contract\ValidatorInterface;
use Hyperf\Utils\Arr;
use Hyperf\Utils\Contracts\MessageBag as MessageBagContract;
use Hyperf\Utils\Fluent;
use Hyperf\Utils\MessageBag;
use Hyperf\Utils\Str;
use Hyperf\Collection\Arr;
use Hyperf\Contract\MessageBag as MessageBagContract;
use Hyperf\Support\Fluent;
use Hyperf\Support\MessageBag;
use Hyperf\Stringable\Str;
use Hyperf\Validation\Concerns;
use Hyperf\Validation\Contract\PresenceVerifierInterface;
use Hyperf\Validation\ValidationException;
Expand All @@ -17,6 +17,9 @@
use Psr\Container\ContainerInterface;
use RuntimeException;

use function Hyperf\Collection\data_get;
use function Hyperf\Collection\collect;

class HyperfValidator implements ValidatorInterface
{
use Concerns\FormatsMessages;
Expand Down Expand Up @@ -337,7 +340,7 @@ public function setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)
/**
* Get the Presence Verifier implementation.
*
*@throws \RuntimeException
* @throws \RuntimeException
*/
public function getPresenceVerifier(): PresenceVerifierInterface
{
Expand Down
3 changes: 2 additions & 1 deletion src/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

class ValidationException extends \Exception
{
#[Pure] public function __construct(protected array $errors)
#[Pure]
public function __construct(protected array $errors)
{
parent::__construct('The given data was invalid');
}
Expand Down

0 comments on commit 63722b4

Please sign in to comment.