Skip to content

Commit

Permalink
upsome
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jun 25, 2020
1 parent e405672 commit 802d124
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 42 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/php.yml
@@ -0,0 +1,41 @@
name: Unit-tests

on: [push]

jobs:
test:
name: Test on php ${{ matrix.php}} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: true
matrix:
php: [7.1, 7.2, 7.3, 7.4] #
os: [ubuntu-latest] # windows-latest, macOS-latest

steps:
- name: Checkout
uses: actions/checkout@v2

# usage refer https://github.com/shivammathur/setup-php
- name: Setup PHP
timeout-minutes: 5
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php}}
tools: pecl, php-cs-fixer, phpunit
extensions: mbstring, dom, fileinfo, mysql, openssl, igbinary, redis # , swoole-4.4.19 #optional, setup extensions
ini-values: post_max_size=56M, short_open_tag=On #optional, setup php.ini configuration
coverage: none #optional, setup coverage driver: xdebug, none

- name: Display Env
run: env

- name: Install dependencies
run: composer install --no-progress --no-suggest

# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md

- name: Run test suite
run: composer run test
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -36,6 +36,7 @@
},
"scripts": {
"check-cs": "./php-cs-fixer fix --dry-run --diff --diff-format=udiff",
"cs-fix": "./php-cs-fixer fix"
"cs-fix": "./php-cs-fixer fix",
"test": "vendor/bin/phpunit"
}
}
7 changes: 0 additions & 7 deletions src/ArrayValueNotExists.php

This file was deleted.

12 changes: 12 additions & 0 deletions src/Exception/ArrayValueNotExists.php
@@ -0,0 +1,12 @@
<?php declare(strict_types=1);

namespace Inhere\Validate\Exception;

/**
* Class ArrayValueNotExists
*
* @package Inhere\Validate\Exception
*/
final class ArrayValueNotExists
{
}
43 changes: 43 additions & 0 deletions src/Exception/ValidateException.php
@@ -0,0 +1,43 @@
<?php declare(strict_types=1);

namespace Inhere\Validate\Exception;

use RuntimeException;

/**
* Class ValidateException
*
* @package Inhere\Validate\Exception
*/
class ValidateException extends RuntimeException
{
/**
* @var string
*/
public $field;

/**
* @param string $field
* @param string $message
*
* @return static
*/
public static function create(string $field, string $message): self
{
return new self($field, $message);
}

/**
* Class constructor.
*
* @param string $field
* @param string $message
*/
public function __construct(string $field, string $message)
{
parent::__construct($field . ' ' . $message, 500);

// save field
$this->field = $field;
}
}
18 changes: 18 additions & 0 deletions src/GlobalOption.php
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace Inhere\Validate;

/**
* Class GlobalOption TODO
*
* @package Inhere\Validate
*/
final class GlobalOption
{
/**
* Prettify field name on get error message
*
* @var bool
*/
public static $prettifyName = true;
}
2 changes: 1 addition & 1 deletion src/Traits/ErrorMessageTrait.php
Expand Up @@ -60,7 +60,7 @@ trait ErrorMessageTrait
private $_stopOnError = true;

/**
* prettify field name on get error message
* Prettify field name on get error message
*
* @var bool
*/
Expand Down
1 change: 1 addition & 0 deletions src/Valid.php
Expand Up @@ -2,6 +2,7 @@

namespace Inhere\Validate;

use Inhere\Validate\Exception\ValidateException;
use function array_merge;
use function is_int;
use function is_numeric;
Expand Down
34 changes: 2 additions & 32 deletions src/ValidateException.php
Expand Up @@ -2,42 +2,12 @@

namespace Inhere\Validate;

use RuntimeException;

/**
* Class ValidateException
*
* @package Inhere\Validate
* @deprecated please use Inhere\Validate\Exception\ValidateException
*/
class ValidateException extends RuntimeException
class ValidateException extends Exception\ValidateException
{
/**
* @var string
*/
public $field;

/**
* @param string $field
* @param string $message
*
* @return static
*/
public static function create(string $field, string $message): self
{
return new self($field, $message);
}

/**
* Class constructor.
*
* @param string $field
* @param string $message
*/
public function __construct(string $field, string $message)
{
parent::__construct($field . ' ' . $message, 500);

// save field
$this->field = $field;
}
}
1 change: 1 addition & 0 deletions src/ValidationTrait.php
Expand Up @@ -10,6 +10,7 @@

use Closure;
use Generator;
use Inhere\Validate\Exception\ArrayValueNotExists;
use Inhere\Validate\Filter\FilteringTrait;
use Inhere\Validate\Filter\Filters;
use Inhere\Validate\Traits\ErrorMessageTrait;
Expand Down
1 change: 1 addition & 0 deletions src/Validators.php
Expand Up @@ -9,6 +9,7 @@

namespace Inhere\Validate;

use Inhere\Validate\Exception\ArrayValueNotExists;
use Inhere\Validate\Traits\NameAliasTrait;
use function array_diff;
use function array_key_exists;
Expand Down
1 change: 0 additions & 1 deletion test/Traits/ErrorMessageTraitTest.php
Expand Up @@ -65,7 +65,6 @@ public function testErrorMessage(): void

// prettifyName
$v->setPrettifyName(false);

$this->assertFalse($v->isPrettifyName());

// re-validate
Expand Down

0 comments on commit 802d124

Please sign in to comment.