Skip to content

Commit

Permalink
Upgrade to PhpUnit 10.x and code clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
prwater committed Dec 4, 2023
1 parent b815ce3 commit 045bd81
Show file tree
Hide file tree
Showing 51 changed files with 220 additions and 215 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/.idea/
/.phpunit.result.cache
/.phpunit.cache/
/bin/
/composer.lock
/custom.task.properties
/custom.type.properties
/doc/
/node_modules/
/package-lock.json
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"require-dev": {
"ext-dom": "*",
"phing/phing": "^3.0.0-RC4",
"phpunit/phpunit": "^9.6.3",
"phpunit/phpunit": "^10.5.1",
"plaisio/console-kernel": "^1.0.1",
"plaisio/console-type-script": "^1.0.0",
"plaisio/request-core": "^0.13.0"
Expand Down
41 changes: 21 additions & 20 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="test/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory suffix=".php">vendor/setbased</directory>
</exclude>
<report>
<clover outputFile="test/coverage.xml"/>
<html outputDirectory="test/report"/>
</report>
</coverage>
<testsuites>
<testsuite name="Tests">
<directory>test</directory>
</testsuite>
</testsuites>
<logging/>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="test/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<coverage>
<report>
<clover outputFile="test/coverage.xml"/>
<html outputDirectory="test/report"/>
</report>
</coverage>
<testsuites>
<testsuite name="Tests">
<directory>test</directory>
</testsuite>
</testsuites>
<logging/>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory suffix=".php">vendor/setbased</directory>
</exclude>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion src/Validator/HttpValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function validate(Control $control): bool
// Test that the page actually exits. We consider all HTTP 200-399 responses as valid.
try
{
$headers = get_headers($url);
$headers = @get_headers($url);
$valid = (is_array($headers) && preg_match('/^HTTP\\/\\d+\\.\\d+\\s+[23]\\d\\d\\s*.*$/', $headers[0]));
}
catch (\Exception $e)
Expand Down
2 changes: 1 addition & 1 deletion test/Cleaner/AmbiguityCleanerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testValidUtf8Ambiguities(): void
$property->setAccessible(true);
$unambiguities = $property->getValue($cleaner);

foreach ($unambiguities as $unambiguity => $ambiguities)
foreach ($unambiguities as $ambiguities)
{
foreach ($ambiguities as $ambiguity)
{
Expand Down
10 changes: 5 additions & 5 deletions test/Cleaner/IntegerCleanerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class IntegerCleanerTest extends TestCase
*
* @return string[][]
*/
public function getCases(): array
public static function getCases(): array
{
return [[null, null],
['', null],
Expand All @@ -35,10 +35,10 @@ public function getCases(): array
*
* @return array
*/
public function getNonStrings(): array
public static function getNonStrings(): array
{
return [[[]],
[$this],
[new \stdClass()],
[fopen('php://stdin', 'r')]];
}

Expand All @@ -51,7 +51,7 @@ public function getNonStrings(): array
*
* @dataProvider getCases
*/
public function testClean($value, $expected): void
public function testClean(mixed $value, mixed $expected): void
{
$cleaner = IntegerCleaner::get();

Expand All @@ -67,7 +67,7 @@ public function testClean($value, $expected): void
*
* @dataProvider getNonStrings
*/
public function testNonString($value): void
public function testNonString(mixed $value): void
{
$this->expectException(\LogicException::class);

Expand Down
24 changes: 12 additions & 12 deletions test/Cleaner/PruneWhitespaceCleanerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ class PruneWhitespaceCleanerTest extends PlaisioTestCase
//--------------------------------------------------------------------------------------------------------------------
use StringCleaner;

//--------------------------------------------------------------------------------------------------------------------
/**
* Returns cases with spaces only.
*
* @return array
*/
public static function whitespaceOnly(): array
{
return [[''], [null], [' '], [' '], ["\n"], ["\n \n"], ["\n \t"], [" \t\n\r\0\x0B \t\n\r\0\x0B"]];
}

//--------------------------------------------------------------------------------------------------------------------
/**
* Returns an instance of PruneWhitespaceCleaner.
Expand All @@ -39,6 +50,7 @@ public function testClean(): void
self::assertEquals('Hello World!', $value);
}


//--------------------------------------------------------------------------------------------------------------------
/**
* Test with ambiguous whitespaceOnly only.
Expand All @@ -52,7 +64,6 @@ public function testEmpty(): void
self::assertNull($value);
}


//--------------------------------------------------------------------------------------------------------------------
/**
* Tests whitespaces only.
Expand All @@ -69,17 +80,6 @@ public function testWhitSpaceOnly(?string $string): void
self::assertNull($clean);
}

//--------------------------------------------------------------------------------------------------------------------
/**
* Returns cases with with spaces only.
*
* @return array
*/
public function whitespaceOnly(): array
{
return [[''], [null], [' '], [' '], ["\n"], ["\n \n"], ["\n \t"], [" \t\n\r\0\x0B \t\n\r\0\x0B"]];
}

//--------------------------------------------------------------------------------------------------------------------
}

Expand Down
22 changes: 11 additions & 11 deletions test/Cleaner/RemoveWhitespaceCleanerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ class RemoveWhitespaceCleanerTest extends PlaisioTestCase
//--------------------------------------------------------------------------------------------------------------------
use StringCleaner;

//--------------------------------------------------------------------------------------------------------------------
/**
* Returns cases with spaces only.
*
* @return array
*/
public static function whitespaceOnly(): array
{
return [[''], [null], [' '], [' '], ["\n"], ["\n \n"], ["\n \t"], [" \t\n\r\0\x0B \t\n\r\0\x0B"]];
}

//--------------------------------------------------------------------------------------------------------------------
/**
* Returns an instance of RemoveWhitespaceCleaner.
Expand Down Expand Up @@ -56,17 +67,6 @@ public function testWhitSpaceOnly(?string $string): void
self::assertNull($clean);
}

//--------------------------------------------------------------------------------------------------------------------
/**
* Returns cases with with spaces only.
*
* @return array
*/
public function whitespaceOnly(): array
{
return [[''], [null], [' '], [' '], ["\n"], ["\n \n"], ["\n \t"], [" \t\n\r\0\x0B \t\n\r\0\x0B"]];
}

//--------------------------------------------------------------------------------------------------------------------
}

Expand Down
22 changes: 11 additions & 11 deletions test/Cleaner/TidyCleanerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ class TidyCleanerTest extends PlaisioTestCase

//--------------------------------------------------------------------------------------------------------------------
/**
* Returns an instance of TidyCleaner.
* Return HTML snippet test cases.
*
* @return TidyCleaner
* @return string[][]
*/
public function createCleaner(): TidyCleaner
public static function snippets(): array
{
return TidyCleaner::get();
return [['<h2>subheading</h3>', '<h2>subheading</h2>'],
['<h1>heading', '<h1>heading</h1>'],
['<br>', '<br />'],
['<p>&nbsp;</p>', null]];
}

//--------------------------------------------------------------------------------------------------------------------
/**
* Return HTML snippet test cases.
* Returns an instance of TidyCleaner.
*
* @return string[][]
* @return TidyCleaner
*/
public function snippets(): array
public function createCleaner(): TidyCleaner
{
return [['<h2>subheading</h3>', '<h2>subheading</h2>'],
['<h1>heading', '<h1>heading</h1>'],
['<br>', '<br />'],
['<p>&nbsp;</p>', null]];
return TidyCleaner::get();
}

//--------------------------------------------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions test/Cleaner/Traits/StringCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ trait StringCleaner
*
* @return array
*/
public function getNonStrings(): array
public static function getNonStrings(): array
{
return [[[]],
[$this],
[new \stdClass()],
[fopen('php://stdin', 'r')]];
}

Expand All @@ -29,7 +29,7 @@ public function getNonStrings(): array
*
* @dataProvider getNonStrings
*/
public function testNonString($value): void
public function testNonString(mixed $value): void
{
$this->expectException(\LogicException::class);

Expand Down
22 changes: 11 additions & 11 deletions test/Cleaner/TrimWhitespaceCleanerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ class TrimWhitespaceCleanerTest extends PlaisioTestCase
//--------------------------------------------------------------------------------------------------------------------
use StringCleaner;

//--------------------------------------------------------------------------------------------------------------------
/**
* Returns cases with spaces only.
*
* @return array
*/
public static function whitespaceOnly(): array
{
return [[''], [null], [' '], [' '], ["\n"], ["\n \n"], ["\n \t"], [" \t\n\r\0\x0B \t\n\r\0\x0B"]];
}

//--------------------------------------------------------------------------------------------------------------------
/**
* Returns an instance of TrimWhitespaceCleaner.
Expand Down Expand Up @@ -55,17 +66,6 @@ public function testWhitSpaceOnly(?string $string): void
self::assertNull($clean);
}

//--------------------------------------------------------------------------------------------------------------------
/**
* Returns cases with with spaces only.
*
* @return array
*/
public function whitespaceOnly(): array
{
return [[''], [null], [' '], [' '], ["\n"], ["\n \n"], ["\n \t"], [" \t\n\r\0\x0B \t\n\r\0\x0B"]];
}

//--------------------------------------------------------------------------------------------------------------------
}

Expand Down
2 changes: 1 addition & 1 deletion test/Control/ButtonControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Unit tests for class ButtonControl.
*/
class ButtonControlTest extends PushControlTest
class ButtonControlTest extends PushControlTestCase
{
//--------------------------------------------------------------------------------------------------------------------
/**
Expand Down
4 changes: 2 additions & 2 deletions test/Control/CheckboxControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Plaisio\Form\Control\ForceSubmitControl;
use Plaisio\Form\Control\SimpleControl;
use Plaisio\Form\RawForm;
use Plaisio\Form\Test\Control\Traits\ImmutableTest;
use Plaisio\Form\Test\Control\Traits\ImmutableTestCase;
use Plaisio\Form\Test\Control\Traits\InputElementTest1;
use Plaisio\Form\Test\PlaisioTestCase;

Expand All @@ -18,7 +18,7 @@
class CheckboxControlTest extends PlaisioTestCase
{
//--------------------------------------------------------------------------------------------------------------------
use ImmutableTest;
use ImmutableTestCase;
use InputElementTest1;

//--------------------------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion test/Control/CheckboxesControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public function testWhiteListed1(): void

//--------------------------------------------------------------------------------------------------------------------
/**
* Test labels are casted to strings.
* Test labels are cast to strings.
*/
public function testWithNumericValues(): void
{
Expand Down
2 changes: 1 addition & 1 deletion test/Control/DatabaseLabelControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DatabaseLabelControlTest extends TestCase
/**
* Returns invalid label prefixes.
*/
public function getInvalidPrefixes(): array
public static function getInvalidPrefixes(): array
{
return [['123ABC'],
['_CMP_ID'],
Expand Down
6 changes: 3 additions & 3 deletions test/Control/DateControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
use Plaisio\Form\Control\SimpleControl;
use Plaisio\Form\Formatter\DateFormatter;
use Plaisio\Form\RawForm;
use Plaisio\Form\Test\Control\Traits\ImmutableTest;
use Plaisio\Form\Test\Control\Traits\ImmutableTestCase;
use Plaisio\Form\Test\Control\Traits\InputElementTest1;
use Plaisio\Form\Test\Control\Traits\InputElementTest2;

/**
* Unit tests for class DateControl.
*/
class DateControlTest extends SimpleControlTest
class DateControlTest extends SimpleControlTestCase
{
//--------------------------------------------------------------------------------------------------------------------
use ImmutableTest;
use ImmutableTestCase;
use InputElementTest1;
use InputElementTest2;

Expand Down
2 changes: 0 additions & 2 deletions test/Control/FileControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

namespace Plaisio\Form\Test\Control;

use Plaisio\Form\Control\FieldSet;
use Plaisio\Form\Control\FileControl;
use Plaisio\Form\Control\SimpleControl;
use Plaisio\Form\RawForm;
use Plaisio\Form\Test\Control\Traits\InputElementTest1;
use Plaisio\Form\Test\PlaisioTestCase;

Expand Down
2 changes: 1 addition & 1 deletion test/Control/ForceSubmitControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Unit tests for class ForceSubmitControl.
*/
class ForceSubmitControlTest extends PushControlTest
class ForceSubmitControlTest extends PushControlTestCase
{
//--------------------------------------------------------------------------------------------------------------------
use InputElementTest1;
Expand Down
Loading

0 comments on commit 045bd81

Please sign in to comment.