Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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') }}
Expand Down Expand Up @@ -70,4 +70,4 @@ jobs:

- name: Submit code coverage
if: ${{ always() }}
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v5
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/build/
/vendor/
composer.lock
.phpunit.result.cache
.phpunit.cache
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
22 changes: 0 additions & 22 deletions phpunit.xml

This file was deleted.

24 changes: 24 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
shortenArraysForExportThreshold="10"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="false"
beStrictAboutOutputDuringTests="true"
displayDetailsOnAllIssues="true"
failOnAllIssues="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
9 changes: 4 additions & 5 deletions src/Containers/ParsedInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 " .
Expand All @@ -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 (
Expand All @@ -182,15 +181,15 @@ 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");
}

/**
* Invoked via `unset`
*/
public function offsetUnset($offset)
public function offsetUnset($offset): never
{
throw new BadMethodCallException("ParsedInput is read-only");
}
Expand Down
1 change: 0 additions & 1 deletion src/Containers/SafeInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
class SafeInput extends ParsedInput
{

public function __construct(ParsedInput $valid)
{
if (!$valid->isValidated()) {
Expand Down
1 change: 0 additions & 1 deletion src/Exceptions/InputException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class InputException extends UnexpectedValueException
{

public const PARSE_ERROR = 1;
public const FORMAT_ERROR = 2;
public const MISSING_VALUES = 3;
Expand Down
1 change: 0 additions & 1 deletion src/Interfaces/ParserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

interface ParserInterface
{

/**
* @param string $raw_input Unparsed, unvalidated input
* @return array<mixed> Parsed, unvalidated input
Expand Down
1 change: 0 additions & 1 deletion src/Interfaces/ValidationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

interface ValidationInterface
{

/**
* @return array<string, InputObject>
*/
Expand Down
1 change: 0 additions & 1 deletion src/Parsers/JSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class JSON implements ParserInterface
{

public function parse(string $raw_input): array
{
if (!strlen($raw_input)) {
Expand Down
1 change: 0 additions & 1 deletion src/Parsers/URLEncoded.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class URLEncoded implements ParserInterface
{

public function parse(string $raw_input): array
{
if (!strlen($raw_input)) {
Expand Down
1 change: 0 additions & 1 deletion src/SafeInputTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 18 additions & 18 deletions tests/Containers/ParsedInputTest.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<?php

declare(strict_types=1);

namespace Firehed\Input\Containers;

use BadMethodCallException;
use DomainException;
use Firehed\Input\Exceptions\InputException;
use Firehed\Input\Interfaces\ValidationInterface;
use Firehed\Input\Objects\InputObject;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use UnexpectedValueException;

/**
* @covers Firehed\Input\Containers\ParsedInput
*/
class ParsedInputTest extends \PHPUnit\Framework\TestCase
#[CoversClass(ParsedInput::class)]
class ParsedInputTest extends TestCase
{

// ----(Constructor)--------------------------------------------------------

public function testConstructWorks(): void
Expand Down Expand Up @@ -125,7 +127,7 @@
{
$this->addRequired(
'short',
$this->getMockForAbstractClass('Firehed\Input\Objects\InputObject')
$this->createStub(InputObject::class)
);

$parsed = new ParsedInput([]);
Expand Down Expand Up @@ -178,7 +180,7 @@
{
$this->addOptional(
'short',
$this->getMockForAbstractClass('Firehed\Input\Objects\InputObject')
$this->createStub(InputObject::class)
);

$parsed = new ParsedInput([]);
Expand Down Expand Up @@ -231,9 +233,7 @@

// ----(Validation:Nesting)-------------------------------------------------

/**
* @dataProvider nestedValidationExceptions
*/
#[DataProvider('nestedValidationExceptions')]
public function testValidateHandlesInputExceptions(
InputException $ex,
array $invalid,
Expand All @@ -244,7 +244,7 @@
$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:';
Expand All @@ -263,7 +263,7 @@
}
}

public function nestedValidationExceptions()
public static function nestedValidationExceptions(): array
{
return [
// Required inputs
Expand Down Expand Up @@ -361,11 +361,11 @@
$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;
}
Expand All @@ -387,17 +387,17 @@
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;
}
Expand Down
14 changes: 8 additions & 6 deletions tests/Containers/RawInputTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

declare(strict_types=1);

namespace Firehed\Input\Containers;

/**
* @covers Firehed\Input\Containers\RawInput
*/
class RawInputTest extends \PHPUnit\Framework\TestCase
{
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(RawInput::class)]
class RawInputTest extends TestCase
{
public function testConstruct(): void
{
$this->assertInstanceOf(
Expand All @@ -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(
Expand Down
Loading
Loading