diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0f1ccaa..f16b707 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,14 +12,14 @@ on: jobs: testsuite: name: Unittests - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: - php-version: ['8.0', '8.1', '8.2'] + php-version: ['8.1', '8.2', '8.3'] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 1 @@ -27,7 +27,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} - extensions: json, pdo + extensions: json, mbstring tools: pecl - name: Validate composer.json diff --git a/.gitignore b/.gitignore index 5c9fe27..06b17b2 100644 --- a/.gitignore +++ b/.gitignore @@ -81,3 +81,4 @@ Network Trash Folder Temporary Items .apdisk /.phpunit.result.cache +/.phpunit.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index c0a0373..8ab9341 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Change Log ========== +2024-03-02 +---------- + + * required PHP 8.1+ + * update dependencies + * fix missing return types + 2023-10-05 ---------- diff --git a/composer.json b/composer.json index 8df3f74..9727b76 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,11 @@ } ], "require": { - "php": ">=8.0", + "php": ">=8.1", "ext-mbstring": "*" }, "require-dev": { - "phpunit/phpunit": "^9.5", + "phpunit/phpunit": "^10.5", "doctrine/dbal": "^3.1.0", "ramsey/uuid": "^4.3", "symfony/var-dumper": "^6.0" diff --git a/phpunit.xml b/phpunit.xml index 815a57c..2e79f20 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,15 +1,7 @@ - - - - src/ - - - tests - - + @@ -19,4 +11,12 @@ tests + + + src/ + + + tests + + diff --git a/src/Factory.php b/src/Factory.php index 544127e..ef1c5f1 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -39,7 +39,7 @@ public function __invoke(string $rule, ...$args): Rule return $this->rule($rule)->fillParameters($args); } - protected function registerDefaultRules() + protected function registerDefaultRules(): void { $rules = [ 'accepted' => new Rules\Accepted, diff --git a/src/Rules/Present.php b/src/Rules/Present.php index a536f20..96bc30e 100644 --- a/src/Rules/Present.php +++ b/src/Rules/Present.php @@ -16,7 +16,7 @@ public function check(mixed $value): bool return $this->validation->input()->has($this->attribute->key()); } - protected function setAttributeAsRequired() + protected function setAttributeAsRequired(): void { $this->attribute?->makeRequired(); } diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index 5ac084f..f3244a9 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -85,10 +85,13 @@ public function testNonExistentValidationRule() public function testNewValidationRuleCanBeAdded() { $this->validator->addRule('even', new Even()); + $this->validator->messages()->add('en', [ + 'rule.even' => 'The :attribute must be even', + ]); - $data = [4, 6, 8, 10 ]; + $data = ['s' => 4]; - $validation = $this->validator->make($data, ['s' => 'even'], []); + $validation = $this->validator->make($data, ['s' => 'even']); $validation->validate(); @@ -312,7 +315,7 @@ public function testRootAsteriskValidation(array $data, array $rules, $errors = } } - public function rootAsteriskProvider(): array + public static function rootAsteriskProvider(): array { return [ 'control sample success' => [ diff --git a/tests/Fixtures/Even.php b/tests/Fixtures/Even.php index 6460be8..300d30e 100644 --- a/tests/Fixtures/Even.php +++ b/tests/Fixtures/Even.php @@ -6,7 +6,7 @@ class Even extends Rule { - protected string $message = "The :attribute must be even"; + protected string $message = 'rule.even'; public function check($value): bool { diff --git a/tests/Rules/AfterTest.php b/tests/Rules/AfterTest.php index f9985ea..1232a95 100644 --- a/tests/Rules/AfterTest.php +++ b/tests/Rules/AfterTest.php @@ -12,7 +12,7 @@ class AfterTest extends TestCase { /** - * @var \Somnambulist\Components\Validation\Rules\After + * @var After */ protected $validator; @@ -48,7 +48,7 @@ public function testUserProvidedParamCannotBeValidatedBecauseItIsInvalid() $this->validator->fillParameters(["to,morrow"])->check("now"); } - public function getInvalidDates() + public static function getInvalidDates(): array { $now = new DateTime(); @@ -62,7 +62,7 @@ public function getInvalidDates() ]; } - public function getValidDates() + public static function getValidDates(): array { $now = new DateTime(); diff --git a/tests/Rules/BeforeTest.php b/tests/Rules/BeforeTest.php index 669ecfb..b34bc6a 100644 --- a/tests/Rules/BeforeTest.php +++ b/tests/Rules/BeforeTest.php @@ -30,7 +30,7 @@ public function testOnlyAWellFormedDateCanBeValidated($date) ); } - public function getValidDates() + public static function getValidDates(): array { $now = new DateTime(); @@ -54,7 +54,7 @@ public function testANonWellFormedDateCannotBeValidated($date) $this->validator->fillParameters(["tomorrow"])->check($date); } - public function getInvalidDates() + public static function getInvalidDates(): array { $now = new DateTime(); diff --git a/tests/Rules/BooleanTest.php b/tests/Rules/BooleanTest.php index 237d9ff..1ee72b3 100644 --- a/tests/Rules/BooleanTest.php +++ b/tests/Rules/BooleanTest.php @@ -17,8 +17,8 @@ public function setUp(): void public function testValids() { - $this->assertTrue($this->rule->check(\true)); - $this->assertTrue($this->rule->check(\false)); + $this->assertTrue($this->rule->check(true)); + $this->assertTrue($this->rule->check(false)); $this->assertTrue($this->rule->check(1)); $this->assertTrue($this->rule->check(0)); $this->assertTrue($this->rule->check('1')); diff --git a/tests/UploadedFileTest.php b/tests/UploadedFileTest.php index 6274b3f..1aed50e 100644 --- a/tests/UploadedFileTest.php +++ b/tests/UploadedFileTest.php @@ -74,7 +74,7 @@ public function testMissingKeyUploadedFile($uploadedFile) $this->assertNotNull($errors->first('file:required')); } - public function getSamplesMissingKeyFromUploadedFileValue() + public static function getSamplesMissingKeyFromUploadedFileValue(): array { $validUploadedFile = [ 'name' => 'foo', diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index 3cad135..e866d42 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -29,7 +29,7 @@ public function testParseRule($rules, $expectedResult) $this->assertSame($expectedResult, $result); } - public function parseRuleProvider(): array + public static function parseRuleProvider(): array { return [ [