From 5e4c266b4d7be822a00914fe920e553bce1451f5 Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 5 Sep 2023 15:01:08 +0800 Subject: [PATCH] Add PHP 8.1 and 8.2 test in GitHub action --- .github/workflows/build.yml | 9 ++------- src/Configuration.php | 25 ++++++++++++------------- tests/ConfigurationTest.php | 13 ++++++------- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1c994de..1f3835b 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-req=php - - name: Run test suite run: composer check env: diff --git a/src/Configuration.php b/src/Configuration.php index 123ee09..2f766dc 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -3,7 +3,6 @@ namespace Selective\Config; use Cake\Chronos\Chronos; -use InvalidArgumentException; /** * Configuration. @@ -31,7 +30,7 @@ public function __construct(array $data = []) * @param string $key The key * @param int|null $default The default value * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * * @return int The value */ @@ -40,7 +39,7 @@ public function getInt(string $key, int $default = null): int $value = $this->find($key, $default); if ($this->isNullOrBlank($value)) { - throw new InvalidArgumentException(sprintf('No value found for key "%s"', $key)); + throw new \InvalidArgumentException(sprintf('No value found for key "%s"', $key)); } return (int)$value; @@ -71,7 +70,7 @@ public function findInt(string $key, int $default = null) * @param string $key The key * @param string|null $default The default value * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * * @return string The value */ @@ -80,7 +79,7 @@ public function getString(string $key, string $default = null): string $value = $this->find($key, $default); if ($value === null) { - throw new InvalidArgumentException(sprintf('No value found for key "%s"', $key)); + throw new \InvalidArgumentException(sprintf('No value found for key "%s"', $key)); } return (string)$value; @@ -111,7 +110,7 @@ public function findString(string $key, string $default = null) * @param string $key The key * @param array|null $default The default value * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * * @return array The value */ @@ -120,7 +119,7 @@ public function getArray(string $key, array $default = null): array $value = $this->find($key, $default); if ($this->isNullOrBlank($value)) { - throw new InvalidArgumentException(sprintf('No value found for key "%s"', $key)); + throw new \InvalidArgumentException(sprintf('No value found for key "%s"', $key)); } return (array)$value; @@ -151,7 +150,7 @@ public function findArray(string $key, array $default = null) * @param string $key The key * @param float|null $default The default value * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * * @return float The value */ @@ -160,7 +159,7 @@ public function getFloat(string $key, float $default = null): float $value = $this->find($key, $default); if ($this->isNullOrBlank($value)) { - throw new InvalidArgumentException(sprintf('No value found for key "%s"', $key)); + throw new \InvalidArgumentException(sprintf('No value found for key "%s"', $key)); } return (float)$value; @@ -191,7 +190,7 @@ public function findFloat(string $key, float $default = null) * @param string $key The key * @param bool|null $default The default value * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * * @return bool The value */ @@ -200,7 +199,7 @@ public function getBool(string $key, bool $default = null): bool $value = $this->find($key, $default); if ($this->isNullOrBlank($value)) { - throw new InvalidArgumentException(sprintf('No value found for key "%s"', $key)); + throw new \InvalidArgumentException(sprintf('No value found for key "%s"', $key)); } return (bool)$value; @@ -231,7 +230,7 @@ public function findBool(string $key, bool $default = null) * @param string $key The key * @param Chronos|null $default The default value * - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * * @return Chronos The value */ @@ -240,7 +239,7 @@ public function getChronos(string $key, Chronos $default = null): Chronos $value = $this->find($key, $default); if ($this->isNullOrBlank($value)) { - throw new InvalidArgumentException(sprintf('No value found for key "%s"', $key)); + throw new \InvalidArgumentException(sprintf('No value found for key "%s"', $key)); } if ($value instanceof Chronos) { diff --git a/tests/ConfigurationTest.php b/tests/ConfigurationTest.php index b79202e..1e65369 100644 --- a/tests/ConfigurationTest.php +++ b/tests/ConfigurationTest.php @@ -3,7 +3,6 @@ namespace Selective\Config\Test; use Cake\Chronos\Chronos; -use InvalidArgumentException; use PHPUnit\Framework\TestCase; use Selective\Config\Configuration; @@ -59,7 +58,7 @@ public function providerGetString(): array */ public function testGetStringError($data, string $key): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $reader = new Configuration($data); $reader->getString($key); @@ -164,7 +163,7 @@ public function providerGetInt(): array */ public function testGetIntError($data, string $key): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $reader = new Configuration($data); $reader->getInt($key); @@ -269,7 +268,7 @@ public function providerGetBool(): array */ public function testGetBoolError($data, string $key): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $reader = new Configuration($data); $reader->getBool($key); @@ -374,7 +373,7 @@ public function providerGetFloat(): array */ public function testGetFloatError($data, string $key): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $reader = new Configuration($data); $reader->getFloat($key); @@ -479,7 +478,7 @@ public function providerGetArray(): array */ public function testGetArrayError($data, string $key): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $reader = new Configuration($data); $reader->getArray($key); @@ -585,7 +584,7 @@ public function providerGetChronos(): array */ public function testGetChronosError($data, string $key): void { - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $reader = new Configuration($data); $reader->getChronos($key);