Skip to content

Commit 802d124

Browse files
committed
upsome
1 parent e405672 commit 802d124

12 files changed

+122
-42
lines changed

.github/workflows/php.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Unit-tests
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
name: Test on php ${{ matrix.php}} and ${{ matrix.os }}
8+
runs-on: ${{ matrix.os }}
9+
timeout-minutes: 10
10+
strategy:
11+
fail-fast: true
12+
matrix:
13+
php: [7.1, 7.2, 7.3, 7.4] #
14+
os: [ubuntu-latest] # windows-latest, macOS-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
20+
# usage refer https://github.com/shivammathur/setup-php
21+
- name: Setup PHP
22+
timeout-minutes: 5
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: ${{ matrix.php}}
26+
tools: pecl, php-cs-fixer, phpunit
27+
extensions: mbstring, dom, fileinfo, mysql, openssl, igbinary, redis # , swoole-4.4.19 #optional, setup extensions
28+
ini-values: post_max_size=56M, short_open_tag=On #optional, setup php.ini configuration
29+
coverage: none #optional, setup coverage driver: xdebug, none
30+
31+
- name: Display Env
32+
run: env
33+
34+
- name: Install dependencies
35+
run: composer install --no-progress --no-suggest
36+
37+
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
38+
# Docs: https://getcomposer.org/doc/articles/scripts.md
39+
40+
- name: Run test suite
41+
run: composer run test

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
},
3737
"scripts": {
3838
"check-cs": "./php-cs-fixer fix --dry-run --diff --diff-format=udiff",
39-
"cs-fix": "./php-cs-fixer fix"
39+
"cs-fix": "./php-cs-fixer fix",
40+
"test": "vendor/bin/phpunit"
4041
}
4142
}

src/ArrayValueNotExists.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Exception/ArrayValueNotExists.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Inhere\Validate\Exception;
4+
5+
/**
6+
* Class ArrayValueNotExists
7+
*
8+
* @package Inhere\Validate\Exception
9+
*/
10+
final class ArrayValueNotExists
11+
{
12+
}

src/Exception/ValidateException.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Inhere\Validate\Exception;
4+
5+
use RuntimeException;
6+
7+
/**
8+
* Class ValidateException
9+
*
10+
* @package Inhere\Validate\Exception
11+
*/
12+
class ValidateException extends RuntimeException
13+
{
14+
/**
15+
* @var string
16+
*/
17+
public $field;
18+
19+
/**
20+
* @param string $field
21+
* @param string $message
22+
*
23+
* @return static
24+
*/
25+
public static function create(string $field, string $message): self
26+
{
27+
return new self($field, $message);
28+
}
29+
30+
/**
31+
* Class constructor.
32+
*
33+
* @param string $field
34+
* @param string $message
35+
*/
36+
public function __construct(string $field, string $message)
37+
{
38+
parent::__construct($field . ' ' . $message, 500);
39+
40+
// save field
41+
$this->field = $field;
42+
}
43+
}

src/GlobalOption.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Inhere\Validate;
4+
5+
/**
6+
* Class GlobalOption TODO
7+
*
8+
* @package Inhere\Validate
9+
*/
10+
final class GlobalOption
11+
{
12+
/**
13+
* Prettify field name on get error message
14+
*
15+
* @var bool
16+
*/
17+
public static $prettifyName = true;
18+
}

src/Traits/ErrorMessageTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ trait ErrorMessageTrait
6060
private $_stopOnError = true;
6161

6262
/**
63-
* prettify field name on get error message
63+
* Prettify field name on get error message
6464
*
6565
* @var bool
6666
*/

src/Valid.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Inhere\Validate;
44

5+
use Inhere\Validate\Exception\ValidateException;
56
use function array_merge;
67
use function is_int;
78
use function is_numeric;

src/ValidateException.php

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,12 @@
22

33
namespace Inhere\Validate;
44

5-
use RuntimeException;
6-
75
/**
86
* Class ValidateException
97
*
108
* @package Inhere\Validate
9+
* @deprecated please use Inhere\Validate\Exception\ValidateException
1110
*/
12-
class ValidateException extends RuntimeException
11+
class ValidateException extends Exception\ValidateException
1312
{
14-
/**
15-
* @var string
16-
*/
17-
public $field;
18-
19-
/**
20-
* @param string $field
21-
* @param string $message
22-
*
23-
* @return static
24-
*/
25-
public static function create(string $field, string $message): self
26-
{
27-
return new self($field, $message);
28-
}
29-
30-
/**
31-
* Class constructor.
32-
*
33-
* @param string $field
34-
* @param string $message
35-
*/
36-
public function __construct(string $field, string $message)
37-
{
38-
parent::__construct($field . ' ' . $message, 500);
39-
40-
// save field
41-
$this->field = $field;
42-
}
4313
}

src/ValidationTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Closure;
1212
use Generator;
13+
use Inhere\Validate\Exception\ArrayValueNotExists;
1314
use Inhere\Validate\Filter\FilteringTrait;
1415
use Inhere\Validate\Filter\Filters;
1516
use Inhere\Validate\Traits\ErrorMessageTrait;

src/Validators.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Inhere\Validate;
1111

12+
use Inhere\Validate\Exception\ArrayValueNotExists;
1213
use Inhere\Validate\Traits\NameAliasTrait;
1314
use function array_diff;
1415
use function array_key_exists;

test/Traits/ErrorMessageTraitTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public function testErrorMessage(): void
6565

6666
// prettifyName
6767
$v->setPrettifyName(false);
68-
6968
$this->assertFalse($v->isPrettifyName());
7069

7170
// re-validate

0 commit comments

Comments
 (0)