diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index ce4db10..2920608 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -15,14 +15,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
- uses: actions/checkout@v2
+ uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Cache Composer packages
id: composer-cache
- uses: actions/cache@v2
+ uses: actions/cache@v5
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.json') }}
diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml
index d1fd5c3..179a2d9 100644
--- a/.github/workflows/static-analysis.yml
+++ b/.github/workflows/static-analysis.yml
@@ -15,14 +15,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
- uses: actions/checkout@v2
+ uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
+ with:
+ php-version: '8.2'
- name: Cache Composer packages
id: composer-cache
- uses: actions/cache@v2
+ uses: actions/cache@v5
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.json') }}
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index de0c351..1741a11 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -20,11 +20,11 @@ jobs:
- 'high'
- 'low'
php:
- - '8.0'
+ - '8.2'
steps:
- name: Check out code
- uses: actions/checkout@v2
+ uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
@@ -35,7 +35,7 @@ jobs:
- name: Cache Composer packages
id: composer-cache
- uses: actions/cache@v2
+ uses: actions/cache@v5
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.dependencies }}-${{ matrix.php }}-${{ hashFiles('**/composer.json') }}
@@ -70,4 +70,4 @@ jobs:
- name: Submit code coverage
if: ${{ always() }}
- uses: codecov/codecov-action@v1
+ uses: codecov/codecov-action@v5
diff --git a/.gitignore b/.gitignore
index a6804c8..fd9667e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
/build/
/vendor/
composer.lock
-.phpunit.result.cache
+.phpunit.cache
diff --git a/composer.json b/composer.json
index 565372a..e471895 100644
--- a/composer.json
+++ b/composer.json
@@ -22,13 +22,13 @@
"sort-packages": true
},
"require": {
- "php": "^8.0"
+ "php": "^8.2"
},
"require-dev": {
"phpstan/phpstan": "^0.12.32",
"phpstan/phpstan-phpunit": "^0.12",
- "phpunit/phpunit": "^8.3 || ^9",
- "squizlabs/php_codesniffer": "^3.6"
+ "phpunit/phpunit": "^11.0 || ^12.0 || ^13.0",
+ "squizlabs/php_codesniffer": "^4.0"
},
"scripts": {
"test": [
diff --git a/phpunit.xml b/phpunit.xml
deleted file mode 100644
index fc0cfc4..0000000
--- a/phpunit.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
- tests
-
-
-
-
- src
-
-
-
-
-
-
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..68f2d65
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,24 @@
+
+
+
+
+ tests
+
+
+
+
+
+ src
+
+
+
diff --git a/src/Containers/ParsedInput.php b/src/Containers/ParsedInput.php
index 06cc2ab..d469df5 100644
--- a/src/Containers/ParsedInput.php
+++ b/src/Containers/ParsedInput.php
@@ -151,7 +151,7 @@ public function asArray(): array
/**
* Invoked via `isset` and `empty`
*/
- public function offsetExists($offset)
+ public function offsetExists($offset): bool
{
throw new BadMethodCallException(
"ParsedInput is already validated, and contains all expected " .
@@ -161,9 +161,8 @@ public function offsetExists($offset)
/**
* Invoked by array access of the object
- * @return mixed
*/
- public function offsetGet($offset)
+ public function offsetGet($offset): mixed
{
$data = $this->getData();
if (
@@ -182,7 +181,7 @@ public function offsetGet($offset)
/**
* Invoked by setting an array value on the object
*/
- public function offsetSet($offset, $value)
+ public function offsetSet($offset, $value): never
{
throw new BadMethodCallException("ParsedInput is read-only");
}
@@ -190,7 +189,7 @@ public function offsetSet($offset, $value)
/**
* Invoked via `unset`
*/
- public function offsetUnset($offset)
+ public function offsetUnset($offset): never
{
throw new BadMethodCallException("ParsedInput is read-only");
}
diff --git a/src/Containers/SafeInput.php b/src/Containers/SafeInput.php
index 30012f6..8dc9724 100644
--- a/src/Containers/SafeInput.php
+++ b/src/Containers/SafeInput.php
@@ -13,7 +13,6 @@
*/
class SafeInput extends ParsedInput
{
-
public function __construct(ParsedInput $valid)
{
if (!$valid->isValidated()) {
diff --git a/src/Exceptions/InputException.php b/src/Exceptions/InputException.php
index c0758e7..6dddfad 100644
--- a/src/Exceptions/InputException.php
+++ b/src/Exceptions/InputException.php
@@ -9,7 +9,6 @@
class InputException extends UnexpectedValueException
{
-
public const PARSE_ERROR = 1;
public const FORMAT_ERROR = 2;
public const MISSING_VALUES = 3;
diff --git a/src/Interfaces/ParserInterface.php b/src/Interfaces/ParserInterface.php
index 0e80519..910cda3 100644
--- a/src/Interfaces/ParserInterface.php
+++ b/src/Interfaces/ParserInterface.php
@@ -8,7 +8,6 @@
interface ParserInterface
{
-
/**
* @param string $raw_input Unparsed, unvalidated input
* @return array Parsed, unvalidated input
diff --git a/src/Interfaces/ValidationInterface.php b/src/Interfaces/ValidationInterface.php
index db748af..ed07e6c 100644
--- a/src/Interfaces/ValidationInterface.php
+++ b/src/Interfaces/ValidationInterface.php
@@ -8,7 +8,6 @@
interface ValidationInterface
{
-
/**
* @return array
*/
diff --git a/src/Parsers/JSON.php b/src/Parsers/JSON.php
index fb2fc37..b2314c9 100644
--- a/src/Parsers/JSON.php
+++ b/src/Parsers/JSON.php
@@ -7,7 +7,6 @@
class JSON implements ParserInterface
{
-
public function parse(string $raw_input): array
{
if (!strlen($raw_input)) {
diff --git a/src/Parsers/URLEncoded.php b/src/Parsers/URLEncoded.php
index 7e19533..9ef9379 100644
--- a/src/Parsers/URLEncoded.php
+++ b/src/Parsers/URLEncoded.php
@@ -7,7 +7,6 @@
class URLEncoded implements ParserInterface
{
-
public function parse(string $raw_input): array
{
if (!strlen($raw_input)) {
diff --git a/src/SafeInputTestTrait.php b/src/SafeInputTestTrait.php
index 2ad96d8..3ec957f 100644
--- a/src/SafeInputTestTrait.php
+++ b/src/SafeInputTestTrait.php
@@ -4,7 +4,6 @@
trait SafeInputTestTrait
{
-
/**
* Transform an array of data to a SafeInput object. Intended for testing
* consumers of validated input where testing the actual validation process
diff --git a/tests/Containers/ParsedInputTest.php b/tests/Containers/ParsedInputTest.php
index 93b1339..880cb48 100644
--- a/tests/Containers/ParsedInputTest.php
+++ b/tests/Containers/ParsedInputTest.php
@@ -1,5 +1,7 @@
addRequired(
'short',
- $this->getMockForAbstractClass('Firehed\Input\Objects\InputObject')
+ $this->createStub(InputObject::class)
);
$parsed = new ParsedInput([]);
@@ -178,7 +180,7 @@ public function testMissingOptionalParametersAreSetToNull(): void
{
$this->addOptional(
'short',
- $this->getMockForAbstractClass('Firehed\Input\Objects\InputObject')
+ $this->createStub(InputObject::class)
);
$parsed = new ParsedInput([]);
@@ -231,9 +233,7 @@ public function testOptionalParametersWithValidNullWorksWhenNotProvided(): void
// ----(Validation:Nesting)-------------------------------------------------
- /**
- * @dataProvider nestedValidationExceptions
- */
+ #[DataProvider('nestedValidationExceptions')]
public function testValidateHandlesInputExceptions(
InputException $ex,
array $invalid,
@@ -244,7 +244,7 @@ public function testValidateHandlesInputExceptions(
$io = $this->createMock(InputObject::class);
$io->expects($this->atLeastOnce())
->method('evaluate')
- ->will($this->throwException($ex));
+ ->willThrowException($ex);
if ($required) {
$this->addRequired('struct', $io);
$msg = 'Required:';
@@ -263,7 +263,7 @@ public function testValidateHandlesInputExceptions(
}
}
- public function nestedValidationExceptions()
+ public static function nestedValidationExceptions(): array
{
return [
// Required inputs
@@ -361,11 +361,11 @@ private function getValidation(): ValidationInterface
$validation = $this->createMock(ValidationInterface::class);
$validation->expects($this->atLeastOnce())
->method('getRequiredInputs')
- ->will($this->returnValue($this->required));
+ ->willReturn($this->required);
$validation->expects($this->atLeastOnce())
->method('getOptionalInputs')
- ->will($this->returnValue($this->optional));
+ ->willReturn($this->optional);
return $validation;
}
@@ -387,17 +387,17 @@ private function addOptional(string $key, InputObject $type): void
private function getMockIO(bool $valid, $ret = null): InputObject
{
$mock = $this->getMockBuilder(InputObject::class)
- ->setMethods(['evaluate', 'getDefaultValue'])
- ->getMockForAbstractClass();
+ ->onlyMethods(['evaluate', 'getDefaultValue', 'validate'])
+ ->getMock();
if ($valid) {
$mock->expects($this->atLeastOnce())
->method('evaluate')
- ->will($this->returnValue($ret));
+ ->willReturn($ret);
} else {
$mock->expects($this->atLeastOnce())
->method('evaluate')
- ->will($this->throwException(new UnexpectedValueException()));
+ ->willThrowException(new UnexpectedValueException());
}
return $mock;
}
diff --git a/tests/Containers/RawInputTest.php b/tests/Containers/RawInputTest.php
index 717fff9..8b4ad7e 100644
--- a/tests/Containers/RawInputTest.php
+++ b/tests/Containers/RawInputTest.php
@@ -1,13 +1,15 @@
assertInstanceOf(
@@ -24,7 +26,7 @@ public function testParse(): void
$mock->expects($this->once())
->method('parse')
->with($raw_data)
- ->will($this->returnValue((array)$raw_data));
+ ->willReturn((array)$raw_data);
$raw = new RawInput($raw_data);
$parsed = $raw->parse($mock);
$this->assertInstanceOf(
diff --git a/tests/Containers/SafeInputTest.php b/tests/Containers/SafeInputTest.php
index 627f00d..7bdb53b 100644
--- a/tests/Containers/SafeInputTest.php
+++ b/tests/Containers/SafeInputTest.php
@@ -1,46 +1,46 @@
getMockBuilder(ParsedInput::class)
+ $stub = $this->getMockBuilder(ParsedInput::class)
->disableOriginalConstructor()
- ->setMethods(['getData', 'isValidated'])
+ ->onlyMethods(['getData', 'isValidated'])
->getMock();
- $mock->expects($this->any())
- ->method('getData')
- ->will($this->returnValue($data));
- $mock->expects($this->any())
- ->method('isValidated')
- ->will($this->returnValue(true));
- return new SafeInput($mock);
+ $stub->method('getData')->willReturn($data);
+ $stub->method('isValidated')->willReturn(true);
+ return new SafeInput($stub);
}
+ #[AllowMockObjectsWithoutExpectations]
public function testConstruct(): void
{
$this->assertInstanceOf(SafeInput::class, $this->getSafeInput([]));
}
+ #[AllowMockObjectsWithoutExpectations]
public function testConstructThrowsWithUnvalidatedInput(): void
{
- $valid = $this->getMockBuilder(ParsedInput::class)
+ $stub = $this->getMockBuilder(ParsedInput::class)
->disableOriginalConstructor()
+ ->onlyMethods(['isValidated'])
->getMock();
- $valid->expects($this->atLeastOnce())
- ->method('isValidated')
- ->will($this->returnValue(false));
+ $stub->method('isValidated')->willReturn(false);
$this->expectException(BadMethodCallException::class);
- new SafeInput($valid);
+ new SafeInput($stub);
}
}
diff --git a/tests/Exceptions/InputExceptionTest.php b/tests/Exceptions/InputExceptionTest.php
index 21e1655..d2f57d0 100644
--- a/tests/Exceptions/InputExceptionTest.php
+++ b/tests/Exceptions/InputExceptionTest.php
@@ -5,18 +5,19 @@
namespace Firehed\Input\Exceptions;
use LogicException;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\TestCase;
use ReflectionClass;
use TypeError;
-/**
- * @covers Firehed\Input\Exceptions\InputException
- */
-class InputExceptionTest extends \PHPUnit\Framework\TestCase
+#[CoversClass(InputException::class)]
+class InputExceptionTest extends TestCase
{
/**
* @return array{int, string}[]
*/
- public function constants(): array
+ public static function constants(): array
{
$rc = new ReflectionClass(InputException::class);
$constants = $rc->getConstants();
@@ -28,9 +29,7 @@ public function constants(): array
return $out;
}
- /**
- * @dataProvider constants
- */
+ #[DataProvider('constants')]
public function testConstruct(int $constant, string $name): void
{
$this->assertInstanceOf(
@@ -49,10 +48,8 @@ public function testInvalidConstructWithInt(): void
}
}
- /**
- * @dataProvider constants
- */
- public function testGetInvalid(int $constant): void
+ #[DataProvider('constants')]
+ public function testGetInvalid(int $constant, string $name): void
{
$ex = new InputException($constant, ['foo']);
if ($constant === InputException::INVALID_VALUES) {
@@ -62,10 +59,8 @@ public function testGetInvalid(int $constant): void
}
}
- /**
- * @dataProvider constants
- */
- public function testGetMissing(int $constant): void
+ #[DataProvider('constants')]
+ public function testGetMissing(int $constant, string $name): void
{
$ex = new InputException($constant, ['foo']);
if ($constant === InputException::MISSING_VALUES) {
@@ -75,10 +70,8 @@ public function testGetMissing(int $constant): void
}
}
- /**
- * @dataProvider constants
- */
- public function testGetUnexpected(int $constant): void
+ #[DataProvider('constants')]
+ public function testGetUnexpected(int $constant, string $name): void
{
$ex = new InputException($constant, ['foo']);
if ($constant === InputException::UNEXPECTED_VALUES) {
diff --git a/tests/Objects/InputObjectTest.php b/tests/Objects/InputObjectTest.php
index a0d9098..55b3183 100644
--- a/tests/Objects/InputObjectTest.php
+++ b/tests/Objects/InputObjectTest.php
@@ -6,12 +6,12 @@
use BadMethodCallException;
use Error;
+use PHPUnit\Framework\Attributes\CoversClass;
+use PHPUnit\Framework\TestCase;
use UnexpectedValueException;
-/**
- * @covers Firehed\Input\Objects\InputObject
- */
-class InputObjectTest extends \PHPUnit\Framework\TestCase
+#[CoversClass(InputObject::class)]
+class InputObjectTest extends TestCase
{
private InputObject $io;
diff --git a/tests/Parsers/JSONTest.php b/tests/Parsers/JSONTest.php
index 516b837..9f86abe 100644
--- a/tests/Parsers/JSONTest.php
+++ b/tests/Parsers/JSONTest.php
@@ -1,18 +1,21 @@
parse($json);
}
- /**
- * @dataProvider formatErrors
- */
+ #[DataProvider('formatErrors')]
public function testFormatError(string $json): void
{
$parser = new JSON();
diff --git a/tests/Parsers/URLEncodedTest.php b/tests/Parsers/URLEncodedTest.php
index a9d5936..b5389b2 100644
--- a/tests/Parsers/URLEncodedTest.php
+++ b/tests/Parsers/URLEncodedTest.php
@@ -1,18 +1,21 @@
'bar']],
@@ -25,18 +28,15 @@ public function validURLEncoded(): array
/**
* @return string[][]
*/
- public function formatErrors(): array
+ public static function formatErrors(): array
{
return [
['&'],
];
}
- /**
- * @dataProvider validURLEncoded
- * @param mixed $expected
- */
- public function testParse(string $data, $expected): void
+ #[DataProvider('validURLEncoded')]
+ public function testParse(string $data, mixed $expected): void
{
$parser = new URLEncoded();
@@ -49,9 +49,7 @@ public function testParse(string $data, $expected): void
);
}
- /**
- * @dataProvider formatErrors
- */
+ #[DataProvider('formatErrors')]
public function testFormatError(string $data): void
{
$parser = new URLEncoded();