Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests on PHP 8.3 #17

Merged
merged 7 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.3'
coverage: none

- name: Install composer dependencies
Expand Down
19 changes: 2 additions & 17 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.1, 8.2]
laravel: [9.*]
php: [8.2, 8.3]
laravel: [10.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 9.*
testbench: 7.*
- laravel: 10.*
testbench: 8.*
exclude:
- php: 8.2
laravel: 9.*
stability: prefer-lowest

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand All @@ -44,15 +38,6 @@ jobs:
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Set Minimum PHP 8.1 Versions
run: |
composer require ramsey/collection:^1.2 brick/math:^0.9.3 --no-interaction --no-update

- name: Set Minimum PHP 8.2 Versions
run: |
composer require guzzlehttp/guzzle:^7.5 guzzlehttp/psr7:^2.4 predis/predis:^2.0.2 --no-interaction --no-update
if: matrix.php >= 8.2

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
}
],
"require": {
"php": "^8.1",
"illuminate/translation": "^9.0 || ^10.0",
"illuminate/support": "^9.0 || ^10.0",
"illuminate/validation": "^9.0 || ^10.0"
"php": "^8.2",
"illuminate/translation": "^10.0",
"illuminate/support": "^10.0",
"illuminate/validation": "^10.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.7",
"nunomaduro/collision": "^6.0",
"nunomaduro/collision": "^7.10",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^7.0 || ^8.0",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.1",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.24",
"pestphp/pest-plugin-laravel": "^2.2",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^10.4"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 8 additions & 8 deletions src/Database/DatabaseRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,32 +166,32 @@ protected function maxUInt16(): int

protected function minInt24(): int
{
return -8388608; // -0x800000
return -8_388_608; // -0x800000
}

protected function maxInt24(): int
{
return 8388607; // 0x7fffff
return 8_388_607; // 0x7fffff
}

protected function maxUInt24(): int
{
return 16777215; // 0x00ffffff
return 16_777_215; // 0x00ffffff
}

protected function minInt32(): int
{
return -2147483648; // -0x80000000
return -2_147_483_648; // -0x80000000
}

protected function maxInt32(): int
{
return 2147483647; // 0x7fffffff
return 2_147_483_647; // 0x7fffffff
}

protected function maxUInt32(): int
{
return 4294967295; // 0x00ffffffff
return 4_294_967_295; // 0x00ffffffff
}

protected function minFloat(): float
Expand All @@ -208,11 +208,11 @@ protected function minInt64(): int
{
// should be -9223372036854775808 but easier to exclude this value
// because php transforms -9223372036854775808 to -9.2233720368548E+18
return -9223372036854775807;
return -9_223_372_036_854_775_807;
}

protected function maxInt64(): int
{
return 9223372036854775807;
return 9_223_372_036_854_775_807;
}
}
28 changes: 10 additions & 18 deletions src/Rules/DbBoolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,29 @@

namespace Soyhuce\Rules\Rules;

use Illuminate\Contracts\Validation\Rule;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Validator;
use Soyhuce\Rules\Concerns\DatabaseRelatedRule;
use function in_array;
use function is_array;

class DbBoolean implements Rule
class DbBoolean implements ValidationRule
{
use DatabaseRelatedRule;

private string $attribute;

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

return !is_array($value) && in_array($value, $this->booleans()->all(), true);
}
if (!is_array($value) && in_array($value, $this->booleans()->all(), true)) {
return;
}

public function message(): string
{
$validator = Validator::make([], []);
$validator->addFailure($this->attribute, 'boolean');
$validator->addFailure($attribute, 'boolean');

return $validator->errors()->first($this->attribute);
$fail($validator->errors()->first($attribute));
}
}
2 changes: 1 addition & 1 deletion tests/Rules/DbBigIncrementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DbBigIncrementsTest extends RuleTestCase
public function theRuleCorrectlyValidates(): void
{
$this->assertValidates(10, new DbBigIncrements());
$this->assertValidates(9223372036854775807, new DbBigIncrements());
$this->assertValidates(9_223_372_036_854_775_807, new DbBigIncrements());
$this->assertValidates('9223372036854775807', new DbBigIncrements());
$this->assertNotValidates('9223372036854775808', new DbBigIncrements());

Expand Down
4 changes: 2 additions & 2 deletions tests/Rules/DbBigIntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public function theRuleCorrectlyValidates(): void
{
// -9223372036854775808 to 9223372036854775807
$this->assertValidates(10, new DbBigInteger());
$this->assertValidates(9223372036854775807, new DbBigInteger());
$this->assertValidates(9_223_372_036_854_775_807, new DbBigInteger());
$this->assertValidates('9223372036854775807', new DbBigInteger());
$this->assertNotValidates('9223372036854775808', new DbBigInteger());

$this->assertValidates(-9223372036854775807, new DbBigInteger());
$this->assertValidates(-9_223_372_036_854_775_807, new DbBigInteger());
$this->assertValidates('-9223372036854775807', new DbBigInteger());
$this->assertNotValidates('-9223372036854775808', new DbBigInteger());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Rules/DbDoubleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DbDoubleTest extends RuleTestCase
public function theRuleIsNotImplemented(): void
{
$this->expectException(Unimplemented::class);
$this->expectErrorMessage(sprintf('Method %s::double is not yet implemented', DatabaseRange::class));
$this->expectExceptionMessage(sprintf('Method %s::double is not yet implemented', DatabaseRange::class));

$this->assertValidates(10, new DbDouble());
}
Expand All @@ -29,7 +29,7 @@ public function theRuleIsNotImplemented(): void
public function helperCanBeUsed(): void
{
$this->expectException(Unimplemented::class);
$this->expectErrorMessage(sprintf('Method %s::double is not yet implemented', DatabaseRange::class));
$this->expectExceptionMessage(sprintf('Method %s::double is not yet implemented', DatabaseRange::class));

$this->assertValidates(10, DbRules::double());
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Rules/DbIncrementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public function theRuleCorrectlyValidates(): void
{
$this->assertValidates(10, new DbIncrements());
$this->assertValidates(1, new DbIncrements());
$this->assertValidates(4294967295, new DbIncrements());
$this->assertValidates(4_294_967_295, new DbIncrements());
$this->assertNotValidates(0, new DbIncrements());
$this->assertNotValidates(4294967296, new DbIncrements());
$this->assertNotValidates(4_294_967_296, new DbIncrements());

$this->assertNotValidates([], new DbIncrements());
$this->assertNotValidates(UploadedFile::fake()->create('file'), new DbIncrements());
Expand All @@ -43,7 +43,7 @@ public function messagesAreCorrectlyHandled(): void
);

$this->assertFailsWithMessage(
4294967296,
4_294_967_296,
new DbIncrements(),
[trans('validation.max.numeric', ['attribute' => 'test', 'max' => '4294967295'])]
);
Expand Down Expand Up @@ -95,6 +95,6 @@ public function maxMustBeInActualRange(): void
{
$this->expectException(ValueOutOfRange::class);

new DbIncrements(max: 4294967296);
new DbIncrements(max: 4_294_967_296);
}
}
12 changes: 6 additions & 6 deletions tests/Rules/DbIntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class DbIntegerTest extends RuleTestCase
public function theRuleCorrectlyValidates(): void
{
$this->assertValidates(10, new DbInteger());
$this->assertValidates(-2147483648, new DbInteger());
$this->assertValidates(2147483647, new DbInteger());
$this->assertNotValidates(-2147483649, new DbInteger());
$this->assertNotValidates(2147483648, new DbInteger());
$this->assertValidates(-2_147_483_648, new DbInteger());
$this->assertValidates(2_147_483_647, new DbInteger());
$this->assertNotValidates(-2_147_483_649, new DbInteger());
$this->assertNotValidates(2_147_483_648, new DbInteger());

$this->assertNotValidates([], new DbInteger());
$this->assertNotValidates(UploadedFile::fake()->create('file'), new DbInteger());
Expand All @@ -36,12 +36,12 @@ public function theRuleCorrectlyValidates(): void
public function messagesAreCorrectlyHandled(): void
{
$this->assertFailsWithMessage(
-2147483649,
-2_147_483_649,
new DbInteger(),
[trans('validation.min.numeric', ['attribute' => 'test', 'min' => '-2147483648'])]
);
$this->assertFailsWithMessage(
2147483648,
2_147_483_648,
new DbInteger(),
[trans('validation.max.numeric', ['attribute' => 'test', 'max' => '2147483647'])]
);
Expand Down
6 changes: 3 additions & 3 deletions tests/Rules/DbMediumIncrementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public function theRuleCorrectlyValidates(): void
{
$this->assertValidates(10, new DbMediumIncrements());
$this->assertValidates(1, new DbMediumIncrements());
$this->assertValidates(16777215, new DbMediumIncrements());
$this->assertValidates(16_777_215, new DbMediumIncrements());
$this->assertNotValidates(0, new DbMediumIncrements());
$this->assertNotValidates(16777216, new DbMediumIncrements());
$this->assertNotValidates(16_777_216, new DbMediumIncrements());

$this->assertNotValidates([], new DbMediumIncrements());
$this->assertNotValidates(UploadedFile::fake()->create('file'), new DbMediumIncrements());
Expand All @@ -41,7 +41,7 @@ public function messagesAreCorrectlyHandled(): void
[trans('validation.min.numeric', ['attribute' => 'test', 'min' => '1'])]
);
$this->assertFailsWithMessage(
16777216,
16_777_216,
new DbMediumIncrements(),
[trans('validation.max.numeric', ['attribute' => 'test', 'max' => '16777215'])]
);
Expand Down
12 changes: 6 additions & 6 deletions tests/Rules/DbMediumIntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class DbMediumIntegerTest extends RuleTestCase
public function theRuleCorrectlyValidates(): void
{
$this->assertValidates(10, new DbMediumInteger());
$this->assertValidates(-8388608, new DbMediumInteger());
$this->assertValidates(8388607, new DbMediumInteger());
$this->assertNotValidates(-8388609, new DbMediumInteger());
$this->assertNotValidates(8388608, new DbMediumInteger());
$this->assertValidates(-8_388_608, new DbMediumInteger());
$this->assertValidates(8_388_607, new DbMediumInteger());
$this->assertNotValidates(-8_388_609, new DbMediumInteger());
$this->assertNotValidates(8_388_608, new DbMediumInteger());

$this->assertNotValidates([], new DbMediumInteger());
$this->assertNotValidates(UploadedFile::fake()->create('file'), new DbMediumInteger());
Expand All @@ -36,12 +36,12 @@ public function theRuleCorrectlyValidates(): void
public function messagesAreCorrectlyHandled(): void
{
$this->assertFailsWithMessage(
-8388609,
-8_388_609,
new DbMediumInteger(),
[trans('validation.min.numeric', ['attribute' => 'test', 'min' => '-8388608'])]
);
$this->assertFailsWithMessage(
8388608,
8_388_608,
new DbMediumInteger(),
[trans('validation.max.numeric', ['attribute' => 'test', 'max' => '8388607'])]
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Rules/DbUnsignedBigIntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DbUnsignedBigIntegerTest extends RuleTestCase
public function theRuleCorrectlyValidates(): void
{
$this->assertValidates(10, new DbUnsignedBigInteger());
$this->assertValidates(9223372036854775807, new DbUnsignedBigInteger());
$this->assertValidates(9_223_372_036_854_775_807, new DbUnsignedBigInteger());
$this->assertValidates('9223372036854775807', new DbUnsignedBigInteger());
$this->assertNotValidates('9223372036854775808', new DbUnsignedBigInteger());

Expand Down
6 changes: 3 additions & 3 deletions tests/Rules/DbUnsignedIntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public function theRuleCorrectlyValidates(): void
{
$this->assertValidates(10, new DbUnsignedInteger());
$this->assertValidates(0, new DbUnsignedInteger());
$this->assertValidates(4294967295, new DbUnsignedInteger());
$this->assertValidates(4_294_967_295, new DbUnsignedInteger());
$this->assertNotValidates(-1, new DbUnsignedInteger());
$this->assertNotValidates(4294967296, new DbUnsignedInteger());
$this->assertNotValidates(4_294_967_296, new DbUnsignedInteger());

$this->assertNotValidates([], new DbUnsignedInteger());
$this->assertNotValidates(UploadedFile::fake()->create('file'), new DbUnsignedInteger());
Expand All @@ -41,7 +41,7 @@ public function messagesAreCorrectlyHandled(): void
[trans('validation.min.numeric', ['attribute' => 'test', 'min' => '0'])]
);
$this->assertFailsWithMessage(
4294967296,
4_294_967_296,
new DbUnsignedInteger(),
[trans('validation.max.numeric', ['attribute' => 'test', 'max' => '4294967295'])]
);
Expand Down
6 changes: 3 additions & 3 deletions tests/Rules/DbUnsignedMediumIntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public function theRuleCorrectlyValidates(): void
{
$this->assertValidates(10, new DbUnsignedMediumInteger());
$this->assertValidates(0, new DbUnsignedMediumInteger());
$this->assertValidates(16777215, new DbUnsignedMediumInteger());
$this->assertValidates(16_777_215, new DbUnsignedMediumInteger());
$this->assertNotValidates(-1, new DbUnsignedMediumInteger());
$this->assertNotValidates(16777216, new DbUnsignedMediumInteger());
$this->assertNotValidates(16_777_216, new DbUnsignedMediumInteger());

$this->assertNotValidates([], new DbUnsignedMediumInteger());
$this->assertNotValidates(UploadedFile::fake()->create('file'), new DbUnsignedMediumInteger());
Expand All @@ -41,7 +41,7 @@ public function messagesAreCorrectlyHandled(): void
[trans('validation.min.numeric', ['attribute' => 'test', 'min' => '0'])]
);
$this->assertFailsWithMessage(
16777216,
16_777_216,
new DbUnsignedMediumInteger(),
[trans('validation.max.numeric', ['attribute' => 'test', 'max' => '16777215'])]
);
Expand Down
4 changes: 1 addition & 3 deletions tests/Rules/RuleTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
class RuleTestCase extends TestCase
{
/**
* @param mixed $value
* @param mixed $rule
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function makeValidator($value, $rule)
protected function makeValidator(mixed $value, mixed $rule)
{
return Validator::make(['test' => $value], ['test' => $rule]);
}
Expand Down
Loading