Skip to content

Commit

Permalink
PHPUnit 10 Shift (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
nie7321 authored Mar 18, 2024
1 parent 350d6f5 commit 3954095
Show file tree
Hide file tree
Showing 53 changed files with 188 additions and 264 deletions.
11 changes: 1 addition & 10 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
php-versions: ['8.1', '8.2', '8.3']
php-versions: ['8.2', '8.3']

steps:
- uses: actions/checkout@v4
Expand All @@ -37,15 +37,6 @@ jobs:
- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3.3.2
with:
path: vendor
key: php-${{ matrix.php-versions }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
php-${{ matrix.php-versions }}
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/vendor
.env
.env.backup
.phpunit.result.cache
/.phpunit.cache
docker-compose.override.yml
Homestead.json
Homestead.yaml
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"require-dev": {
"orchestra/testbench": "^8",
"phpunit/phpunit": "^9",
"phpunit/phpunit": "^10.0",
"php-coveralls/php-coveralls": "^2.4"
},
"autoload": {
Expand Down
26 changes: 11 additions & 15 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<?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"
colors="true"
>
<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion tests/Calculation/JSONCalculationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* @coversDefaultClass \Northwestern\SysDev\DynamicForms\Calculation\JSONCalculation
*/
class JSONCalculationTest extends TestCase
final class JSONCalculationTest extends TestCase
{
/**
* @covers ::__invoke
Expand Down
2 changes: 1 addition & 1 deletion tests/ComponentRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @coversDefaultClass \Northwestern\SysDev\DynamicForms\ComponentRegistry
*/
class ComponentRegistryTest extends TestCase
final class ComponentRegistryTest extends TestCase
{
/**
* @covers ::__construct
Expand Down
6 changes: 3 additions & 3 deletions tests/Components/Inputs/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* @coversDefaultClass \Northwestern\SysDev\DynamicForms\Components\Inputs\Address
*/
class AddressTest extends InputComponentTestCase
final class AddressTest extends InputComponentTestCase
{
public string $componentClass = Address::class;
public array $defaultAdditional = ['provider' => Address::PROVIDER_OPENSTREETMAP];
Expand Down Expand Up @@ -54,7 +54,7 @@ public function testUnsupportedProviderThrowsError(): void
$this->getComponent(additional: ['provider' => Address::PROVIDER_AZURE]);
}

public function validationsProvider(): array
public static function validationsProvider(): array
{
return [
'no data passes' => [[], [], true],
Expand All @@ -63,7 +63,7 @@ public function validationsProvider(): array
];
}

public function submissionValueProvider(): array
public static function submissionValueProvider(): array
{
return [
'no transformations' => [null, self::VALID_ADDR, self::VALID_ADDR],
Expand Down
11 changes: 4 additions & 7 deletions tests/Components/Inputs/ButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@

use Northwestern\SysDev\DynamicForms\Components\Inputs\Button;
use Northwestern\SysDev\DynamicForms\Tests\Components\TestCases\BaseComponentTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @coversDefaultClass \Northwestern\SysDev\DynamicForms\Components\Inputs\Button
*/
class ButtonTest extends BaseComponentTestCase
final class ButtonTest extends BaseComponentTestCase
{
protected string $componentClass = Button::class;

/**
* @covers ::action
*
* @dataProvider actionProvider
*/
#[DataProvider('actionProvider')]
public function testAction(array $additional, string $expectedAction): void
{
/** @var Button $component */
Expand All @@ -25,7 +22,7 @@ public function testAction(array $additional, string $expectedAction): void
$this->assertEquals($expectedAction, $component->action());
}

public function actionProvider(): array
public static function actionProvider(): array
{
return [
'key not present' => [[], Button::ACTION_SUBMIT],
Expand Down
4 changes: 2 additions & 2 deletions tests/Components/Inputs/CheckboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ class CheckboxTest extends InputComponentTestCase
{
protected string $componentClass = Checkbox::class;

public function validationsProvider(): array
public static function validationsProvider(): array
{
return [
'required passes' => [['required' => true], true, true],
'required fails' => [['required' => true], false, false],
];
}

public function submissionValueProvider(): array
public static function submissionValueProvider(): array
{
return [
'no transformations' => [null, true, true],
Expand Down
14 changes: 6 additions & 8 deletions tests/Components/Inputs/CurrencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
use Northwestern\SysDev\DynamicForms\Components\CaseEnum;
use Northwestern\SysDev\DynamicForms\Components\Inputs\Currency;
use Northwestern\SysDev\DynamicForms\Tests\Components\TestCases\InputComponentTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @coversDefaultClass \Northwestern\SysDev\DynamicForms\Components\Inputs\Currency
*/
class CurrencyTest extends InputComponentTestCase
final class CurrencyTest extends InputComponentTestCase
{
protected string $componentClass = Currency::class;

public function validationsProvider(): array
public static function validationsProvider(): array
{
return [
'passes with blank data' => [[], '', true],
Expand All @@ -22,18 +23,15 @@ public function validationsProvider(): array
];
}

/**
* @dataProvider submissionValueNumericsDataProvider
* @covers ::submissionValue
*/
#[DataProvider('submissionValueNumericsDataProvider')]
public function testSubmissionValueHandlesNumerics(int | float | array $submissionValue, bool $hasMultipleValues, array | int | float $expected): void
{
$currency = $this->getComponent(hasMultipleValues: $hasMultipleValues, submissionValue: $submissionValue);

$this->assertEquals($expected, $currency->submissionValue());
}

public function submissionValueNumericsDataProvider(): array
public static function submissionValueNumericsDataProvider(): array
{
return [
'integer is untouched' => [100, false, 100],
Expand All @@ -43,7 +41,7 @@ public function submissionValueNumericsDataProvider(): array
];
}

public function submissionValueProvider(): array
public static function submissionValueProvider(): array
{
return [
'no transformations' => [null, 1.00, 1.00],
Expand Down
14 changes: 6 additions & 8 deletions tests/Components/Inputs/DateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@
use Northwestern\SysDev\DynamicForms\Components\CaseEnum;
use Northwestern\SysDev\DynamicForms\Components\Inputs\DateTime;
use Northwestern\SysDev\DynamicForms\Tests\Components\TestCases\InputComponentTestCase;
use PHPUnit\Framework\Attributes\TestWith;

/**
* @coversDefaultClass \Northwestern\SysDev\DynamicForms\Components\Inputs\DateTime
*/
class DateTimeTest extends InputComponentTestCase
final class DateTimeTest extends InputComponentTestCase
{
protected string $componentClass = DateTime::class;

/**
* @testWith [""]
* ["garbage"]
* @covers ::submissionValue
*/
#[TestWith([''])]
#[TestWith(['garbage'])]
public function testSubmissionValueHandlesNulls(string $value): void
{
$date = $this->getComponent(submissionValue: $value);
Expand All @@ -34,7 +32,7 @@ public function testSubmissionValueHandlesDates(): void
$this->assertEquals('2021-03-25 17:00:00', $date->submissionValue());
}

public function validationsProvider(): array
public static function validationsProvider(): array
{
return [
'passes with blank' => [[], '', true, null],
Expand All @@ -50,7 +48,7 @@ public function validationsProvider(): array
];
}

public function submissionValueProvider(): array
public static function submissionValueProvider(): array
{
return [
'no transformations' => [null, '2021-03-25T12:00:00-05:00', Carbon::parse('2021-03-25T12:00:00-05:00')],
Expand Down
28 changes: 9 additions & 19 deletions tests/Components/Inputs/DayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
use Northwestern\SysDev\DynamicForms\Components\CaseEnum;
use Northwestern\SysDev\DynamicForms\Components\Inputs\Day;
use Northwestern\SysDev\DynamicForms\Tests\Components\TestCases\InputComponentTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* @coversDefaultClass \Northwestern\SysDev\DynamicForms\Components\Inputs\Day
*/
class DayTest extends InputComponentTestCase
final class DayTest extends InputComponentTestCase
{
protected string $componentClass = Day::class;

/**
* @dataProvider getDatePartsDataProvider
* @covers ::getDateParts
*/
#[DataProvider('getDatePartsDataProvider')]
public function testGetDateParts(string $value, array $expected): void
{
$reflection = new \ReflectionClass(Day::class);
Expand All @@ -29,7 +27,7 @@ public function testGetDateParts(string $value, array $expected): void
);
}

public function getDatePartsDataProvider(): array
public static function getDatePartsDataProvider(): array
{
$default = ['year' => null, 'month' => null, 'day' => null];

Expand All @@ -47,12 +45,8 @@ public function getDatePartsDataProvider(): array
* Overwriting the parent method so we can pass validations to a different spot.
*
* @see getDay
*
* @dataProvider validationsProvider
* @covers ::processValidations
* @covers ::validate
* @covers ::makeDateFormatString
*/
#[DataProvider('validationsProvider')]
public function testValidations(
array $validations,
mixed $submissionValue,
Expand All @@ -67,26 +61,22 @@ public function testValidations(
$this->assertEquals($passes, $bag->isEmpty(), $bag);
}

/**
* @covers ::processValidations
* @covers ::validate
* @dataProvider validationsProvider
*/
#[DataProvider('validationsProvider')]
public function testValidationsOnMultipleValues(
array $validations,
mixed $submissionValue,
bool $passes,
?string $message = null,
array $additional = [],
?string $errorLabel = null
) {
): void {
$component = $this->getDay([$submissionValue], true, $validations, $errorLabel);

$bag = $component->validate();
$this->assertEquals($passes, $bag->isEmpty(), $bag);
}

public function validationsProvider(): array
public static function validationsProvider(): array
{
$allRequired = [
'year' => ['required' => true],
Expand Down Expand Up @@ -115,7 +105,7 @@ public function validationsProvider(): array
];
}

public function submissionValueProvider(): array
public static function submissionValueProvider(): array
{
$date = '01/01/2021';

Expand Down
4 changes: 2 additions & 2 deletions tests/Components/Inputs/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EmailTest extends InputComponentTestCase
{
protected string $componentClass = Email::class;

public function validationsProvider(): array
public static function validationsProvider(): array
{
return [
'passes when no value is supplied' => [[], '', true],
Expand All @@ -32,7 +32,7 @@ public function validationsProvider(): array
];
}

public function submissionValueProvider(): array
public static function submissionValueProvider(): array
{
return [
'no transformations' => [null, 'foo@bar.com', 'foo@bar.com'],
Expand Down
Loading

0 comments on commit 3954095

Please sign in to comment.