Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
StyleCIBot authored and jiannei committed Oct 12, 2023
1 parent f95081c commit 74a003c
Show file tree
Hide file tree
Showing 19 changed files with 146 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidEnumValueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class InvalidEnumValueException extends Exception
/**
* Create an InvalidEnumValueException.
*
* @param $invalidValue
* @param $invalidValue
* @param Enum|string $enumClass
*/
public function __construct($invalidValue, $enumClass)
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidMethodException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class InvalidMethodException extends Exception
/**
* Create an InvalidMethodException.
*
* @param $invalidMethod
* @param $invalidMethod
* @param Enum|string $enumClass
*/
public function __construct($invalidMethod, $enumClass)
Expand Down
4 changes: 2 additions & 2 deletions src/Repositories/Enums/CacheEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function parseEnumKey(string $cacheKey): string
/**
* Get cache key.
*
* @param $value
* @param $value
* @param string|int|null $identifier
* @return string
*/
Expand All @@ -58,7 +58,7 @@ public static function getCacheKey($value, $identifier = null): string
/**
* Get cache expire time.
*
* @param $value
* @param $value
* @param null $options
* @return mixed
*
Expand Down
10 changes: 9 additions & 1 deletion tests/EnumComparisonTest.php
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);
Expand Down
10 changes: 9 additions & 1 deletion tests/EnumInstanceTest.php
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);
Expand Down
10 changes: 9 additions & 1 deletion tests/EnumLocalizationTest.php
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');
Expand Down
10 changes: 9 additions & 1 deletion tests/EnumMiddlewareTest.php
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],
Expand Down
9 changes: 9 additions & 0 deletions tests/EnumNativeCastTest.php
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;
Expand Down
10 changes: 9 additions & 1 deletion tests/EnumRandomTest.php
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();
Expand Down
10 changes: 9 additions & 1 deletion tests/EnumRequestTest.php
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],
Expand Down
10 changes: 9 additions & 1 deletion tests/EnumTest.php
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);
Expand Down
9 changes: 9 additions & 0 deletions tests/Feature/ExampleTest.php
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();
});
10 changes: 9 additions & 1 deletion tests/FlaggedEnumTest.php
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
Expand Down
16 changes: 7 additions & 9 deletions tests/Pest.php
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');

Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/ExampleTest.php
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();
});
9 changes: 9 additions & 0 deletions tests/Validation/EnumKeyTest.php
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;
Expand Down
9 changes: 9 additions & 0 deletions tests/Validation/EnumPipeValidationTest.php
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;
Expand Down
9 changes: 9 additions & 0 deletions tests/Validation/EnumTest.php
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;
Expand Down
9 changes: 9 additions & 0 deletions tests/Validation/EnumValueTest.php
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;
Expand Down

0 comments on commit 74a003c

Please sign in to comment.