-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
f95081c
commit 74a003c
Showing
19 changed files
with
146 additions
and
21 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
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
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 |
---|---|---|
@@ -1,10 +1,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
uses(\Jiannei\Enum\Laravel\Tests\TestCase::class); | ||
use Jiannei\Enum\Laravel\Tests\Enums\StringValuesEnum; | ||
use Jiannei\Enum\Laravel\Tests\Enums\UserTypeEnum; | ||
|
||
|
||
test('comparison against plain value matching', function () { | ||
// 使用常量实例的 is 方法,比较某个值与当前常量实例的值是否相同 | ||
$admin = UserTypeEnum::fromValue(UserTypeEnum::ADMINISTRATOR); | ||
|
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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
uses(\Jiannei\Enum\Laravel\Tests\TestCase::class); | ||
use Jiannei\Enum\Laravel\Exceptions\InvalidEnumKeyException; | ||
use Jiannei\Enum\Laravel\Exceptions\InvalidEnumValueException; | ||
use Jiannei\Enum\Laravel\Tests\Enums\UserTypeEnum; | ||
|
||
|
||
test('can instantiate enum class with new', function () { | ||
// 使用 new 方式实例化常量 | ||
$userType = new UserTypeEnum(UserTypeEnum::ADMINISTRATOR); | ||
|
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 |
---|---|---|
@@ -1,9 +1,17 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
uses(\Jiannei\Enum\Laravel\Tests\TestCase::class); | ||
use Jiannei\Enum\Laravel\Tests\Enums\ExampleEnum; | ||
|
||
|
||
test('enum get description with localization', function () { | ||
// 常量描述本地化:存在相应语言包的时候取语言包中对应的描述 | ||
$this->app->setLocale('en'); | ||
|
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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
uses(\Jiannei\Enum\Laravel\Tests\TestCase::class); | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Config; | ||
use Jiannei\Enum\Laravel\Http\Middleware\TransformEnums; | ||
use Jiannei\Enum\Laravel\Tests\Enums\UserTypeEnum; | ||
|
||
|
||
beforeEach(function () { | ||
Config::set('enum', [ | ||
'localization' => ['key' => 'enums'], 'transformations' => ['user_type' => UserTypeEnum::class], | ||
|
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
uses(\Jiannei\Enum\Laravel\Tests\TestCase::class); | ||
use Jiannei\Enum\Laravel\Exceptions\InvalidEnumValueException; | ||
use Jiannei\Enum\Laravel\Tests\Enums\UserTypeCustomCastEnum; | ||
|
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 |
---|---|---|
@@ -1,9 +1,17 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
uses(\Jiannei\Enum\Laravel\Tests\TestCase::class); | ||
use Jiannei\Enum\Laravel\Tests\Enums\SingleValueEnum; | ||
|
||
|
||
test('get random instance', function () { | ||
// 获取随机的实例 | ||
$instance = SingleValueEnum::getRandomInstance(); | ||
|
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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
uses(\Jiannei\Enum\Laravel\Tests\TestCase::class); | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Config; | ||
use Jiannei\Enum\Laravel\Tests\Enums\UserTypeEnum; | ||
|
||
|
||
beforeEach(function () { | ||
Config::set('enum', [ | ||
'localization' => ['key' => 'enums1'], 'transformations' => ['user_type' => UserTypeEnum::class], | ||
|
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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
uses(\Jiannei\Enum\Laravel\Tests\TestCase::class); | ||
use Jiannei\Enum\Laravel\Enum; | ||
use Jiannei\Enum\Laravel\Tests\Enums\ExampleEnum; | ||
use Jiannei\Enum\Laravel\Tests\Enums\StringValuesEnum; | ||
use Jiannei\Enum\Laravel\Tests\Enums\UserTypeEnum; | ||
|
||
|
||
test('enum values', function () { | ||
// 常规用法:获取常量的值 | ||
expect(UserTypeEnum::ADMINISTRATOR)->toEqual(0); | ||
|
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
test('example', function () { | ||
expect(true)->toBeTrue(); | ||
}); |
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 |
---|---|---|
@@ -1,9 +1,17 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
uses(\Jiannei\Enum\Laravel\Tests\TestCase::class); | ||
use Jiannei\Enum\Laravel\Tests\Enums\SuperPowersEnum; | ||
|
||
|
||
test('can construct flagged enum using static properties', function () { | ||
// 实例化 Flagged 常量对象的几种方式 | ||
// 方式一:new | ||
|
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 |
---|---|---|
@@ -1,15 +1,13 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Test Case | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The closure you provide to your test functions is always bound to a specific PHPUnit test | ||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may | ||
| need to change it using the "uses()" function to bind a different classes or traits. | ||
| | ||
*/ | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
// uses(Tests\TestCase::class)->in('Feature'); | ||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
test('example', function () { | ||
expect(true)->toBeTrue(); | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
uses(\Jiannei\Enum\Laravel\Tests\TestCase::class); | ||
use Jiannei\Enum\Laravel\Http\Requests\Rules\EnumKey; | ||
use Jiannei\Enum\Laravel\Tests\Enums\StringValuesEnum; | ||
|
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
uses(\Jiannei\Enum\Laravel\Tests\TestCase::class); | ||
use Illuminate\Support\Facades\Validator; | ||
use Jiannei\Enum\Laravel\Tests\Enums\UserTypeEnum; | ||
|
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
uses(\Jiannei\Enum\Laravel\Tests\TestCase::class); | ||
use Jiannei\Enum\Laravel\Http\Requests\Rules\Enum; | ||
use Jiannei\Enum\Laravel\Tests\Enums\UserTypeEnum; | ||
|
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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Jiannei/laravel-enum. | ||
* | ||
* (c) Jiannei <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
uses(\Jiannei\Enum\Laravel\Tests\TestCase::class); | ||
use Jiannei\Enum\Laravel\Http\Requests\Rules\EnumValue; | ||
use Jiannei\Enum\Laravel\Tests\Enums\StringValuesEnum; | ||
|