-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
264 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[{*.yml,*.json}] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/.editorconfig export-ignore | ||
/.gitignore export-ignore | ||
/.gitattributes export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/tests export-ignore | ||
/.github export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: phpunit | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
phpunit: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php: [7.3, 7.4, 8.0, 8.1, 8.2] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: xdebug | ||
#extensions: 'redis' | ||
|
||
- name: Get composer cache directory | ||
id: composer-cache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: php${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} | ||
restore-keys: php${{ matrix.php }}-composer- | ||
|
||
- name: Install dependencies | ||
run: composer install --prefer-dist --no-progress | ||
|
||
- name: Run phpunit | ||
run: composer test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ build | |
vendor | ||
.idea | ||
.vscode | ||
.phpunit* | ||
composer.lock | ||
/phpunit.xml | ||
.phpunit.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd" | ||
bootstrap="tests/bootstrap.php" | ||
cacheResultFile=".phpunit.cache/test-results" | ||
executionOrder="depends,defects" | ||
forceCoversAnnotation="false" | ||
beStrictAboutCoversAnnotation="true" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutTodoAnnotatedTests="true" | ||
convertDeprecationsToExceptions="true" | ||
failOnRisky="true" | ||
failOnWarning="true" | ||
verbose="true"> | ||
<testsuites> | ||
<testsuite name="default"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<coverage cacheDirectory=".phpunit.cache/code-coverage" | ||
processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
</coverage> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/support/helpers.php | ||
/runtime | ||
/resource |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace WebmanTech\LaravelValidation\Tests\Facades; | ||
|
||
use Illuminate\Contracts\Validation\Factory as FactoryContract; | ||
use Illuminate\Contracts\Validation\Validator as ValidatorContract; | ||
use Illuminate\Validation\ValidationException; | ||
use PHPUnit\Framework\TestCase; | ||
use Throwable; | ||
use WebmanTech\LaravelValidation\Facades\Validator; | ||
|
||
/** | ||
* https://laravel.com/docs/10.x/validation | ||
*/ | ||
class ValidatorTest extends TestCase | ||
{ | ||
public function testInstance() | ||
{ | ||
$this->assertInstanceOf(FactoryContract::class, Validator::instance()); | ||
$this->assertInstanceOf(FactoryContract::class, validator()); | ||
$this->assertInstanceOf(ValidatorContract::class, validator(['title' => '123'])); | ||
} | ||
|
||
public function testValidate() | ||
{ | ||
$data1 = [ | ||
'email' => '123', | ||
]; | ||
$okRules = [ | ||
'email' => 'required|string', | ||
]; | ||
$errorRules = [ | ||
'email' => 'required|email', | ||
]; | ||
// validate ok | ||
$data = Validator::validate($data1, $okRules); | ||
$this->assertEquals($data1, $data); | ||
// validate error | ||
try { | ||
Validator::validate($data1, $errorRules); | ||
} catch (Throwable $e) { | ||
$this->assertInstanceOf(ValidationException::class, $e); | ||
} | ||
// manual validate | ||
// ok | ||
$validator = Validator::make($data, $okRules); | ||
$this->assertFalse($validator->fails()); | ||
$this->assertEquals($data, $validator->validated()); | ||
// fails | ||
$validator = Validator::make($data, $errorRules); | ||
$this->assertTrue($validator->fails()); | ||
$this->assertEquals(1, $validator->errors()->count()); | ||
} | ||
|
||
public function testMessages() | ||
{ | ||
try { | ||
Validator::validate([ | ||
'title' => '' | ||
], [ | ||
'title' => 'required' | ||
], [ | ||
'title.required' => '标题不能为空' | ||
]); | ||
} catch (ValidationException $e) { | ||
$this->assertEquals('标题不能为空', $e->errors()['title'][0]); | ||
} | ||
} | ||
|
||
public function testRules() | ||
{ | ||
$this->assertTrue(true); | ||
// https://laravel.com/docs/10.x/validation#available-validation-rules | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
if (!file_exists(__DIR__ . '/support/helpers.php')) { | ||
mkdir(__DIR__ . '/support'); | ||
copy(__DIR__ . '/../vendor/workerman/webman-framework/src/support/helpers.php', __DIR__ . '/support/helpers.php'); | ||
} | ||
require_once __DIR__ . '/support/helpers.php'; | ||
|
||
if ( | ||
!file_exists(__DIR__ . '/config/plugin/webman-tech/laravel-validation') | ||
|| !file_exists(__DIR__ . '/resource') | ||
) { | ||
\WebmanTech\LaravelValidation\Install::install(); | ||
} | ||
|
||
require_once __DIR__ . '/../vendor/workerman/webman-framework/src/support/bootstrap.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
return [ | ||
'runtime_path' => base_path(false) . DIRECTORY_SEPARATOR . 'runtime', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
return new \Webman\Container(); |
20 changes: 20 additions & 0 deletions
20
tests/config/plugin/webman-tech/laravel-validation/app.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
use Illuminate\Contracts\Translation\Translator; | ||
use Illuminate\Contracts\Validation\Factory as ValidationFactory; | ||
|
||
return [ | ||
'enable' => true, | ||
/** | ||
* translation 实例 | ||
*/ | ||
'translation' => function (): ?Translator { | ||
return null; | ||
}, | ||
/** | ||
* 扩展自定义验证规则 | ||
*/ | ||
'extends' => function (ValidationFactory $validator): void { | ||
//$validator->extend(); | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* This file is part of webman. | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the MIT-LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author walkor<walkor@workerman.net> | ||
* @copyright walkor<walkor@workerman.net> | ||
* @link http://www.workerman.net/ | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
|
||
/** | ||
* Multilingual configuration | ||
*/ | ||
return [ | ||
// Default language | ||
'locale' => 'zh_CN', | ||
// Fallback language | ||
'fallback_locale' => ['zh_CN', 'en'], | ||
// Folder where language files are stored | ||
'path' => base_path() . '/resource/translations', | ||
]; |