Skip to content

Commit

Permalink
Add laravel 12 required (#12)
Browse files Browse the repository at this point in the history
* Upgrade package versions

* Touch environment files

* Fit codes as laravel 12

* Update README for laravel 12
  • Loading branch information
cable8mm authored Mar 4, 2025
1 parent c78ca4b commit bf676cb
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 97 deletions.
33 changes: 22 additions & 11 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,34 @@ on:
push:
branches-ignore:
- "dependabot/npm_and_yarn/*"

jobs:
pint:
lint:
runs-on: ubuntu-latest
name: Pint
strategy:
fail-fast: true
matrix:
php: [8.4]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: "laravel-pint"
uses: aglipanci/laravel-pint-action@0.1.0
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
preset: laravel
php-version: ${{ matrix.php }}
extensions: json, dom, curl, libxml, mbstring
coverage: none

- name: Install Pint
run: composer global require laravel/pint

- name: Run Pint
run: pint

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
- name: Commit linted files
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: PHP Linting (Pint)
skip_fetch: true
commit_message: "Fixes coding style"
permissions:
contents: write
29 changes: 7 additions & 22 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ name: run-tests

on:
workflow_dispatch:
pull_request:
push:
branches-ignore:
- "dependabot/npm_and_yarn/*"
branches:
- main

jobs:
test:
Expand All @@ -14,23 +15,9 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.0, 8.1, 8.2, 8.3]
laravel: ["9.*", "10.*", "11.*"]
include:
- laravel: 11.*
testbench: 9.*
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
exclude:
- laravel: 10.*
php: 8.0
- laravel: 11.*
php: 8.1
- laravel: 11.*
php: 8.0
name: PHP ${{ matrix.php }} - L${{ matrix.laravel }}
php: [8.2, 8.3, 8.4]

name: PHP ${{ matrix.php }}

steps:
- name: Checkout code
Expand All @@ -46,9 +33,7 @@ jobs:
run: composer validate

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "nesbot/carbon:^2.63" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --prefer-dist --no-interaction
run: composer install --prefer-dist --no-progress --no-suggest

- name: Execute tests
run: composer test
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ This repository contains a helpful Laravel validation rule for KISA passwords. K

| Available | PHP | Laravel |
| :-------: | :-: | :-----: |
|| 8.0 | 9.x |
|| 8.1 | 9.x |
|| 8.1 | 10.x |
|| 8.2 | 9.x |
|| 8.2 | 10.x |
|| 8.2 | 11.x |
|| 8.3 | 9.x |
|| 8.2 | 12.x |
|| 8.3 | 10.x |
|| 8.3 | 11.x |
|| 8.3 | 12.x |

## Installation

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
}
],
"require": {
"php": "^8.0",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0"
"php": "^8.1",
"illuminate/support": "^10.0|^11.0|^12.0"
},
"require-dev": {
"laravel/pint": "^1.0",
"orchestra/testbench": "^6.23|^7.0|^8.0|^9.0",
"orchestra/testbench": "^8.0|^9.0|^10.0",
"phpunit/phpunit": "^9.0|^10.0|^11.0"
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion lang/en/messages.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

return [
'kisa_password' => 'The :attribute must follow password rules.',
'The :attribute must follow password rules.' => 'The :attribute must follow password rules.',
];
2 changes: 1 addition & 1 deletion lang/ko/messages.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

return [
'kisa_password' => ':attribute 필드가 암호 규칙에 맞지 않습니다.',
'The :attribute must follow password rules.' => ':attribute 필드가 암호 규칙에 맞지 않습니다.',
];
11 changes: 2 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true"
cacheResult="false"
colors="true"
testdox="true">
<testsuites>
Expand All @@ -17,7 +10,7 @@
</testsuite>
</testsuites>

<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
<source>
<include>
<directory>src</directory>
</include>
Expand Down
47 changes: 9 additions & 38 deletions src/Rules/KisaPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,18 @@

namespace Cable8mm\ValidationKisaRules\Rules;

use Illuminate\Contracts\Validation\Rule;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;

class KisaPassword implements Rule
class KisaPassword implements ValidationRule
{
protected string $attribute;

/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function passes($attribute, $value)
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$this->attribute = $attribute;

$valueLength = strlen($value);
$validatedCount = 0;

Expand All @@ -42,41 +27,27 @@ public function passes($attribute, $value)
$validatedCount++;
}

// Rule 3. The string must contain at least one SPECIAL CHRACTER.
// Rule 3. The string must contain at least one **Special Character**.
if (preg_match('/[!@#$%^&*()_+|~=`{}\[\]:";\'<>?,.\/]/', $value)) {
$validatedCount++;
}

if ($validatedCount === 0) {
return false;
$fail('The :attribute must follow password rules.')->translate();
}

// Condition 1:
// If one rule is satisfied, the length of the string must be
// between 10 and 20 characters (including 10 and 20).
if ($validatedCount === 1 && ($valueLength < 10 || $valueLength > 20)) {
return false;
$fail('The :attribute must follow password rules.')->translate();
}

// Condition 2:
// If two or more rules are satisfied, the length of the string must be
// between 8 and 20 characters (including 8 and 20).
if ($validatedCount >= 2 && ($valueLength < 8 || $valueLength > 20)) {
return false;
$fail('The :attribute must follow password rules.')->translate();
}

return true;
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return __('validationKisaRules::messages.kisa_password', [
'attribute' => $this->attribute,
]);
}
}
21 changes: 13 additions & 8 deletions tests/Rules/KisaPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Cable8mm\ValidationKisaRules\Tests\Rules;

use Cable8mm\ValidationKisaRules\Rules\KisaPassword;
use Illuminate\Support\Facades\Validator;
use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\TestCase;

Expand All @@ -21,8 +22,6 @@ protected function getPackageProviders($app)

public function test_pass_according_to_kisa_password_rule_or_not()
{
$rule = new KisaPassword();

$passwords = [
'12345678' => false,
'abcdefgha' => false,
Expand All @@ -38,18 +37,24 @@ public function test_pass_according_to_kisa_password_rule_or_not()
];

foreach ($passwords as $password => $expected) {
$actual = $rule->passes('attribute', $password);

$this->assertEquals($expected, $actual, $password);
$input = ['name' => $password];
$rules = ['name' => new KisaPassword];

if ($expected) {
$this->assertTrue(Validator::make($input, $rules)->passes());
} else {
$this->assertFalse(Validator::make($input, $rules)->passes());
}
}
}

public function test_validate_message_can_be_seen()
{
$rule = new KisaPassword();
$rule = new KisaPassword;

$actual = $rule->passes('attribute', '1');
$input = ['name' => '12345678'];
$rules = ['name' => new KisaPassword];

$this->assertEquals('validationKisaRules::messages.kisa_password', $rule->message());
$this->assertSame('The name must follow password rules.', Validator::make($input, $rules)->messages()->first());
}
}

0 comments on commit bf676cb

Please sign in to comment.