From fb2100f5ab7bd141d883651bd53b893913dd0e6d Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 5 Sep 2023 15:56:45 +0800 Subject: [PATCH] Add PHP-8.1 and 8.2 test in GitHub action --- .github/workflows/build.yml | 9 ++------- src/Encoder/EncoderInterface.php | 4 +--- src/Encoder/JsonEncoder.php | 6 ++---- src/Exception/ValidationException.php | 7 +++---- tests/Encoder/JsonEncoderTest.php | 3 +-- tests/Exception/ValidationExceptionTest.php | 2 +- 6 files changed, 10 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index efb24ce..0d65073 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: ['7.2', '7.3', '7.4', '8.0'] + php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} steps: @@ -34,14 +34,9 @@ jobs: - name: Validate composer.json and composer.lock run: composer validate - - name: Install dependencies for PHP 7 - if: matrix.php-versions < '8.0' + - name: Install dependencies for PHP run: composer update --prefer-dist --no-progress - - name: Install dependencies for PHP 8 - if: matrix.php-versions >= '8.0' - run: composer update --prefer-dist --no-progress --ignore-platform-reqs - - name: Run test suite run: composer check env: diff --git a/src/Encoder/EncoderInterface.php b/src/Encoder/EncoderInterface.php index 3f0654c..455651e 100644 --- a/src/Encoder/EncoderInterface.php +++ b/src/Encoder/EncoderInterface.php @@ -2,8 +2,6 @@ namespace Selective\Validation\Encoder; -use UnexpectedValueException; - /** * Encoder interface. */ @@ -14,7 +12,7 @@ interface EncoderInterface * * @param mixed $data The data * - * @throws UnexpectedValueException + * @throws \UnexpectedValueException * * @return string The encoded string */ diff --git a/src/Encoder/JsonEncoder.php b/src/Encoder/JsonEncoder.php index 3f32efb..31ed660 100644 --- a/src/Encoder/JsonEncoder.php +++ b/src/Encoder/JsonEncoder.php @@ -2,8 +2,6 @@ namespace Selective\Validation\Encoder; -use UnexpectedValueException; - /** * Encoder interface. */ @@ -14,7 +12,7 @@ final class JsonEncoder implements EncoderInterface * * @param mixed $data The data * - * @throws UnexpectedValueException + * @throws \UnexpectedValueException * * @return string The encoded string */ @@ -23,7 +21,7 @@ public function encode($data): string $result = json_encode($data); if ($result === false) { - throw new UnexpectedValueException( + throw new \UnexpectedValueException( sprintf('JSON encoding failed. Code: %s. Error: %s.', json_last_error(), json_last_error_msg()) ); } diff --git a/src/Exception/ValidationException.php b/src/Exception/ValidationException.php index 8329c3b..110c355 100644 --- a/src/Exception/ValidationException.php +++ b/src/Exception/ValidationException.php @@ -2,14 +2,13 @@ namespace Selective\Validation\Exception; -use DomainException; use Selective\Validation\ValidationResult; use Throwable; /** * Validation Exception. */ -final class ValidationException extends DomainException +final class ValidationException extends \DomainException { /** * @var ValidationResult|null @@ -22,13 +21,13 @@ final class ValidationException extends DomainException * @param string $message The Exception message to throw * @param ValidationResult|null $validationResult The validation result object * @param int $code The Exception code - * @param Throwable|null $previous The previous throwable used for the exception chaining + * @param \Throwable|null $previous The previous throwable used for the exception chaining */ public function __construct( string $message, ValidationResult $validationResult = null, int $code = 422, - Throwable $previous = null + \Throwable $previous = null ) { parent::__construct($message, $code, $previous); diff --git a/tests/Encoder/JsonEncoderTest.php b/tests/Encoder/JsonEncoderTest.php index e60ec1c..e3a55ee 100644 --- a/tests/Encoder/JsonEncoderTest.php +++ b/tests/Encoder/JsonEncoderTest.php @@ -4,7 +4,6 @@ use PHPUnit\Framework\TestCase; use Selective\Validation\Encoder\JsonEncoder; -use UnexpectedValueException; /** * Tests. @@ -31,7 +30,7 @@ public function testEncode(): void */ public function testInvalidEncoding(): void { - $this->expectException(UnexpectedValueException::class); + $this->expectException(\UnexpectedValueException::class); $this->expectExceptionMessage('JSON encoding failed. Code: 5. Error: Malformed UTF-8 characters,' . ' possibly incorrectly encoded.'); diff --git a/tests/Exception/ValidationExceptionTest.php b/tests/Exception/ValidationExceptionTest.php index ed67a44..2163ac3 100644 --- a/tests/Exception/ValidationExceptionTest.php +++ b/tests/Exception/ValidationExceptionTest.php @@ -21,7 +21,7 @@ public function testSuccessAction(): void $service = new TestService(); $result = $service->process(1); - $this->assertSame('{"success":true}', (json_encode($result))); + $this->assertSame('{"success":true}', json_encode($result)); } /**