diff --git a/.github/workflows/analyzers.yaml b/.github/workflows/analyzers.yaml
index 6a7f015c..4f6e23f8 100644
--- a/.github/workflows/analyzers.yaml
+++ b/.github/workflows/analyzers.yaml
@@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
- php-versions: ['8.2', '8.3', '8.4']
+ php-versions: ['8.3', '8.4', '8.5']
composer-options: ['--ignore-platform-req=php+']
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}
@@ -29,3 +29,4 @@ jobs:
run: composer update --prefer-dist --no-progress --no-suggest ${{ matrix.composer-options }}
- name: Run the tests
run: composer run psalm
+ continue-on-error: ${{ matrix.php-versions == '8.5' }}
diff --git a/.github/workflows/autoloader.yaml b/.github/workflows/autoloader.yaml
index f59b88e1..9e6b2b97 100644
--- a/.github/workflows/autoloader.yaml
+++ b/.github/workflows/autoloader.yaml
@@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
- php-versions: ['8.2', '8.3', '8.4']
+ php-versions: ['8.3', '8.4', '8.5']
composer-options: ['--ignore-platform-req=php+']
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}
diff --git a/.github/workflows/code-style.yaml b/.github/workflows/code-style.yaml
index 0e6a2ab9..8648c064 100644
--- a/.github/workflows/code-style.yaml
+++ b/.github/workflows/code-style.yaml
@@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
- php-versions: ['8.2', '8.3', '8.4']
+ php-versions: ['8.3', '8.4', '8.5']
composer-options: ['--ignore-platform-req=php+']
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}
diff --git a/.github/workflows/stress.yaml b/.github/workflows/stress.yaml
index 2b3653a3..2e596e01 100644
--- a/.github/workflows/stress.yaml
+++ b/.github/workflows/stress.yaml
@@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
- php-versions: ['8.2', '8.3', '8.4']
+ php-versions: ['8.3', '8.4', '8.5']
composer-options: ['--ignore-platform-req=php+']
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}
diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml
index 86d32ff3..40eefee3 100644
--- a/.github/workflows/tests.yaml
+++ b/.github/workflows/tests.yaml
@@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
- php-versions: ['8.2', '8.3', '8.4']
+ php-versions: ['8.3', '8.4', '8.5']
composer-options: ['--ignore-platform-req=php+']
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}
@@ -32,4 +32,3 @@ jobs:
run: composer run tests
- name: Check tests quality
run: composer run testquality
- continue-on-error: ${{ matrix.php-versions == '8.4' }} # Infection is not ready yet.
diff --git a/.phive/phars.xml b/.phive/phars.xml
deleted file mode 100644
index 8de8650b..00000000
--- a/.phive/phars.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/composer.json b/composer.json
index c20d94b0..f855d5c0 100644
--- a/composer.json
+++ b/composer.json
@@ -7,20 +7,23 @@
],
"type": "library",
"require": {
- "php": "~8.2.0 || ~8.3.0 || ~8.4.0",
+ "php": "~8.3.0 || ~8.4.0 || ~8.5.0",
"ext-dom": "*",
"ext-libxml": "*",
"ext-xml": "*",
"ext-xsl": "*",
"ext-xmlreader": "*",
"ext-xmlwriter": "*",
- "azjezz/psl": "^3.0",
+ "azjezz/psl": "^3.0 || ^4.0",
"webmozart/assert": "^1.10"
},
"require-dev": {
"symfony/finder": "^6.1 || ^7.0",
"veewee/composer-run-parallel": "^1.0.0",
- "vimeo/psalm": "^5.4",
+ "phpunit/phpunit": "~12.3",
+ "vimeo/psalm": "~6.13",
+ "php-cs-fixer/shim": "~3.88",
+ "infection/infection": "^0.31.7",
"php-standard-library/psalm-plugin": "^2.2"
},
"license": "MIT",
@@ -47,19 +50,19 @@
"autoload": [
"@php build/bootstrap.php"
],
- "cs": "PHP_CS_FIXER_IGNORE_ENV=1 php ./tools/php-cs-fixer.phar fix --dry-run",
- "cs:fix": "PHP_CS_FIXER_IGNORE_ENV=1 php ./tools/php-cs-fixer.phar fix",
+ "cs": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --dry-run",
+ "cs:fix": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix",
"psalm": "./vendor/bin/psalm --no-cache --stats",
- "tests": "./tools/phpunit.phar --coverage-text --color",
+ "tests": "./vendor/bin/phpunit --coverage-text --color",
"stress": [
"Composer\\Config::disableProcessTimeout",
- "@php -c stress.ini ./tools/phpunit.phar --configuration phpunit.stress.xml --no-coverage"
+ "@php -c stress.ini ./vendor/bin/phpunit --configuration phpunit.stress.xml --no-coverage"
],
"testquality": "@parallel coverage infection",
"coverage": "@php ./tools/full-coverage-check.php .phpunit.cache/clover/clover.xml",
"infection": [
"Composer\\Config::disableProcessTimeout",
- "./tools/infection.phar --show-mutations -v"
+ "./vendor/bin/infection --show-mutations -v"
],
"ci": [
"@autoload",
@@ -69,7 +72,8 @@
},
"config": {
"allow-plugins": {
- "veewee/composer-run-parallel": true
+ "veewee/composer-run-parallel": true,
+ "infection/extension-installer": true
}
}
}
diff --git a/infection.json.dist b/infection.json.dist
index 498a7669..13b14c61 100644
--- a/infection.json.dist
+++ b/infection.json.dist
@@ -6,15 +6,19 @@
},
"minMsi": 100,
"minCoveredMsi": 100,
- "phpUnit": {
- "customPath": ".\/tools\/phpunit.phar"
- },
"logs": {
"text": ".phpunit.cache/infection.log",
"html": ".phpunit.cache/infection"
},
"mutators": {
"@default": true,
+ "ReturnRemoval": {
+ "ignore": [
+ "VeeWee\\Xml\\Dom\\Traverser\\Visitor\\RemoveNamespaces::onNodeLeave",
+ "VeeWee\\Xml\\Dom\\Traverser\\Visitor\\SortAttributes::onNodeEnter",
+ "VeeWee\\Xml\\Reader\\Reader::provide",
+ ]
+ },
"CastInt": {
"ignore": [
"VeeWee\\Xml\\*Exception::__construct"
diff --git a/phpunit.xml b/phpunit.xml
index 1dbb0c76..7f6c8a09 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,31 +1,34 @@
-
-
- src
-
-
- src/bootstrap.php
-
-
-
-
-
-
-
-
- tests/Xml
-
-
+
+
+ src
+
+
+ src/bootstrap.php
+
+
+
+
+
+
+
+
+
+
+
+
+ tests/Xml
+
+
diff --git a/psalm.xml b/psalm.xml
index 95604c82..ae6d9c4c 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -9,34 +9,21 @@
skipChecksOnUnresolvableIncludes="false"
checkForThrowsDocblock="true"
checkForThrowsInGlobalScope="true"
+ findUnusedCode="false"
+ ensureOverrideAttribute="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -47,6 +34,7 @@
+
diff --git a/src/Xml/Dom/Xpath/Locator/query_single.php b/src/Xml/Dom/Xpath/Locator/query_single.php
index af15b053..943dcac0 100644
--- a/src/Xml/Dom/Xpath/Locator/query_single.php
+++ b/src/Xml/Dom/Xpath/Locator/query_single.php
@@ -41,7 +41,9 @@ static function (DOMXPath $xpath) use ($query, $node): DOMNode {
1,
format('Expected to find only one node that matches %s. Got %s', $query, count($list))
);
+ $node = $list->item(0);
+ Assert::notNull($node);
- return $list->item(0);
+ return $node;
};
}
diff --git a/src/Xml/Reader/Configurator/xsd_schema.php b/src/Xml/Reader/Configurator/xsd_schema.php
index 1107cf0c..383fa697 100644
--- a/src/Xml/Reader/Configurator/xsd_schema.php
+++ b/src/Xml/Reader/Configurator/xsd_schema.php
@@ -20,7 +20,7 @@ function xsd_schema(string $schemaFile): Closure
Assert::fileExists($schemaFile);
disallow_libxml_false_returns(
- $reader->setSchema($schemaFile),
+ @$reader->setSchema($schemaFile),
'Unable to apply XSD schema to the XML Reader.'
);
diff --git a/src/Xml/Xslt/Configurator/security_preferences.php b/src/Xml/Xslt/Configurator/security_preferences.php
index 06f73c5c..faffb4b5 100644
--- a/src/Xml/Xslt/Configurator/security_preferences.php
+++ b/src/Xml/Xslt/Configurator/security_preferences.php
@@ -5,19 +5,26 @@
namespace VeeWee\Xml\Xslt\Configurator;
use Closure;
+use XSL_SECPREF_CREATE_DIRECTORY;
+use XSL_SECPREF_DEFAULT;
+use XSL_SECPREF_NONE;
+use XSL_SECPREF_READ_FILE;
+use XSL_SECPREF_READ_NETWORK;
+use XSL_SECPREF_WRITE_FILE;
+use XSL_SECPREF_WRITE_NETWORK;
use XSLTProcessor;
/**
* @see https://www.php.net/manual/en/xsltprocessor.setsecurityprefs.php
*
* @param int-mask<
- * \XSL_SECPREF_NONE,
- * \XSL_SECPREF_READ_FILE,
- * \XSL_SECPREF_WRITE_FILE,
- * \XSL_SECPREF_CREATE_DIRECTORY,
- * \XSL_SECPREF_READ_NETWORK,
- * \XSL_SECPREF_WRITE_NETWORK,
- * \XSL_SECPREF_DEFAULT
+ * XSL_SECPREF_NONE,
+ * XSL_SECPREF_READ_FILE,
+ * XSL_SECPREF_WRITE_FILE,
+ * XSL_SECPREF_CREATE_DIRECTORY,
+ * XSL_SECPREF_READ_NETWORK,
+ * XSL_SECPREF_WRITE_NETWORK,
+ * XSL_SECPREF_DEFAULT
* > $preferences
*
* @return Closure(XSLTProcessor): XSLTProcessor
diff --git a/src/Xml/Xslt/Transformer/document_to_string.php b/src/Xml/Xslt/Transformer/document_to_string.php
index b0fff5d8..2bf6af89 100644
--- a/src/Xml/Xslt/Transformer/document_to_string.php
+++ b/src/Xml/Xslt/Transformer/document_to_string.php
@@ -17,7 +17,6 @@ function document_to_string(Document $document): Closure
{
return static fn (XSLTProcessor $processor): string => disallow_issues(
static function () use ($document, $processor): string {
- // Result can also be null ... undocumentedly!
return (string) disallow_libxml_false_returns(
$processor->transformToXML($document->toUnsafeDocument()),
'Unable to apply the XSLT template'
diff --git a/stubs/XSLTProcessor.phpstub b/stubs/XSLTProcessor.phpstub
new file mode 100644
index 00000000..7a3d033e
--- /dev/null
+++ b/stubs/XSLTProcessor.phpstub
@@ -0,0 +1,14 @@
+
+ * The transformed document.
+ *
+ * @return string|false|null The result of the transformation as a string or FALSE on error.
+ */
+ public function transformToXml($document): string|false|null {}
+
+}
diff --git a/tests/Xml/Dom/Assert/AssertAttributeTest.php b/tests/Xml/Dom/Assert/AssertAttributeTest.php
new file mode 100644
index 00000000..b1d52332
--- /dev/null
+++ b/tests/Xml/Dom/Assert/AssertAttributeTest.php
@@ -0,0 +1,44 @@
+expectException(AssertException::class);
+ }
+
+ $actual = assert_attribute($node);
+ static::assertSame($node, $actual);
+ }
+
+ public static function provideTestCases()
+ {
+ $doc = Document::fromXmlString(
+ <<
+ - Hello
+
+ EOXML
+ )->toUnsafeDocument();
+
+ yield [$doc, false];
+ yield [$doc->documentElement, false];
+ yield [$doc->documentElement->firstElementChild, false];
+ yield [$doc->documentElement->firstElementChild->attributes->getNamedItem('attr'), true];
+ yield [$doc->documentElement->firstElementChild->firstChild, false];
+ yield [null, false];
+ }
+}
diff --git a/tests/Xml/Dom/Assert/AssertCDataTest.php b/tests/Xml/Dom/Assert/AssertCDataTest.php
index 283e1c00..5dc37c4f 100644
--- a/tests/Xml/Dom/Assert/AssertCDataTest.php
+++ b/tests/Xml/Dom/Assert/AssertCDataTest.php
@@ -5,6 +5,7 @@
namespace VeeWee\Tests\Xml\Dom\Assert;
use DOMNode;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Psl\Type\Exception\AssertException;
use VeeWee\Xml\Dom\Document;
@@ -12,10 +13,7 @@
final class AssertCDataTest extends TestCase
{
- /**
- *
- * @dataProvider provideTestCases
- */
+ #[DataProvider('provideTestCases')]
public function test_it_knows_cdata(?DOMNode $node, bool $expected): void
{
if (!$expected) {
@@ -26,7 +24,7 @@ public function test_it_knows_cdata(?DOMNode $node, bool $expected): void
static::assertSame($node, $actual);
}
- public function provideTestCases()
+ public static function provideTestCases()
{
$doc = Document::fromXmlString(
<< [
'',
diff --git a/tests/Xml/Dom/Configurator/ComparableTest.php b/tests/Xml/Dom/Configurator/ComparableTest.php
index cc777041..3afc0e51 100644
--- a/tests/Xml/Dom/Configurator/ComparableTest.php
+++ b/tests/Xml/Dom/Configurator/ComparableTest.php
@@ -4,6 +4,7 @@
namespace VeeWee\Tests\Xml\Dom\Configurator;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use VeeWee\Xml\Dom\Document;
use function VeeWee\Xml\Dom\Configurator\comparable;
@@ -12,9 +13,7 @@
final class ComparableTest extends TestCase
{
- /**
- * @dataProvider provideXmls
- */
+ #[DataProvider('provideXmls')]
public function test_it_can_canonicalize(string $input, string $expected): void
{
$comparable = Document::fromXmlString($input, comparable());
@@ -23,7 +22,7 @@ public function test_it_can_canonicalize(string $input, string $expected): void
static::assertSame($expected, $actual);
}
- public function provideXmls()
+ public static function provideXmls()
{
yield 'no-action' => [
'',
diff --git a/tests/Xml/Dom/Configurator/OptimizeNamespacesTest.php b/tests/Xml/Dom/Configurator/OptimizeNamespacesTest.php
index 25e8ca67..650c8fd7 100644
--- a/tests/Xml/Dom/Configurator/OptimizeNamespacesTest.php
+++ b/tests/Xml/Dom/Configurator/OptimizeNamespacesTest.php
@@ -4,6 +4,7 @@
namespace VeeWee\Tests\Xml\Dom\Configurator;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use VeeWee\Xml\Dom\Document;
use function VeeWee\Xml\Dom\Configurator\optimize_namespaces;
@@ -12,9 +13,7 @@
final class OptimizeNamespacesTest extends TestCase
{
- /**
- * @dataProvider provideXmls
- */
+ #[DataProvider('provideXmls')]
public function test_it_can_optimize_namespaces(string $input, string $expected): void
{
$optimized = Document::fromXmlString($input, optimize_namespaces('ns'));
@@ -23,7 +22,7 @@ public function test_it_can_optimize_namespaces(string $input, string $expected)
static::assertSame($expected, $actual);
}
- public function provideXmls()
+ public static function provideXmls()
{
yield 'no-action' => [
'',
diff --git a/tests/Xml/Dom/DocumentTest.php b/tests/Xml/Dom/DocumentTest.php
index 04f9c9d1..bd8c9ee4 100644
--- a/tests/Xml/Dom/DocumentTest.php
+++ b/tests/Xml/Dom/DocumentTest.php
@@ -36,7 +36,7 @@ public function test_it_can_create_an_empty_document(): void
$document = new DOMDocument();
$doc = Document::empty();
- static::assertEquals($document, $doc->toUnsafeDocument());
+ static::assertEquals($document->C14N(), $doc->toUnsafeDocument()->C14N());
}
@@ -45,7 +45,7 @@ public function test_it_can_create_a_configured_document(): void
$document = new DOMDocument();
$doc = Document::configure(identity());
- static::assertEquals($document, $doc->toUnsafeDocument());
+ static::assertEquals($document->C14N(), $doc->toUnsafeDocument()->C14N());
}
diff --git a/tests/Xml/Dom/Locator/Attribute/AttributesListTest.php b/tests/Xml/Dom/Locator/Attribute/AttributesListTest.php
index 251b136b..a0f930f2 100644
--- a/tests/Xml/Dom/Locator/Attribute/AttributesListTest.php
+++ b/tests/Xml/Dom/Locator/Attribute/AttributesListTest.php
@@ -5,15 +5,14 @@
namespace VeeWee\Tests\Xml\Dom\Locator\Attribute;
use DOMNode;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use VeeWee\Xml\Dom\Document;
use function VeeWee\Xml\Dom\Locator\Attribute\attributes_list;
final class AttributesListTest extends TestCase
{
- /**
- * @dataProvider provideTestCases
- */
+ #[DataProvider('provideTestCases')]
public function test_it_can_fetch_xmlns_attribute_list_from_node(DOMNode $node, array $expected): void
{
$actual = attributes_list($node);
@@ -21,7 +20,7 @@ public function test_it_can_fetch_xmlns_attribute_list_from_node(DOMNode $node,
static::assertEquals($expected, [...$actual]);
}
- public function provideTestCases()
+ public static function provideTestCases()
{
$doc = Document::fromXmlString(
<< [
'',
diff --git a/tests/Xml/Dom/Manipulator/Node/RenameTest.php b/tests/Xml/Dom/Manipulator/Node/RenameTest.php
index 975434cf..cdf6c341 100644
--- a/tests/Xml/Dom/Manipulator/Node/RenameTest.php
+++ b/tests/Xml/Dom/Manipulator/Node/RenameTest.php
@@ -162,7 +162,6 @@ public function test_it_can_rename_namespaced_attributes(): void
*/
public function test_it_can_not_rename_namespaced_attribute_prefix_when_the_xmlns_is_still_available(): void
{
- $this->markAsRisky('Broken DOM functionality');
$doc = Document::fromXmlString('');
$root = $doc->map(document_element());
$node = $root->getAttributeNode('a:who');
diff --git a/tests/Xml/Dom/Manipulator/Xmlns/RenameTest.php b/tests/Xml/Dom/Manipulator/Xmlns/RenameTest.php
index 09b161af..dc379012 100644
--- a/tests/Xml/Dom/Manipulator/Xmlns/RenameTest.php
+++ b/tests/Xml/Dom/Manipulator/Xmlns/RenameTest.php
@@ -4,6 +4,7 @@
namespace VeeWee\Tests\Xml\Dom\Manipulator\Xmlns;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Exception\RuntimeException;
@@ -12,9 +13,7 @@
final class RenameTest extends TestCase
{
- /**
- * @dataProvider provideXmls
- */
+ #[DataProvider('provideXmls')]
public function test_it_can_rename_namespaces(string $input, string $expected): void
{
$document = Document::fromXmlString($input)->toUnsafeDocument();
@@ -34,7 +33,7 @@ public function test_it_can_not_rename_existing_prefix_to_other_uri(): void
rename($document, 'http://replace', 'ns1');
}
- public function provideXmls()
+ public static function provideXmls()
{
yield 'no-action' => [
'',
diff --git a/tests/Xml/Dom/Predicate/IsAttributeTest.php b/tests/Xml/Dom/Predicate/IsAttributeTest.php
index 6044f798..c6783a27 100644
--- a/tests/Xml/Dom/Predicate/IsAttributeTest.php
+++ b/tests/Xml/Dom/Predicate/IsAttributeTest.php
@@ -5,22 +5,20 @@
namespace VeeWee\Tests\Xml\Dom\Predicate;
use DOMNode;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use VeeWee\Xml\Dom\Document;
use function VeeWee\Xml\Dom\Predicate\is_attribute;
final class IsAttributeTest extends TestCase
{
- /**
- *
- * @dataProvider provideTestCases
- */
+ #[DataProvider('provideTestCases')]
public function test_it_knows_attributes(DOMNode $node, bool $expected): void
{
static::assertSame($expected, is_attribute($node));
}
- public function provideTestCases()
+ public static function provideTestCases()
{
$doc = Document::fromXmlString(
<<getFixture($xml);
@@ -36,7 +34,7 @@ public function test_it_can_validate_internal_xsds(string $xml, int $errors): vo
/**
* @return array
*/
- public function provideSchemeValidation()
+ public static function provideSchemeValidation()
{
yield 'valid' => [
'xml' => 'xml-valid.xml',
diff --git a/tests/Xml/Dom/Validator/ValidatorChainTest.php b/tests/Xml/Dom/Validator/ValidatorChainTest.php
index 06abfe2a..6e377f14 100644
--- a/tests/Xml/Dom/Validator/ValidatorChainTest.php
+++ b/tests/Xml/Dom/Validator/ValidatorChainTest.php
@@ -5,22 +5,20 @@
namespace VeeWee\Tests\Xml\Dom\Validator;
use DOMDocument;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use VeeWee\Tests\Xml\ErrorHandling\Issue\UseIssueTrait;
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\ErrorHandling\Issue\IssueCollection;
-use VeeWee\Xml\ErrorHandling\Issue\Level;
+use VeeWee\Xml\ErrorHandling\Issue\Level;
use function VeeWee\Xml\Dom\Validator\validator_chain;
final class ValidatorChainTest extends TestCase
{
use UseIssueTrait;
- /**
- *
- * @dataProvider provideErrorCases
- */
+ #[DataProvider('provideErrorCases')]
public function test_it_can_validate_multiple_validators(callable $validator, int $errors): void
{
$doc = Document::empty();
@@ -29,7 +27,7 @@ public function test_it_can_validate_multiple_validators(callable $validator, in
static::assertCount($errors, $issues);
}
- public function provideErrorCases()
+ public static function provideErrorCases()
{
yield 'empty' => [
'validator' => validator_chain(),
@@ -46,8 +44,8 @@ public function provideErrorCases()
yield 'oneFails' => [
'validator' => validator_chain(
static fn (DOMDocument $document) => new IssueCollection(),
- fn (DOMDocument $document) => new IssueCollection(
- $this->createIssue(Level::fatal())
+ static fn (DOMDocument $document) => new IssueCollection(
+ self::createIssue(Level::fatal())
),
static fn (DOMDocument $document) => new IssueCollection(),
static fn (DOMDocument $document) => new IssueCollection()
@@ -56,12 +54,12 @@ public function provideErrorCases()
];
yield 'allFails' => [
'validator' => validator_chain(
- fn (DOMDocument $document) => new IssueCollection(
- $this->createIssue(Level::fatal())
+ static fn (DOMDocument $document) => new IssueCollection(
+ self::createIssue(Level::fatal())
),
- fn (DOMDocument $document) => new IssueCollection(
- $this->createIssue(Level::fatal()),
- $this->createIssue(Level::fatal())
+ static fn (DOMDocument $document) => new IssueCollection(
+ self::createIssue(Level::fatal()),
+ self::createIssue(Level::fatal())
),
),
'errors' => 3,
diff --git a/tests/Xml/Dom/Validator/XsdValidatorTest.php b/tests/Xml/Dom/Validator/XsdValidatorTest.php
index 4a2d9bd1..1b459f73 100644
--- a/tests/Xml/Dom/Validator/XsdValidatorTest.php
+++ b/tests/Xml/Dom/Validator/XsdValidatorTest.php
@@ -4,16 +4,14 @@
namespace VeeWee\Tests\Xml\Dom\Validator;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use VeeWee\Xml\Dom\Document;
use function VeeWee\Xml\Dom\Validator\xsd_validator;
final class XsdValidatorTest extends TestCase
{
- /**
- *
- * @dataProvider provideSchemeValidation
- */
+ #[DataProvider('provideSchemeValidation')]
public function test_it_can_validate_xsds(string $xml, string $xsd, int $errors): void
{
$doc = Document::fromXmlFile($this->getFixture($xml));
@@ -32,7 +30,7 @@ public function test_it_can_validate_xsds(string $xml, string $xsd, int $errors)
/**
* @return array
*/
- public function provideSchemeValidation()
+ public static function provideSchemeValidation()
{
yield 'valid' => [
'xml' => 'xml-valid.xml',
diff --git a/tests/Xml/Encoding/EncodingTest.php b/tests/Xml/Encoding/EncodingTest.php
index 3b923c0d..ac18b5c6 100644
--- a/tests/Xml/Encoding/EncodingTest.php
+++ b/tests/Xml/Encoding/EncodingTest.php
@@ -5,6 +5,7 @@
namespace VeeWee\Tests\Xml\Encoding;
use JsonSerializable;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Encoding\Exception\EncodingException;
@@ -21,11 +22,9 @@ final class EncodingTest extends TestCase
{
private const XML_HEADER = '';
- /**
- * @dataProvider provideBidirectionalCases
- * @dataProvider provideRiskyBidirectionalCases
- * @dataProvider provideEncodingOnly
- */
+ #[DataProvider('provideBidirectionalCases')]
+ #[DataProvider('provideRiskyBidirectionalCases')]
+ #[DataProvider('provideEncodingOnly')]
public function test_it_encodes(string $xml, array $data)
{
$actual = xml_encode($data, identity());
@@ -33,11 +32,9 @@ public function test_it_encodes(string $xml, array $data)
static::assertStringStartsWith(self::XML_HEADER, $actual);
}
- /**
- * @dataProvider provideBidirectionalCases
- * @dataProvider provideRiskyBidirectionalCases
- * @dataProvider provideEncodingOnly
- */
+ #[DataProvider('provideBidirectionalCases')]
+ #[DataProvider('provideRiskyBidirectionalCases')]
+ #[DataProvider('provideEncodingOnly')]
public function test_it_encodes_to_document(string $xml, array $data)
{
$actual = document_encode($data, identity());
@@ -45,11 +42,9 @@ public function test_it_encodes_to_document(string $xml, array $data)
static::assertStringStartsWith(self::XML_HEADER, $actual->toXmlString());
}
- /**
- * @dataProvider provideBidirectionalCases
- * @dataProvider provideRiskyBidirectionalCases
- * @dataProvider provideEncodingOnly
- */
+ #[DataProvider('provideBidirectionalCases')]
+ #[DataProvider('provideRiskyBidirectionalCases')]
+ #[DataProvider('provideEncodingOnly')]
public function test_it_encodes_to_element(string $xml, array $data)
{
$actual = element_encode($data);
@@ -57,22 +52,18 @@ public function test_it_encodes_to_element(string $xml, array $data)
static::assertStringStartsNotWith(self::XML_HEADER, $actual);
}
- /**
- * @dataProvider provideBidirectionalCases
- * @dataProvider provideRiskyBidirectionalCases
- * @dataProvider provideDecodingOnly
- * @dataProvider provideRiskyDecodingOnly
- */
+ #[DataProvider('provideBidirectionalCases')]
+ #[DataProvider('provideRiskyBidirectionalCases')]
+ #[DataProvider('provideDecodingOnly')]
+ #[DataProvider('provideRiskyDecodingOnly')]
public function test_it_decodes(string $xml, array $data)
{
$actual = xml_decode($xml, identity());
static::assertSame($data, $actual);
}
- /**
- * @dataProvider provideBidirectionalCases
- * @dataProvider provideDecodingOnly
- */
+ #[DataProvider('provideBidirectionalCases')]
+ #[DataProvider('provideDecodingOnly')]
public function test_it_decodes_from_element(string $xml, array $data)
{
$doc = Document::fromXmlString($xml);
@@ -82,34 +73,28 @@ public function test_it_decodes_from_element(string $xml, array $data)
static::assertSame($data, $actual);
}
- /**
- * @dataProvider provideInvalidXml
- */
+ #[DataProvider('provideInvalidXml')]
public function test_it_errors_while_encoding_invalid_xml(string $xml, array $data)
{
$this->expectException(EncodingException::class);
xml_encode($data);
}
- /**
- * @dataProvider provideInvalidXml
- */
+ #[DataProvider('provideInvalidXml')]
public function test_it_errors_while_encoding_invalid_xml_element(string $xml, array $data)
{
$this->expectException(EncodingException::class);
element_encode($data);
}
- /**
- * @dataProvider provideInvalidXml
- */
- public function test_it_errors_while_decoding_invalid_xml(string $xml)
+ #[DataProvider('provideInvalidXml')]
+ public function test_it_errors_while_decoding_invalid_xml(string $xml, array $data)
{
$this->expectException(EncodingException::class);
xml_decode($xml);
}
- public function provideBidirectionalCases()
+ public static function provideBidirectionalCases()
{
yield 'empty' => [
'xml' => '',
@@ -239,19 +224,13 @@ public function provideBidirectionalCases()
]
]
];
- yield 'cdata' => [
- 'xml' => 'world]]>',
- 'data' => ['hello' => [
- '@cdata' => 'world'
- ]]
- ];
yield 'mixed cdata' => [
'xml' => 'hello world]]>',
'data' => ['hello' => 'hello world']
];
}
- public function provideRiskyBidirectionalCases()
+ public static function provideRiskyBidirectionalCases()
{
yield 'namespaced' => [
'xml' => << [
'xml' => << [
+ 'xml' => 'world